Kannel: Open Source WAP and SMS gateway  svn-r5335
test_date.c File Reference
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "gwlib/gwlib.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 64 of file test_date.c.

References date_parse_iso(), universaltime::day, get_and_set_debugs(), gwlib_init(), gwlib_shutdown(), universaltime::hour, info(), universaltime::minute, universaltime::month, octstr_create, octstr_destroy(), octstr_get_cstr, universaltime::offset_sec, panic, universaltime::second, and universaltime::year.

65 {
66  Octstr *s;
67  struct universaltime ut;
68 
69  gwlib_init();
70 
71  get_and_set_debugs(argc, argv, NULL);
72 
73  s = octstr_create("2009-02-10T10:02:03");
74  if (date_parse_iso(&ut, s) == -1) {
75  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
76  }
77  info(0, "%s : %04ld-%02ld-%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
78  octstr_destroy(s);
79 
80  s = octstr_create("2009-02-10");
81  if (date_parse_iso(&ut, s) == -1) {
82  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
83  }
84  info(0, "%s : %04ld-%02ld-%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
85  octstr_destroy(s);
86 
87  s = octstr_create("20090210T10:02:03");
88  if (date_parse_iso(&ut, s) == -1) {
89  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
90  }
91  info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
92  octstr_destroy(s);
93 
94  s = octstr_create("20090210");
95  if (date_parse_iso(&ut, s) == -1) {
96  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
97  }
98  info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
99  octstr_destroy(s);
100 
101  s = octstr_create("20090210T10:02:03Z");
102  if (date_parse_iso(&ut, s) == -1) {
103  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
104  }
105  info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld+%ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second, ut.offset_sec);
106  octstr_destroy(s);
107 
108  s = octstr_create("20090210T10:02:03+01:00");
109  if (date_parse_iso(&ut, s) == -1) {
110  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
111  }
112  info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld+%ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second, ut.offset_sec);
113  octstr_destroy(s);
114 
115  s = octstr_create("20090210T10:02:03-01:00");
116  if (date_parse_iso(&ut, s) == -1) {
117  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
118  }
119  info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld%+ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second, ut.offset_sec);
120  octstr_destroy(s);
121 
122  s = octstr_create("20090210T10:02:03-01:15");
123  if (date_parse_iso(&ut, s) == -1) {
124  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
125  }
126  info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld%+ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second, ut.offset_sec);
127  octstr_destroy(s);
128 
129  s = octstr_create("20090210T10:02:03.375-01:15");
130  if (date_parse_iso(&ut, s) == -1) {
131  panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
132  }
133  info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld%+ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second, ut.offset_sec);
134  octstr_destroy(s);
135 
136  gwlib_shutdown();
137  return 0;
138 }
void info(int err, const char *fmt,...)
Definition: log.c:672
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
int date_parse_iso(struct universaltime *ut, Octstr *os)
Definition: date.c:230
Definition: octstr.c:118
#define panic
Definition: log.h:87
void gwlib_shutdown(void)
Definition: gwlib.c:94
void gwlib_init(void)
Definition: gwlib.c:78
int get_and_set_debugs(int argc, char **argv, int(*find_own)(int index, int argc, char **argv))
Definition: utils.c:626
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.