sl@0: /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/ sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #ifdef GLIB_COMPILATION sl@0: #undef GLIB_COMPILATION sl@0: #endif sl@0: sl@0: #include "glib.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: void g_date_debug_print(GDate* d) sl@0: { sl@0: if (!d) g_print("NULL!\n"); sl@0: else sl@0: g_print("julian: %u (%s) DMY: %u %u %u (%s)\n", sl@0: d->julian_days, sl@0: d->julian ? "valid" : "invalid", sl@0: d->day, sl@0: d->month, sl@0: d->year, sl@0: d->dmy ? "valid" : "invalid"); sl@0: sl@0: fflush(stdout); sl@0: } sl@0: sl@0: /* These only work in the POSIX locale, maybe C too - sl@0: * type POSIX into the program to check them sl@0: */ sl@0: char* posix_tests [] = { sl@0: "19981024", sl@0: "981024", sl@0: "October 1998", sl@0: "October 98", sl@0: "oCT 98", sl@0: "10/24/98", sl@0: "10 -- 24 -- 98", sl@0: "10/24/1998", sl@0: "October 24, 1998", sl@0: NULL sl@0: }; sl@0: sl@0: int main(int argc, char** argv) sl@0: { sl@0: GDate* d; sl@0: gchar* loc; sl@0: gchar input[1024]; sl@0: sl@0: sl@0: loc = setlocale(LC_ALL,""); sl@0: if (loc) sl@0: g_print("\nLocale set to %s\n", loc); sl@0: else sl@0: g_print("\nLocale unchanged\n"); sl@0: sl@0: d = g_date_new(); sl@0: sl@0: while (fgets(input, 10, stdin)) sl@0: { sl@0: if (input[0] == '\n') sl@0: { sl@0: g_print("Enter a date to parse and press enter, or type `POSIX':\n"); sl@0: continue; sl@0: } sl@0: sl@0: if (strcmp(input,"POSIX\n") == 0) sl@0: { sl@0: char** s = posix_tests; sl@0: while (*s) { sl@0: g_date_set_parse(d, *s); sl@0: sl@0: g_print("POSIXy parse test `%s' ...", *s); sl@0: sl@0: if (!g_date_valid(d)) sl@0: { sl@0: g_print(" failed.\n"); sl@0: } sl@0: else sl@0: { sl@0: gchar buf[256]; sl@0: sl@0: g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n", sl@0: d); sl@0: g_print("%s", buf); sl@0: } sl@0: sl@0: ++s; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: g_date_set_parse(d, input); sl@0: sl@0: if (!g_date_valid(d)) sl@0: { sl@0: g_print("Parse failed.\n"); sl@0: } sl@0: else sl@0: { sl@0: gchar buf[256]; sl@0: sl@0: g_date_strftime(buf,100,"Parsed: `%x' (%B %d %Y)\n", sl@0: d); sl@0: g_print("%s", buf); sl@0: } sl@0: } sl@0: } sl@0: sl@0: g_date_free(d); sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: