4
#include <pgtypes_date.h>
5
#include <pgtypes_timestamp.h>
6
#include <pgtypes_interval.h>
8
exec sql include ../regression;
13
exec sql begin declare section;
18
exec sql end declare section;
20
int mdy[3] = { 4, 19, 1998 };
22
char *d1 = "Mon Jan 17 1966";
23
char *t1 = "2000-7-12 17:34:29";
27
exec sql whenever sqlerror do sqlprint();
28
exec sql connect to REGRESSDB1;
29
exec sql create table date_test (d date, ts timestamp);
30
exec sql set datestyle to iso;
31
exec sql set intervalstyle to postgres_verbose;
33
date1 = PGTYPESdate_from_asc(d1, NULL);
34
ts1 = PGTYPEStimestamp_from_asc(t1, NULL);
36
exec sql insert into date_test(d, ts) values (:date1, :ts1);
38
exec sql select * into :date1, :ts1 from date_test where d=:date1;
40
text = PGTYPESdate_to_asc(date1);
41
printf ("Date: %s\n", text);
44
text = PGTYPEStimestamp_to_asc(ts1);
45
printf ("timestamp: %s\n", text);
48
iv1 = PGTYPESinterval_from_asc("13556 days 12 hours 34 minutes 14 seconds ", NULL);
49
PGTYPESinterval_copy(iv1, &iv2);
50
text = PGTYPESinterval_to_asc(&iv2);
51
printf ("interval: %s\n", text);
52
PGTYPESinterval_free(iv1);
55
PGTYPESdate_mdyjul(mdy, &date2);
56
printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
58
mdy[0] = mdy[1] = mdy[2] = 0;
60
printf("date seems to get encoded to julian %ld\n", date2);
62
PGTYPESdate_julmdy(date2, mdy);
63
printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
65
ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL);
66
text = PGTYPEStimestamp_to_asc(ts1);
67
fmt = "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end";
68
out = (char*) malloc(strlen(fmt) + 1);
69
date1 = PGTYPESdate_from_timestamp(ts1);
70
PGTYPESdate_fmt_asc(date1, fmt, out);
71
printf("date_day of %s is %d\n", text, PGTYPESdate_dayofweek(date1));
72
printf("Above date in format \"%s\" is \"%s\"\n", fmt, out);
76
/* rdate_defmt_asc() */
80
in = "In the year 1995, the month of December, it is the 25th day";
81
/* 0123456789012345678901234567890123456789012345678901234567890
84
PGTYPESdate_defmt_asc(&date1, fmt, in);
85
text = PGTYPESdate_to_asc(date1);
86
printf("date_defmt_asc1: %s\n", text);
90
fmt = "mmmm. dd. yyyy";
92
PGTYPESdate_defmt_asc(&date1, fmt, in);
93
text = PGTYPESdate_to_asc(date1);
94
printf("date_defmt_asc2: %s\n", text);
100
PGTYPESdate_defmt_asc(&date1, fmt, in);
101
text = PGTYPESdate_to_asc(date1);
102
printf("date_defmt_asc3: %s\n", text);
105
date1 = 0; text = "";
107
in = "1995, December 25th";
108
PGTYPESdate_defmt_asc(&date1, fmt, in);
109
text = PGTYPESdate_to_asc(date1);
110
printf("date_defmt_asc4: %s\n", text);
113
date1 = 0; text = "";
115
in = "This is 25th day of December, 1995";
116
PGTYPESdate_defmt_asc(&date1, fmt, in);
117
text = PGTYPESdate_to_asc(date1);
118
printf("date_defmt_asc5: %s\n", text);
121
date1 = 0; text = "";
123
in = "Dec. 25th, 1995";
124
PGTYPESdate_defmt_asc(&date1, fmt, in);
125
text = PGTYPESdate_to_asc(date1);
126
printf("date_defmt_asc6: %s\n", text);
129
date1 = 0; text = "";
130
fmt = "mmm. dd. yyyy";
131
in = "dec 25th 1995";
132
PGTYPESdate_defmt_asc(&date1, fmt, in);
133
text = PGTYPESdate_to_asc(date1);
134
printf("date_defmt_asc7: %s\n", text);
137
date1 = 0; text = "";
138
fmt = "mmm. dd. yyyy";
140
PGTYPESdate_defmt_asc(&date1, fmt, in);
141
text = PGTYPESdate_to_asc(date1);
142
printf("date_defmt_asc8: %s\n", text);
145
date1 = 0; text = "";
148
PGTYPESdate_defmt_asc(&date1, fmt, in);
149
text = PGTYPESdate_to_asc(date1);
150
printf("date_defmt_asc9: %s\n", text);
153
date1 = 0; text = "";
154
fmt = "yyyy fierj mm dd.";
156
PGTYPESdate_defmt_asc(&date1, fmt, in);
157
text = PGTYPESdate_to_asc(date1);
158
printf("date_defmt_asc10: %s\n", text);
161
date1 = 0; text = "";
164
PGTYPESdate_defmt_asc(&date1, fmt, in);
165
text = PGTYPESdate_to_asc(date1);
166
printf("date_defmt_asc12: %s\n", text);
169
PGTYPEStimestamp_current(&ts1);
170
text = PGTYPEStimestamp_to_asc(ts1);
171
/* can't output this in regression mode */
172
/* printf("timestamp_current: Now: %s\n", text); */
175
ts1 = PGTYPEStimestamp_from_asc("96-02-29", NULL);
176
text = PGTYPEStimestamp_to_asc(ts1);
177
printf("timestamp_to_asc1: %s\n", text);
180
ts1 = PGTYPEStimestamp_from_asc("1994-02-11 3:10:35", NULL);
181
text = PGTYPEStimestamp_to_asc(ts1);
182
printf("timestamp_to_asc2: %s\n", text);
185
ts1 = PGTYPEStimestamp_from_asc("1994-02-11 26:10:35", NULL);
186
text = PGTYPEStimestamp_to_asc(ts1);
187
printf("timestamp_to_asc3: %s\n", text);
190
/* abc-03:10:35-def-02/11/94-gh */
191
/* 12345678901234567890123456789 */
193
out = (char*) malloc(32);
194
i = PGTYPEStimestamp_fmt_asc(&ts1, out, 31, "abc-%X-def-%x-ghi%%");
195
printf("timestamp_fmt_asc: %d: %s\n", i, out);
198
fmt = "This is a %m/%d/%y %H-%Ml%Stest";
199
in = "This is a 4/12/80 3-39l12test";
200
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
201
text = PGTYPEStimestamp_to_asc(ts1);
202
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
205
fmt = "%a %b %d %H:%M:%S %z %Y";
206
in = "Tue Jul 22 17:28:44 +0200 2003";
207
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
208
text = PGTYPEStimestamp_to_asc(ts1);
209
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
212
fmt = "%a %b %d %H:%M:%S %z %Y";
213
in = "Tue Feb 29 17:28:44 +0200 2000";
214
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
215
text = PGTYPEStimestamp_to_asc(ts1);
216
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
219
fmt = "%a %b %d %H:%M:%S %z %Y";
220
in = "Tue Feb 29 17:28:44 +0200 1900";
221
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
222
text = PGTYPEStimestamp_to_asc(ts1);
223
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
226
fmt = "%a %b %d %H:%M:%S %z %Y";
227
in = "Tue Feb 29 17:28:44 +0200 1996";
228
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
229
text = PGTYPEStimestamp_to_asc(ts1);
230
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
233
fmt = "%b %d %H:%M:%S %z %Y";
234
in = " Jul 31 17:28:44 +0200 1996";
235
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
236
text = PGTYPEStimestamp_to_asc(ts1);
237
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
240
fmt = "%b %d %H:%M:%S %z %Y";
241
in = " Jul 32 17:28:44 +0200 1996";
242
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
243
text = PGTYPEStimestamp_to_asc(ts1);
244
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
247
fmt = "%a %b %d %H:%M:%S %z %Y";
248
in = "Tue Feb 29 17:28:44 +0200 1997";
249
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
250
text = PGTYPEStimestamp_to_asc(ts1);
251
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
255
in = "Tue Jul 22 17:28:44 +0200 2003";
256
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
257
text = PGTYPEStimestamp_to_asc(ts1);
258
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
262
in = "Tue Jul 22 17:28:44 +0200 2003";
263
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
264
text = PGTYPEStimestamp_to_asc(ts1);
265
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
268
fmt = "%b, %d %H_%M`%S %z %Y";
269
in = " Jul, 22 17_28 `44 +0200 2003 ";
270
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
271
text = PGTYPEStimestamp_to_asc(ts1);
272
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
275
fmt = "%a %b %%%d %H:%M:%S %Z %Y";
276
in = "Tue Jul %22 17:28:44 CEST 2003";
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);
282
fmt = "%a %b %%%d %H:%M:%S %Z %Y";
283
in = "Tue Jul %22 17:28:44 CEST 2003";
284
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
285
text = PGTYPEStimestamp_to_asc(ts1);
286
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
289
fmt = "abc%n %C %B %%%d %H:%M:%S %Z %Y";
290
in = "abc\n 19 October %22 17:28:44 CEST 2003";
291
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
292
text = PGTYPEStimestamp_to_asc(ts1);
293
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
296
fmt = "abc%n %C %B %%%d %H:%M:%S %Z %y";
297
in = "abc\n 18 October %34 17:28:44 CEST 80";
298
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
299
text = PGTYPEStimestamp_to_asc(ts1);
300
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
304
in = "abc\n 18 October %34 17:28:44 CEST 80";
305
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
306
text = PGTYPEStimestamp_to_asc(ts1);
307
printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
311
in = "1980-04-12 3:49:44 ";
312
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
313
text = PGTYPEStimestamp_to_asc(ts1);
314
printf("timestamp_defmt_asc(%s, NULL) = %s, error: %d\n", in, text, i);
317
fmt = "%B %d, %Y. Time: %I:%M%p";
318
in = "July 14, 1988. Time: 9:15am";
319
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
320
text = PGTYPEStimestamp_to_asc(ts1);
321
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
324
in = "September 6 at 01:30 pm in the year 1983";
325
fmt = "%B %d at %I:%M %p in the year %Y";
326
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
327
text = PGTYPEStimestamp_to_asc(ts1);
328
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
331
in = " 1976, July 14. Time: 9:15am";
332
fmt = "%Y, %B %d. Time: %I:%M %p";
333
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
334
text = PGTYPEStimestamp_to_asc(ts1);
335
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
338
in = " 1976, July 14. Time: 9:15 am";
339
fmt = "%Y, %B %d. Time: %I:%M%p";
340
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
341
text = PGTYPEStimestamp_to_asc(ts1);
342
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
345
in = " 1976, P.M. July 14. Time: 9:15";
346
fmt = "%Y, %P %B %d. Time: %I:%M";
347
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
348
text = PGTYPEStimestamp_to_asc(ts1);
349
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
354
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
355
text = PGTYPEStimestamp_to_asc(ts1);
356
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);