source: trunk/third/glib/testgdateparser.c @ 14479

Revision 14479, 2.1 KB checked in by ghudson, 25 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14478, which included commits to RCS files with non-trunk default branches.
Line 
1
2#include "glib.h"
3
4#include <stdio.h>
5#include <string.h>
6#include <locale.h>
7
8void g_date_debug_print(GDate* d)
9{
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");
19 
20  fflush(stdout);
21}
22
23/* These only work in the POSIX locale, maybe C too -
24 * type POSIX into the program to check them
25 */
26char* 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
37};
38
39int main(int argc, char** argv)
40{
41  GDate* d;
42  gchar* loc;
43  gchar input[1024];
44
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");
50
51  d = g_date_new();
52
53  while (fgets(input, 1023, stdin))
54    {
55      if (input[0] == '\n')
56        {
57          g_print("Enter a date to parse and press enter, or type `POSIX':\n");
58          continue;
59        }
60
61      if (strcmp(input,"POSIX\n") == 0)
62        {
63          char** s = posix_tests;
64          while (*s) {
65            g_date_set_parse(d, *s);
66           
67            g_print("POSIXy parse test `%s' ...", *s);
68
69            if (!g_date_valid(d))
70              {
71                g_print(" failed.\n");
72              }
73            else
74              {
75                gchar buf[256];
76               
77                g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n",
78                                d);
79                g_print("%s", buf);
80              }
81
82            ++s;
83          }
84        }
85      else
86        {
87          g_date_set_parse(d, input);
88         
89          if (!g_date_valid(d))
90            {
91              g_print("Parse failed.\n");
92            }
93          else
94            {
95              gchar buf[256];
96             
97              g_date_strftime(buf,100,"Parsed: `%x' (%B %d %Y)\n",
98                              d);
99              g_print("%s", buf);
100            }
101        }
102    }
103
104  g_date_free(d);
105
106  return 0;
107}
108
109
Note: See TracBrowser for help on using the repository browser.