Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / glib / testgdateparser.c
blob1e482ffb57c0b5ebec421f46f2285e93a7742718
2 #include "glib.h"
4 #include <stdio.h>
5 #include <string.h>
6 #include <locale.h>
8 void g_date_debug_print(GDate* d)
10 if (!d) g_print("NULL!\n");
11 else
12 g_print("julian: %u (%s) DMY: %u %u %u (%s)\n",
13 d->julian_days,
14 d->julian ? "valid" : "invalid",
15 d->day,
16 d->month,
17 d->year,
18 d->dmy ? "valid" : "invalid");
20 fflush(stdout);
23 /* These only work in the POSIX locale, maybe C too -
24 * type POSIX into the program to check them
26 char* posix_tests [] = {
27 "19981024",
28 "981024",
29 "October 1998",
30 "October 98",
31 "oCT 98",
32 "10/24/98",
33 "10 -- 24 -- 98",
34 "10/24/1998",
35 "October 24, 1998",
36 NULL
39 int main(int argc, char** argv)
41 GDate* d;
42 gchar* loc;
43 gchar input[1024];
45 loc = setlocale(LC_ALL,"");
46 if (loc)
47 g_print("\nLocale set to %s\n", loc);
48 else
49 g_print("\nLocale unchanged\n");
51 d = g_date_new();
53 while (fgets(input, 1023, stdin))
55 if (input[0] == '\n')
57 g_print("Enter a date to parse and press enter, or type `POSIX':\n");
58 continue;
61 if (strcmp(input,"POSIX\n") == 0)
63 char** s = posix_tests;
64 while (*s) {
65 g_date_set_parse(d, *s);
67 g_print("POSIXy parse test `%s' ...", *s);
69 if (!g_date_valid(d))
71 g_print(" failed.\n");
73 else
75 gchar buf[256];
77 g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n",
78 d);
79 g_print("%s", buf);
82 ++s;
85 else
87 g_date_set_parse(d, input);
89 if (!g_date_valid(d))
91 g_print("Parse failed.\n");
93 else
95 gchar buf[256];
97 g_date_strftime(buf,100,"Parsed: `%x' (%B %d %Y)\n",
98 d);
99 g_print("%s", buf);
104 g_date_free(d);
106 return 0;