PostgreSQL Source Code  git master
pgtypeslib-dt_test2.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <pgtypes_date.h>
#include <pgtypes_timestamp.h>
Include dependency graph for pgtypeslib-dt_test2.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

int main (void)
 

Variables

char * dates []
 
static char * times []
 
char * intervals []
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file pgtypeslib-dt_test2.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 77 of file pgtypeslib-dt_test2.c.

78 {
79  /* exec sql begin declare section */
80 
81 
82 
83 
84 
85 
86 #line 62 "dt_test2.pgc"
87  date date1 ;
88 
89 #line 63 "dt_test2.pgc"
90  timestamp ts1 , ts2 ;
91 
92 #line 64 "dt_test2.pgc"
93  char * text ;
94 
95 #line 65 "dt_test2.pgc"
96  interval * i1 ;
97 
98 #line 66 "dt_test2.pgc"
99  date * dc ;
100 /* exec sql end declare section */
101 #line 67 "dt_test2.pgc"
102 
103 
104  int i, j;
105  char *endptr;
106 
107  ECPGdebug(1, stderr);
108 
109  ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL);
111 
112  printf("timestamp: %s\n", text);
114 
115  date1 = PGTYPESdate_from_timestamp(ts1);
116  dc = PGTYPESdate_new();
117  *dc = date1;
118  text = PGTYPESdate_to_asc(*dc);
119  printf("Date of timestamp: %s\n", text);
121  PGTYPESdate_free(dc);
122 
123  for (i = 0; dates[i]; i++)
124  {
125  bool err = false;
126  date1 = PGTYPESdate_from_asc(dates[i], &endptr);
127  if (date1 == INT_MIN) {
128  err = true;
129  }
130  text = PGTYPESdate_to_asc(date1);
131  printf("Date[%d]: %s (%c - %c)\n",
132  i, err ? "-" : text,
133  endptr ? 'N' : 'Y',
134  err ? 'T' : 'F');
136  if (!err)
137  {
138  for (j = 0; times[j]; j++)
139  {
140  int length = strlen(dates[i])
141  + 1
142  + strlen(times[j])
143  + 1;
144  char* t = malloc(length);
145  sprintf(t, "%s %s", dates[i], times[j]);
146  ts1 = PGTYPEStimestamp_from_asc(t, NULL);
148  printf("TS[%d,%d]: %s\n",
149  i, j, errno ? "-" : text);
151  free(t);
152  }
153  }
154  }
155 
156  ts1 = PGTYPEStimestamp_from_asc("2004-04-04 23:23:23", NULL);
157 
158  for (i = 0; intervals[i]; i++)
159  {
160  interval *ic;
161  i1 = PGTYPESinterval_from_asc(intervals[i], &endptr);
162  if (*endptr)
163  printf("endptr set to %s\n", endptr);
164  if (!i1)
165  {
166  printf("Error parsing interval %d\n", i);
167  continue;
168  }
169  j = PGTYPEStimestamp_add_interval(&ts1, i1, &ts2);
170  if (j < 0)
171  continue;
173  printf("interval[%d]: %s\n", i, text ? text : "-");
175 
176  ic = PGTYPESinterval_new();
177  PGTYPESinterval_copy(i1, ic);
179  printf("interval_copy[%d]: %s\n", i, text ? text : "-");
183  }
184 
185  return 0;
186 }
struct varlena text
Definition: c.h:691
void err(int eval, const char *fmt,...)
Definition: err.c:43
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
int j
Definition: isn.c:73
int i
Definition: isn.c:72
void PGTYPESchar_free(char *ptr)
Definition: common.c:145
date PGTYPESdate_from_timestamp(timestamp dt)
Definition: datetime.c:31
long date
Definition: pgtypes_date.h:9
date PGTYPESdate_from_asc(char *str, char **endptr)
Definition: datetime.c:47
void PGTYPESdate_free(date *d)
Definition: datetime.c:25
char * PGTYPESdate_to_asc(date dDate)
Definition: datetime.c:101
date * PGTYPESdate_new(void)
Definition: datetime.c:15
void PGTYPESinterval_free(interval *intvl)
Definition: interval.c:997
char * PGTYPESinterval_to_asc(interval *span)
Definition: interval.c:1062
int PGTYPESinterval_copy(interval *intvlsrc, interval *intvldest)
Definition: interval.c:1082
interval * PGTYPESinterval_new(void)
Definition: interval.c:987
interval * PGTYPESinterval_from_asc(char *str, char **endptr)
Definition: interval.c:1003
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
Definition: timestamp.c:202
int64 timestamp
int PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout)
Definition: timestamp.c:858
char * PGTYPEStimestamp_to_asc(timestamp tstamp)
Definition: timestamp.c:268
char * dates[]
static char * times[]
#define ECPGdebug(X, Y)
char * intervals[]
#define sprintf
Definition: port.h:240
#define printf(...)
Definition: port.h:244
Definition: c.h:678

References dates, ECPGdebug, err(), free, i, intervals, j, malloc, PGTYPESchar_free(), PGTYPESdate_free(), PGTYPESdate_from_asc(), PGTYPESdate_from_timestamp(), PGTYPESdate_new(), PGTYPESdate_to_asc(), PGTYPESinterval_copy(), PGTYPESinterval_free(), PGTYPESinterval_from_asc(), PGTYPESinterval_new(), PGTYPESinterval_to_asc(), PGTYPEStimestamp_add_interval(), PGTYPEStimestamp_from_asc(), PGTYPEStimestamp_to_asc(), printf, sprintf, and times.

Variable Documentation

◆ dates

char* dates[]
Initial value:
= { "19990108foobar",
"19990108 foobar",
"1999-01-08 foobar",
"January 8, 1999",
"1999-01-08",
"1/8/1999",
"1/18/1999",
"01/02/03",
"1999-Jan-08",
"Jan-08-1999",
"08-Jan-1999",
"99-Jan-08",
"08-Jan-99",
"08-Jan-06",
"Jan-08-99",
"19990108",
"990108",
"1999.008",
"J2451187",
"January 8, 99 BC",
"........................Xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
".........................aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
NULL }

Definition at line 28 of file pgtypeslib-dt_test2.c.

Referenced by main().

◆ intervals

char* intervals[]
Initial value:
= { "1 minute",
"1 12:59:10",
"2 day 12 hour 59 minute 10 second",
"1 days 12 hrs 59 mins 10 secs",
"1 days 1 hours 1 minutes 1 seconds",
"1 year 59 mins",
"1 year 59 mins foobar",
NULL }

Definition at line 67 of file pgtypeslib-dt_test2.c.

Referenced by btree_xlog_dedup(), and main().

◆ times

char* times[]
static
Initial value:
= { "0:04",
"1:59 PDT",
"13:24:40 -8:00",
"13:24:40.495+3",
"13:24:40.123456123+3",
NULL }

Definition at line 60 of file pgtypeslib-dt_test2.c.

Referenced by main().