1 #undef G_DISABLE_ASSERT
2 #undef G_LOG_DOMAIN
3
4 #ifdef GLIB_COMPILATION
5 #undef GLIB_COMPILATION
6 #endif
7
8 #include "glib.h"
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <locale.h>
13
14 /* These only work in the POSIX locale, maybe C too -
15 * type POSIX into the program to check them
16 */
17 char* posix_tests [] = {
18 "19981024",
19 "981024",
20 "October 1998",
21 "October 98",
22 "oCT 98",
23 "10/24/98",
24 "10 -- 24 -- 98",
25 "10/24/1998",
26 "October 24, 1998",
27 NULL
28 };
29
main(int argc,char ** argv)30 int main(int argc, char** argv)
31 {
32 GDate* d;
33 gchar* loc;
34 gchar input[1024];
35
36 loc = setlocale(LC_ALL,"");
37 if (loc)
38 g_print("\nLocale set to %s\n", loc);
39 else
40 g_print("\nLocale unchanged\n");
41
42 d = g_date_new();
43
44 while (fgets(input, 1023, stdin))
45 {
46 if (input[0] == '\n')
47 {
48 g_print("Enter a date to parse and press enter, or type 'POSIX':\n");
49 continue;
50 }
51
52 if (strcmp(input,"POSIX\n") == 0)
53 {
54 char** s = posix_tests;
55 while (*s) {
56 g_date_set_parse(d, *s);
57
58 g_print("POSIXy parse test '%s' ...", *s);
59
60 if (!g_date_valid(d))
61 {
62 g_print(" failed.\n");
63 }
64 else
65 {
66 gchar buf[256];
67
68 g_date_strftime(buf,100," parsed '%x' (%B %d %Y)\n",
69 d);
70 g_print("%s", buf);
71 }
72
73 ++s;
74 }
75 }
76 else
77 {
78 g_date_set_parse(d, input);
79
80 if (!g_date_valid(d))
81 {
82 g_print("Parse failed.\n");
83 }
84 else
85 {
86 gchar buf[256];
87
88 g_date_strftime(buf,100,"Parsed: '%x' (%B %d %Y)\n",
89 d);
90 g_print("%s", buf);
91 }
92 }
93 }
94
95 g_date_free(d);
96
97 return 0;
98 }
99