5
#include <pgtypes_date.h>
6
#include <pgtypes_timestamp.h>
8
exec sql include ../regression;
10
char *dates[] = { "19990108foobar",
32
/* do not conflict with libc "times" symbol */
33
static char *times[] = { "0:04",
39
char *intervals[] = { "1 minute",
41
"2 day 12 hour 59 minute 10 second",
42
"1 days 12 hrs 59 mins 10 secs",
43
"1 days 1 hours 1 minutes 1 seconds",
45
"1 year 59 mins foobar",
51
exec sql begin declare section;
57
exec sql end declare section;
64
ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL);
65
text = PGTYPEStimestamp_to_asc(ts1);
67
printf("timestamp: %s\n", text);
70
date1 = PGTYPESdate_from_timestamp(ts1);
71
dc = PGTYPESdate_new();
73
text = PGTYPESdate_to_asc(*dc);
74
printf("Date of timestamp: %s\n", text);
78
for (i = 0; dates[i]; i++)
81
date1 = PGTYPESdate_from_asc(dates[i], &endptr);
82
if (date1 == INT_MIN) {
85
text = PGTYPESdate_to_asc(date1);
86
printf("Date[%d]: %s (%c - %c)\n",
93
for (j = 0; times[j]; j++)
95
int length = strlen(dates[i])
99
char* t = malloc(length);
100
sprintf(t, "%s %s", dates[i], times[j]);
101
ts1 = PGTYPEStimestamp_from_asc(t, NULL);
102
text = PGTYPEStimestamp_to_asc(ts1);
103
if (i != 19 || j != 3) /* timestamp as integer or double differ for this case */
104
printf("TS[%d,%d]: %s\n",
105
i, j, errno ? "-" : text);
112
ts1 = PGTYPEStimestamp_from_asc("2004-04-04 23:23:23", NULL);
114
for (i = 0; intervals[i]; i++)
117
i1 = PGTYPESinterval_from_asc(intervals[i], &endptr);
119
printf("endptr set to %s\n", endptr);
122
printf("Error parsing interval %d\n", i);
125
j = PGTYPEStimestamp_add_interval(&ts1, i1, &ts2);
128
text = PGTYPESinterval_to_asc(i1);
129
printf("interval[%d]: %s\n", i, text ? text : "-");
132
ic = PGTYPESinterval_new();
133
PGTYPESinterval_copy(i1, ic);
134
text = PGTYPESinterval_to_asc(i1);
135
printf("interval_copy[%d]: %s\n", i, text ? text : "-");
137
PGTYPESinterval_free(ic);
138
PGTYPESinterval_free(i1);