4
#include <pgtypes_date.h>
5
#include <pgtypes_timestamp.h>
6
#include <pgtypes_interval.h>
11
exec sql begin declare section;
16
exec sql end declare section;
18
int mdy[3] = { 4, 19, 1998 };
20
char *d1 = "Mon Jan 17 1966";
21
char *t1 = "2000-7-12 17:34:29";
25
if ((dbgs = fopen("log", "w")) != NULL)
27
exec sql whenever sqlerror do sqlprint();
28
exec sql connect to mm;
29
exec sql create table date_test (d date, ts timestamp, iv interval);
30
exec sql set datestyle to iso;
32
date1 = PGTYPESdate_from_asc(d1, NULL);
33
ts1 = PGTYPEStimestamp_from_asc(t1, NULL);
35
exec sql insert into date_test(d, ts, iv) values (:date1, :ts1, now()-'Mon Jan 17 1966');
37
exec sql select * into :date1, :ts1 , :iv1 from date_test where d=:date1;
39
text = PGTYPESdate_to_asc(date1);
40
printf ("Date: %s\n", text);
42
text = PGTYPEStimestamp_to_asc(ts1);
43
printf ("timestamp: %s\n", text);
45
text = PGTYPESinterval_to_asc(&iv1);
46
printf ("interval: %s\n", text);
48
PGTYPESdate_mdyjul(mdy, &date2);
49
printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
51
mdy[0] = mdy[1] = mdy[2] = 0;
53
printf("date seems to get encoded to julian %ld\n", date2);
55
PGTYPESdate_julmdy(date2, mdy);
56
printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
58
ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL);
59
text = PGTYPEStimestamp_to_asc(ts1);
61
printf("date_day of %s is %d\n", text, PGTYPESdate_dayofweek(ts1));
63
PGTYPESdate_today(&date1);
64
text = PGTYPESdate_to_asc(date1);
65
printf("today is %s\n", text);
67
fmt = "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end";
68
out = (char*) malloc(strlen(fmt) + 1);
70
PGTYPESdate_fmt_asc(date1, fmt, out);
71
printf("Today in format \"%s\" is \"%s\"\n", fmt, out);
74
/* rdate_defmt_asc() */
78
in = "In the year 1995, the month of December, it is the 25th day";
79
/* 0123456789012345678901234567890123456789012345678901234567890
82
PGTYPESdate_defmt_asc(&date1, fmt, in);
83
text = PGTYPESdate_to_asc(date1);
84
printf("date_defmt_asc1: %s\n", text);
87
fmt = "mmmm. dd. yyyy";
89
PGTYPESdate_defmt_asc(&date1, fmt, in);
90
text = PGTYPESdate_to_asc(date1);
91
printf("date_defmt_asc2: %s\n", text);
96
PGTYPESdate_defmt_asc(&date1, fmt, in);
97
text = PGTYPESdate_to_asc(date1);
98
printf("date_defmt_asc3: %s\n", text);
100
date1 = 0; text = "";
102
in = "1995, December 25th";
103
PGTYPESdate_defmt_asc(&date1, fmt, in);
104
text = PGTYPESdate_to_asc(date1);
105
printf("date_defmt_asc4: %s\n", text);
107
date1 = 0; text = "";
109
in = "This is 25th day of December, 1995";
110
PGTYPESdate_defmt_asc(&date1, fmt, in);
111
text = PGTYPESdate_to_asc(date1);
112
printf("date_defmt_asc5: %s\n", text);
114
date1 = 0; text = "";
116
in = "Dec. 25th, 1995";
117
PGTYPESdate_defmt_asc(&date1, fmt, in);
118
text = PGTYPESdate_to_asc(date1);
119
printf("date_defmt_asc6: %s\n", text);
121
date1 = 0; text = "";
122
fmt = "mmm. dd. yyyy";
123
in = "dec 25th 1995";
124
PGTYPESdate_defmt_asc(&date1, fmt, in);
125
text = PGTYPESdate_to_asc(date1);
126
printf("date_defmt_asc7: %s\n", text);
128
date1 = 0; text = "";
129
fmt = "mmm. dd. yyyy";
131
PGTYPESdate_defmt_asc(&date1, fmt, in);
132
text = PGTYPESdate_to_asc(date1);
133
printf("date_defmt_asc8: %s\n", text);
135
date1 = 0; text = "";
138
PGTYPESdate_defmt_asc(&date1, fmt, in);
139
text = PGTYPESdate_to_asc(date1);
140
printf("date_defmt_asc9: %s\n", text);
142
date1 = 0; text = "";
143
fmt = "yyyy fierj mm dd.";
145
PGTYPESdate_defmt_asc(&date1, fmt, in);
146
text = PGTYPESdate_to_asc(date1);
147
printf("date_defmt_asc10: %s\n", text);
149
date1 = 0; text = "";
152
PGTYPESdate_defmt_asc(&date1, fmt, in);
153
text = PGTYPESdate_to_asc(date1);
154
printf("date_defmt_asc12: %s\n", text);
156
PGTYPEStimestamp_current(&ts1);
157
text = PGTYPEStimestamp_to_asc(ts1);
158
printf("timestamp_current: Now: %s\n", text);
160
ts1 = PGTYPEStimestamp_from_asc("96-02-29", NULL);
161
text = PGTYPEStimestamp_to_asc(ts1);
162
printf("timestamp_to_asc1: %s\n", text);
164
ts1 = PGTYPEStimestamp_from_asc("1994-02-11 3:10:35", NULL);
165
text = PGTYPEStimestamp_to_asc(ts1);
166
printf("timestamp_to_asc2: %s\n", text);
168
ts1 = PGTYPEStimestamp_from_asc("1994-02-11 26:10:35", NULL);
169
text = PGTYPEStimestamp_to_asc(ts1);
170
printf("timestamp_to_asc3: %s\n", text);
172
/* abc-03:10:35-def-02/11/94-gh */
173
/* 12345678901234567890123456789 */
175
out = (char*) malloc(32);
176
i = PGTYPEStimestamp_fmt_asc(&ts1, out, 31, "abc-%X-def-%x-ghi%%");
177
printf("timestamp_fmt_asc: %d: %s\n", i, out);
179
fmt = "This is a %m/%d/%y %H-%Ml%Stest";
180
in = "This is a 4/12/80 3-39l12test";
181
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
182
text = PGTYPEStimestamp_to_asc(ts1);
183
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
185
fmt = "%a %b %d %H:%M:%S %z %Y";
186
in = "Tue Jul 22 17:28:44 +0200 2003";
187
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
188
text = PGTYPEStimestamp_to_asc(ts1);
189
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
191
fmt = "%a %b %d %H:%M:%S %z %Y";
192
in = "Tue Feb 29 17:28:44 +0200 2000";
193
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
194
text = PGTYPEStimestamp_to_asc(ts1);
195
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
197
fmt = "%a %b %d %H:%M:%S %z %Y";
198
in = "Tue Feb 29 17:28:44 +0200 1900";
199
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
200
text = PGTYPEStimestamp_to_asc(ts1);
201
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
203
fmt = "%a %b %d %H:%M:%S %z %Y";
204
in = "Tue Feb 29 17:28:44 +0200 1996";
205
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
206
text = PGTYPEStimestamp_to_asc(ts1);
207
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
209
fmt = "%b %d %H:%M:%S %z %Y";
210
in = " Jul 31 17:28:44 +0200 1996";
211
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
212
text = PGTYPEStimestamp_to_asc(ts1);
213
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
215
fmt = "%b %d %H:%M:%S %z %Y";
216
in = " Jul 32 17:28:44 +0200 1996";
217
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
218
text = PGTYPEStimestamp_to_asc(ts1);
219
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
221
fmt = "%a %b %d %H:%M:%S %z %Y";
222
in = "Tue Feb 29 17:28:44 +0200 1997";
223
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
224
text = PGTYPEStimestamp_to_asc(ts1);
225
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
228
in = "Tue Jul 22 17:28:44 +0200 2003";
229
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
230
text = PGTYPEStimestamp_to_asc(ts1);
231
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
234
in = "Tue Jul 22 17:28:44 +0200 2003";
235
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
236
text = PGTYPEStimestamp_to_asc(ts1);
237
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
239
fmt = "%b, %d %H_%M`%S %z %Y";
240
in = " Jul, 22 17_28 `44 +0200 2003 ";
241
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
242
text = PGTYPEStimestamp_to_asc(ts1);
243
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
245
fmt = "%a %b %%%d %H:%M:%S %Z %Y";
246
in = "Tue Jul %22 17:28:44 CEST 2003";
247
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
248
text = PGTYPEStimestamp_to_asc(ts1);
249
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
251
fmt = "%a %b %%%d %H:%M:%S %Z %Y";
252
in = "Tue Jul %22 17:28:44 CEST 2003";
253
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
254
text = PGTYPEStimestamp_to_asc(ts1);
255
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
257
fmt = "abc%n %C %B %%%d %H:%M:%S %Z %Y";
258
in = "abc\n 19 October %22 17:28:44 CEST 2003";
259
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
260
text = PGTYPEStimestamp_to_asc(ts1);
261
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
263
fmt = "abc%n %C %B %%%d %H:%M:%S %Z %y";
264
in = "abc\n 18 October %34 17:28:44 CEST 80";
265
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
266
text = PGTYPEStimestamp_to_asc(ts1);
267
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
270
in = "abc\n 18 October %34 17:28:44 CEST 80";
271
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
272
text = PGTYPEStimestamp_to_asc(ts1);
273
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
276
in = "1980-04-12 3:49:44 ";
277
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
278
text = PGTYPEStimestamp_to_asc(ts1);
279
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
281
fmt = "%B %d, %Y. Time: %I:%M%p";
282
in = "July 14, 1988. Time: 9:15am";
283
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
284
text = PGTYPEStimestamp_to_asc(ts1);
285
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
287
in = "September 6 at 01:30 pm in the year 1983";
288
fmt = "%B %d at %I:%M %p in the year %Y";
289
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
290
text = PGTYPEStimestamp_to_asc(ts1);
291
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
293
in = " 1976, July 14. Time: 9:15am";
294
fmt = "%Y, %B %d. Time: %I:%M %p";
295
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
296
text = PGTYPEStimestamp_to_asc(ts1);
297
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
299
in = " 1976, July 14. Time: 9:15 am";
300
fmt = "%Y, %B %d. Time: %I:%M%p";
301
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
302
text = PGTYPEStimestamp_to_asc(ts1);
303
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
305
in = " 1976, P.M. July 14. Time: 9:15";
306
fmt = "%Y, %P %B %d. Time: %I:%M";
307
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
308
text = PGTYPEStimestamp_to_asc(ts1);
309
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);