|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #undef G_DISABLE_ASSERT |
|
19 #undef G_LOG_DOMAIN |
|
20 |
|
21 #ifdef GLIB_COMPILATION |
|
22 #undef GLIB_COMPILATION |
|
23 #endif |
|
24 |
|
25 #include "glib.h" |
|
26 |
|
27 #include <stdio.h> |
|
28 #include <string.h> |
|
29 #include <locale.h> |
|
30 |
|
31 |
|
32 void g_date_debug_print(GDate* d) |
|
33 { |
|
34 if (!d) g_print("NULL!\n"); |
|
35 else |
|
36 g_print("julian: %u (%s) DMY: %u %u %u (%s)\n", |
|
37 d->julian_days, |
|
38 d->julian ? "valid" : "invalid", |
|
39 d->day, |
|
40 d->month, |
|
41 d->year, |
|
42 d->dmy ? "valid" : "invalid"); |
|
43 |
|
44 fflush(stdout); |
|
45 } |
|
46 |
|
47 /* These only work in the POSIX locale, maybe C too - |
|
48 * type POSIX into the program to check them |
|
49 */ |
|
50 char* posix_tests [] = { |
|
51 "19981024", |
|
52 "981024", |
|
53 "October 1998", |
|
54 "October 98", |
|
55 "oCT 98", |
|
56 "10/24/98", |
|
57 "10 -- 24 -- 98", |
|
58 "10/24/1998", |
|
59 "October 24, 1998", |
|
60 NULL |
|
61 }; |
|
62 |
|
63 int main(int argc, char** argv) |
|
64 { |
|
65 GDate* d; |
|
66 gchar* loc; |
|
67 gchar input[1024]; |
|
68 |
|
69 |
|
70 loc = setlocale(LC_ALL,""); |
|
71 if (loc) |
|
72 g_print("\nLocale set to %s\n", loc); |
|
73 else |
|
74 g_print("\nLocale unchanged\n"); |
|
75 |
|
76 d = g_date_new(); |
|
77 |
|
78 while (fgets(input, 10, stdin)) |
|
79 { |
|
80 if (input[0] == '\n') |
|
81 { |
|
82 g_print("Enter a date to parse and press enter, or type `POSIX':\n"); |
|
83 continue; |
|
84 } |
|
85 |
|
86 if (strcmp(input,"POSIX\n") == 0) |
|
87 { |
|
88 char** s = posix_tests; |
|
89 while (*s) { |
|
90 g_date_set_parse(d, *s); |
|
91 |
|
92 g_print("POSIXy parse test `%s' ...", *s); |
|
93 |
|
94 if (!g_date_valid(d)) |
|
95 { |
|
96 g_print(" failed.\n"); |
|
97 } |
|
98 else |
|
99 { |
|
100 gchar buf[256]; |
|
101 |
|
102 g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n", |
|
103 d); |
|
104 g_print("%s", buf); |
|
105 } |
|
106 |
|
107 ++s; |
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 g_date_set_parse(d, input); |
|
113 |
|
114 if (!g_date_valid(d)) |
|
115 { |
|
116 g_print("Parse failed.\n"); |
|
117 } |
|
118 else |
|
119 { |
|
120 gchar buf[256]; |
|
121 |
|
122 g_date_strftime(buf,100,"Parsed: `%x' (%B %d %Y)\n", |
|
123 d); |
|
124 g_print("%s", buf); |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 g_date_free(d); |
|
130 |
|
131 return 0; |
|
132 } |
|
133 |
|
134 |