PostgreSQL Source Code git master
Loading...
Searching...
No Matches
timestamp.c
Go to the documentation of this file.
1/*
2 * src/interfaces/ecpg/pgtypeslib/timestamp.c
3 */
4#include "postgres_fe.h"
5
6#include <time.h>
7#include <limits.h>
8#include <math.h>
9
10#include "common/int.h"
11#include "dt.h"
12#include "pgtypes_date.h"
13#include "pgtypes_timestamp.h"
14#include "pgtypeslib_extern.h"
15
16static int64
17time2t(const int hour, const int min, const int sec, const fsec_t fsec)
18{
19 return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
20} /* time2t() */
21
22static timestamp
24{
25 dt -= (tz * USECS_PER_SEC);
26 return dt;
27} /* dt2local() */
28
29/* tm2timestamp()
30 * Convert a tm structure to a timestamp data type.
31 * Note that year is _not_ 1900-based, but is an explicit full value.
32 * Also, month is one-based, _not_ zero-based.
33 *
34 * Returns -1 on failure (overflow).
35 */
36int
37tm2timestamp(struct tm *tm, fsec_t fsec, int *tzp, timestamp * result)
38{
39 int dDate;
40 int64 time;
41
42 /* Prevent overflow in Julian-day routines */
44 return -1;
45
46 dDate = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
47 time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
49 pg_add_s64_overflow(*result, time, result)))
50 return -1;
51 if (tzp != NULL)
52 *result = dt2local(*result, -(*tzp));
53
54 /* final range check catches just-out-of-range timestamps */
55 if (!IS_VALID_TIMESTAMP(*result))
56 return -1;
57
58 return 0;
59} /* tm2timestamp() */
60
61static timestamp
63{
64 int64 noresult = 0;
66 struct tm tt,
67 *tm = &tt;
68
69 if (GetEpochTime(tm) < 0)
70 return noresult;
71
72 tm2timestamp(tm, 0, NULL, &dt);
73 return dt;
74} /* SetEpochTimestamp() */
75
76/* timestamp2tm()
77 * Convert timestamp data type to POSIX time structure.
78 * Note that year is _not_ 1900-based, but is an explicit full value.
79 * Also, month is one-based, _not_ zero-based.
80 * Returns:
81 * 0 on success
82 * -1 on out of range
83 *
84 * For dates within the system-supported time_t range, convert to the
85 * local time zone. If out of this range, leave as GMT. - tgl 97/05/27
86 */
87static int
88timestamp2tm(timestamp dt, int *tzp, struct tm *tm, fsec_t *fsec, const char **tzn)
89{
91 date0;
92 int64 time;
93#if defined(HAVE_STRUCT_TM_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
95 struct tm *tx;
96#endif
97
98 date0 = date2j(2000, 1, 1);
99
100 time = dt;
102
103 if (time < INT64CONST(0))
104 {
105 time += USECS_PER_DAY;
106 dDate -= 1;
107 }
108
109 /* add offset to go from J2000 back to standard Julian date */
110 dDate += date0;
111
112 /* Julian day routine does not work for negative Julian days */
114 return -1;
115
116 j2date((int) dDate, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
117 dt2time(time, &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
118
119 if (tzp != NULL)
120 {
121 /*
122 * Does this fall within the capabilities of the localtime()
123 * interface? Then use this to rotate to the local time zone.
124 */
126 {
127#if defined(HAVE_STRUCT_TM_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
128 struct tm tmbuf;
129
131 ((date0 - date2j(1970, 1, 1)) * INT64CONST(86400));
132
134 tm->tm_year = tx->tm_year + 1900;
135 tm->tm_mon = tx->tm_mon + 1;
136 tm->tm_mday = tx->tm_mday;
137 tm->tm_hour = tx->tm_hour;
138 tm->tm_min = tx->tm_min;
139 tm->tm_isdst = tx->tm_isdst;
140
141#if defined(HAVE_STRUCT_TM_TM_ZONE)
142 tm->tm_gmtoff = tx->tm_gmtoff;
143 tm->tm_zone = tx->tm_zone;
144
145 *tzp = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
146 if (tzn != NULL)
147 *tzn = tm->tm_zone;
148#elif defined(HAVE_INT_TIMEZONE)
150 if (tzn != NULL)
151 *tzn = TZNAME_GLOBAL[(tm->tm_isdst > 0)];
152#endif
153#else /* not (HAVE_STRUCT_TM_TM_ZONE ||
154 * HAVE_INT_TIMEZONE) */
155 *tzp = 0;
156 /* Mark this as *no* time zone available */
157 tm->tm_isdst = -1;
158 if (tzn != NULL)
159 *tzn = NULL;
160#endif
161 }
162 else
163 {
164 *tzp = 0;
165 /* Mark this as *no* time zone available */
166 tm->tm_isdst = -1;
167 if (tzn != NULL)
168 *tzn = NULL;
169 }
170 }
171 else
172 {
173 tm->tm_isdst = -1;
174 if (tzn != NULL)
175 *tzn = NULL;
176 }
177
178 tm->tm_yday = dDate - date2j(tm->tm_year, 1, 1) + 1;
179
180 return 0;
181} /* timestamp2tm() */
182
183/* EncodeSpecialTimestamp()
184 * * Convert reserved timestamp data type to string.
185 * */
186static void
188{
190 strcpy(str, EARLY);
191 else if (TIMESTAMP_IS_NOEND(dt))
192 strcpy(str, LATE);
193 else
194 abort(); /* shouldn't happen */
195}
196
198PGTYPEStimestamp_from_asc(char *str, char **endptr)
199{
200 timestamp result;
201 int64 noresult = 0;
202 fsec_t fsec;
203 struct tm tt,
204 *tm = &tt;
205 int dtype;
206 int nf;
207 char *field[MAXDATEFIELDS];
208 int ftype[MAXDATEFIELDS];
210 char *realptr;
211 char **ptr = (endptr != NULL) ? endptr : &realptr;
212
213 if (strlen(str) > MAXDATELEN)
214 {
216 return noresult;
217 }
218
219 if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
220 DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, 0) != 0)
221 {
223 return noresult;
224 }
225
226 switch (dtype)
227 {
228 case DTK_DATE:
229 if (tm2timestamp(tm, fsec, NULL, &result) != 0)
230 {
232 return noresult;
233 }
234 break;
235
236 case DTK_EPOCH:
237 result = SetEpochTimestamp();
238 break;
239
240 case DTK_LATE:
241 TIMESTAMP_NOEND(result);
242 break;
243
244 case DTK_EARLY:
245 TIMESTAMP_NOBEGIN(result);
246 break;
247
248 default:
250 return noresult;
251 }
252
253 /* AdjustTimestampForTypmod(&result, typmod); */
254
255 /*
256 * Since it's difficult to test for noresult, make sure errno is 0 if no
257 * error occurred.
258 */
259 errno = 0;
260 return result;
261}
262
263char *
265{
266 struct tm tt,
267 *tm = &tt;
268 char buf[MAXDATELEN + 1];
269 fsec_t fsec;
270 int DateStyle = 1; /* this defaults to USE_ISO_DATES, shall we
271 * make it an option? */
272
275 else if (timestamp2tm(tstamp, NULL, tm, &fsec, NULL) == 0)
276 EncodeDateTime(tm, fsec, false, 0, NULL, DateStyle, buf, 0);
277 else
278 {
280 return NULL;
281 }
282 return pgtypes_strdup(buf);
283}
284
285void
287{
288 struct tm tm;
289
291 if (errno == 0)
292 tm2timestamp(&tm, 0, NULL, ts);
293}
294
295static int
297 char *output, int *pstr_len, const char *fmtstr)
298{
300 int replace_type;
301 int i;
302 const char *p = fmtstr;
303 char *q = output;
304
305 while (*p)
306 {
307 if (*p == '%')
308 {
309 p++;
310 /* fix compiler warning */
312 switch (*p)
313 {
314 /* the abbreviated name of the day in the week */
315 /* XXX should be locale aware */
316 case 'a':
319 break;
320 /* the full name of the day in the week */
321 /* XXX should be locale aware */
322 case 'A':
323 replace_val.str_val = days[dow];
325 break;
326 /* the abbreviated name of the month */
327 /* XXX should be locale aware */
328 case 'b':
329 case 'h':
330 replace_val.str_val = months[tm->tm_mon - 1];
332 break;
333 /* the full name of the month */
334 /* XXX should be locale aware */
335 case 'B':
338 break;
339
340 /*
341 * The preferred date and time representation for the
342 * current locale.
343 */
344 case 'c':
345 /* XXX */
346 break;
347 /* the century number with leading zeroes */
348 case 'C':
349 replace_val.uint_val = tm->tm_year / 100;
351 break;
352 /* day with leading zeroes (01 - 31) */
353 case 'd':
354 replace_val.uint_val = tm->tm_mday;
356 break;
357 /* the date in the format mm/dd/yy */
358 case 'D':
359
360 /*
361 * ts, dDate, dow, tm is information about the timestamp
362 *
363 * q is the start of the current output buffer
364 *
365 * pstr_len is a pointer to the remaining size of output,
366 * i.e. the size of q
367 */
369 q, pstr_len,
370 "%m/%d/%y");
371 if (i)
372 return i;
373 break;
374 /* day with leading spaces (01 - 31) */
375 case 'e':
376 replace_val.uint_val = tm->tm_mday;
378 break;
379
380 /*
381 * alternative format modifier
382 */
383 case 'E':
384 {
385 char tmp[4] = "%Ex";
386
387 p++;
388 if (*p == '\0')
389 return -1;
390 tmp[2] = *p;
391
392 /*
393 * strftime's month is 0 based, ours is 1 based
394 */
395 tm->tm_mon -= 1;
396 i = strftime(q, *pstr_len, tmp, tm);
397 if (i == 0)
398 return -1;
399 while (*q)
400 {
401 q++;
402 (*pstr_len)--;
403 }
404 tm->tm_mon += 1;
406 break;
407 }
408
409 /*
410 * The ISO 8601 year with century as a decimal number. The
411 * 4-digit year corresponding to the ISO week number.
412 */
413 case 'G':
414 {
415 /* Keep compiler quiet - Don't use a literal format */
416 const char *fmt = "%G";
417
418 tm->tm_mon -= 1;
419 i = strftime(q, *pstr_len, fmt, tm);
420 if (i == 0)
421 return -1;
422 while (*q)
423 {
424 q++;
425 (*pstr_len)--;
426 }
427 tm->tm_mon += 1;
429 }
430 break;
431
432 /*
433 * Like %G, but without century, i.e., with a 2-digit year
434 * (00-99).
435 */
436 case 'g':
437 {
438 const char *fmt = "%g"; /* Keep compiler quiet about
439 * 2-digit year */
440
441 tm->tm_mon -= 1;
442 i = strftime(q, *pstr_len, fmt, tm);
443 if (i == 0)
444 return -1;
445 while (*q)
446 {
447 q++;
448 (*pstr_len)--;
449 }
450 tm->tm_mon += 1;
452 }
453 break;
454 /* hour (24 hour clock) with leading zeroes */
455 case 'H':
456 replace_val.uint_val = tm->tm_hour;
458 break;
459 /* hour (12 hour clock) with leading zeroes */
460 case 'I':
461 replace_val.uint_val = tm->tm_hour % 12;
463 break;
464
465 /*
466 * The day of the year as a decimal number with leading
467 * zeroes. It ranges from 001 to 366.
468 */
469 case 'j':
470 replace_val.uint_val = tm->tm_yday;
472 break;
473
474 /*
475 * The hour (24 hour clock). Leading zeroes will be turned
476 * into spaces.
477 */
478 case 'k':
479 replace_val.uint_val = tm->tm_hour;
481 break;
482
483 /*
484 * The hour (12 hour clock). Leading zeroes will be turned
485 * into spaces.
486 */
487 case 'l':
488 replace_val.uint_val = tm->tm_hour % 12;
490 break;
491 /* The month as a decimal number with a leading zero */
492 case 'm':
493 replace_val.uint_val = tm->tm_mon;
495 break;
496 /* The minute as a decimal number with a leading zero */
497 case 'M':
498 replace_val.uint_val = tm->tm_min;
500 break;
501 /* A newline character */
502 case 'n':
503 replace_val.char_val = '\n';
505 break;
506 /* the AM/PM specifier (uppercase) */
507 /* XXX should be locale aware */
508 case 'p':
509 if (tm->tm_hour < 12)
510 replace_val.str_val = "AM";
511 else
512 replace_val.str_val = "PM";
514 break;
515 /* the AM/PM specifier (lowercase) */
516 /* XXX should be locale aware */
517 case 'P':
518 if (tm->tm_hour < 12)
519 replace_val.str_val = "am";
520 else
521 replace_val.str_val = "pm";
523 break;
524 /* the time in the format %I:%M:%S %p */
525 /* XXX should be locale aware */
526 case 'r':
528 q, pstr_len,
529 "%I:%M:%S %p");
530 if (i)
531 return i;
532 break;
533 /* The time in 24 hour notation (%H:%M) */
534 case 'R':
536 q, pstr_len,
537 "%H:%M");
538 if (i)
539 return i;
540 break;
541 /* The number of seconds since the Epoch (1970-01-01) */
542 case 's':
543 replace_val.int64_val = (*ts - SetEpochTimestamp()) / 1000000.0;
545 break;
546 /* seconds as a decimal number with leading zeroes */
547 case 'S':
548 replace_val.uint_val = tm->tm_sec;
550 break;
551 /* A tabulator */
552 case 't':
553 replace_val.char_val = '\t';
555 break;
556 /* The time in 24 hour notation (%H:%M:%S) */
557 case 'T':
559 q, pstr_len,
560 "%H:%M:%S");
561 if (i)
562 return i;
563 break;
564
565 /*
566 * The day of the week as a decimal, Monday = 1, Sunday =
567 * 7
568 */
569 case 'u':
570 replace_val.uint_val = dow;
571 if (replace_val.uint_val == 0)
572 replace_val.uint_val = 7;
574 break;
575 /* The week number of the year as a decimal number */
576 case 'U':
577 tm->tm_mon -= 1;
578 i = strftime(q, *pstr_len, "%U", tm);
579 if (i == 0)
580 return -1;
581 while (*q)
582 {
583 q++;
584 (*pstr_len)--;
585 }
586 tm->tm_mon += 1;
588 break;
589
590 /*
591 * The ISO 8601:1988 week number of the current year as a
592 * decimal number.
593 */
594 case 'V':
595 {
596 /* Keep compiler quiet - Don't use a literal format */
597 const char *fmt = "%V";
598
599 i = strftime(q, *pstr_len, fmt, tm);
600 if (i == 0)
601 return -1;
602 while (*q)
603 {
604 q++;
605 (*pstr_len)--;
606 }
608 }
609 break;
610
611 /*
612 * The day of the week as a decimal, Sunday being 0 and
613 * Monday 1.
614 */
615 case 'w':
616 replace_val.uint_val = dow;
618 break;
619 /* The week number of the year (another definition) */
620 case 'W':
621 tm->tm_mon -= 1;
622 i = strftime(q, *pstr_len, "%U", tm);
623 if (i == 0)
624 return -1;
625 while (*q)
626 {
627 q++;
628 (*pstr_len)--;
629 }
630 tm->tm_mon += 1;
632 break;
633
634 /*
635 * The preferred date representation for the current
636 * locale without the time.
637 */
638 case 'x':
639 {
640 const char *fmt = "%x"; /* Keep compiler quiet about
641 * 2-digit year */
642
643 tm->tm_mon -= 1;
644 i = strftime(q, *pstr_len, fmt, tm);
645 if (i == 0)
646 return -1;
647 while (*q)
648 {
649 q++;
650 (*pstr_len)--;
651 }
652 tm->tm_mon += 1;
654 }
655 break;
656
657 /*
658 * The preferred time representation for the current
659 * locale without the date.
660 */
661 case 'X':
662 tm->tm_mon -= 1;
663 i = strftime(q, *pstr_len, "%X", tm);
664 if (i == 0)
665 return -1;
666 while (*q)
667 {
668 q++;
669 (*pstr_len)--;
670 }
671 tm->tm_mon += 1;
673 break;
674 /* The year without the century (2 digits, leading zeroes) */
675 case 'y':
676 replace_val.uint_val = tm->tm_year % 100;
678 break;
679 /* The year with the century (4 digits) */
680 case 'Y':
681 replace_val.uint_val = tm->tm_year;
683 break;
684 /* The time zone offset from GMT */
685 case 'z':
686 tm->tm_mon -= 1;
687 i = strftime(q, *pstr_len, "%z", tm);
688 if (i == 0)
689 return -1;
690 while (*q)
691 {
692 q++;
693 (*pstr_len)--;
694 }
695 tm->tm_mon += 1;
697 break;
698 /* The name or abbreviation of the time zone */
699 case 'Z':
700 tm->tm_mon -= 1;
701 i = strftime(q, *pstr_len, "%Z", tm);
702 if (i == 0)
703 return -1;
704 while (*q)
705 {
706 q++;
707 (*pstr_len)--;
708 }
709 tm->tm_mon += 1;
711 break;
712 /* A % sign */
713 case '%':
714 replace_val.char_val = '%';
716 break;
717 case '\0':
718 /* fmtstr: foo%' - The string ends with a % sign */
719
720 /*
721 * this is not compliant to the specification
722 */
723 return -1;
724 default:
725
726 /*
727 * if we don't know the pattern, we just copy it
728 */
729 if (*pstr_len > 1)
730 {
731 *q = '%';
732 q++;
733 (*pstr_len)--;
734 if (*pstr_len > 1)
735 {
736 *q = *p;
737 q++;
738 (*pstr_len)--;
739 }
740 else
741 {
742 *q = '\0';
743 return -1;
744 }
745 *q = '\0';
746 }
747 else
748 return -1;
749 break;
750 }
752 if (i)
753 return i;
754 }
755 else
756 {
757 if (*pstr_len > 1)
758 {
759 *q = *p;
760 (*pstr_len)--;
761 q++;
762 *q = '\0';
763 }
764 else
765 return -1;
766 }
767 p++;
768 }
769 return 0;
770}
771
772
773int
775{
776 struct tm tm;
777 fsec_t fsec;
778 date dDate;
779 int dow;
780
783 timestamp2tm(*ts, NULL, &tm, &fsec, NULL);
784
786}
787
788int
790{
793 else
794 iv->time = (*ts1 - *ts2);
795
796 iv->month = 0;
797
798 return 0;
799}
800
801int
802PGTYPEStimestamp_defmt_asc(const char *str, const char *fmt, timestamp * d)
803{
804 int year,
805 month,
806 day;
807 int hour,
808 minute,
809 second;
810 int tz;
811
812 int i;
813 char *mstr;
814 char *mfmt;
815
816 if (!fmt)
817 fmt = "%Y-%m-%d %H:%M:%S";
818 if (!fmt[0])
819 return 1;
820
823
824 /*
825 * initialize with impossible values so that we can see if the fields
826 * where specified at all
827 */
828 /* XXX ambiguity with 1 BC for year? */
829 year = -1;
830 month = -1;
831 day = -1;
832 hour = 0;
833 minute = -1;
834 second = -1;
835 tz = 0;
836
837 i = PGTYPEStimestamp_defmt_scan(&mstr, mfmt, d, &year, &month, &day, &hour, &minute, &second, &tz);
838 free(mstr);
839 free(mfmt);
840 return i;
841}
842
843/*
844* add an interval to a time stamp
845*
846* *tout = tin + span
847*
848* returns 0 if successful
849* returns -1 if it fails
850*
851*/
852
853int
855{
857 *tout = *tin;
858 else
859 {
860 if (span->month != 0)
861 {
862 struct tm tt,
863 *tm = &tt;
864 fsec_t fsec;
865
866 if (timestamp2tm(*tin, NULL, tm, &fsec, NULL) != 0)
867 return -1;
868 tm->tm_mon += span->month;
870 {
871 tm->tm_year += (tm->tm_mon - 1) / MONTHS_PER_YEAR;
872 tm->tm_mon = (tm->tm_mon - 1) % MONTHS_PER_YEAR + 1;
873 }
874 else if (tm->tm_mon < 1)
875 {
878 }
879
880
881 /* adjust for end of month boundary problems... */
882 if (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
883 tm->tm_mday = (day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]);
884
885
886 if (tm2timestamp(tm, fsec, NULL, tin) != 0)
887 return -1;
888 }
889
890 *tin += span->time;
891 *tout = *tin;
892 }
893
894 return 0;
895}
896
897
898/*
899* subtract an interval from a time stamp
900*
901* *tout = tin - span
902*
903* returns 0 if successful
904* returns -1 if it fails
905*
906*/
907
908int
910{
912
913 tspan.month = -span->month;
914 tspan.time = -span->time;
915
917}
const int day_tab[2][13]
Definition datetime.c:76
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition datetime.c:774
void j2date(int jd, int *year, int *month, int *day)
Definition datetime.c:322
void GetCurrentDateTime(struct pg_tm *tm)
Definition datetime.c:377
void EncodeDateTime(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str)
Definition datetime.c:4465
const char *const months[]
Definition datetime.c:82
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
Definition datetime.c:998
int date2j(int year, int month, int day)
Definition datetime.c:297
const char *const days[]
Definition datetime.c:85
void dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
Definition timestamp.c:1874
void GetEpochTime(struct pg_tm *tm)
Definition timestamp.c:2159
Timestamp SetEpochTimestamp(void)
Definition timestamp.c:2181
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition timestamp.c:1997
void EncodeSpecialTimestamp(Timestamp dt, char *str)
Definition timestamp.c:1578
static Timestamp dt2local(Timestamp dt, int timezone)
Definition timestamp.c:2125
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition timestamp.c:1901
static TimeOffset time2t(const int hour, const int min, const int sec, const fsec_t fsec)
Definition timestamp.c:2119
#define INT64CONST(x)
Definition c.h:632
int64_t int64
Definition c.h:615
#define unlikely(x)
Definition c.h:432
#define SECS_PER_HOUR
Definition timestamp.h:127
int32 fsec_t
Definition timestamp.h:41
#define TIMESTAMP_NOBEGIN(j)
Definition timestamp.h:159
#define MONTHS_PER_YEAR
Definition timestamp.h:108
#define MINS_PER_HOUR
Definition timestamp.h:129
#define IS_VALID_JULIAN(y, m, d)
Definition timestamp.h:227
#define IS_VALID_TIMESTAMP(t)
Definition timestamp.h:267
#define SECS_PER_MINUTE
Definition timestamp.h:128
#define USECS_PER_DAY
Definition timestamp.h:131
#define USECS_PER_SEC
Definition timestamp.h:134
#define TIMESTAMP_IS_NOEND(j)
Definition timestamp.h:167
#define TIMESTAMP_IS_NOBEGIN(j)
Definition timestamp.h:162
#define TIMESTAMP_NOT_FINITE(j)
Definition timestamp.h:169
#define TIMESTAMP_NOEND(j)
Definition timestamp.h:164
int PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d, int *year, int *month, int *day, int *hour, int *minute, int *second, int *tz)
Definition dt_common.c:2521
#define IS_VALID_UTIME(y, m, d)
Definition dt.h:298
char * pgtypes_date_months[]
Definition dt_common.c:499
char * pgtypes_date_weekdays_short[]
Definition dt_common.c:497
int DateStyle
Definition globals.c:125
const char * str
#define MAXDATEFIELDS
Definition datetime.h:202
#define DTK_EPOCH
Definition datetime.h:152
#define TMODULO(t, q, u)
Definition datetime.h:248
#define DTK_LATE
Definition datetime.h:151
#define DTK_DATE
Definition datetime.h:144
#define DTK_EARLY
Definition datetime.h:150
#define MAXDATELEN
Definition datetime.h:200
#define isleap(y)
Definition datetime.h:271
#define EARLY
Definition datetime.h:39
#define LATE
Definition datetime.h:40
FILE * output
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition int.h:293
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition int.h:235
char * pgtypes_strdup(const char *str)
Definition common.c:20
int pgtypes_fmt_replace(union un_fmt_comb replace_val, int replace_type, char **output, int *pstr_len)
Definition common.c:30
int PGTYPEStimestamp_sub_interval(timestamp *tin, interval *span, timestamp *tout)
Definition timestamp.c:909
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
Definition timestamp.c:198
int PGTYPEStimestamp_sub(timestamp *ts1, timestamp *ts2, interval *iv)
Definition timestamp.c:789
int PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout)
Definition timestamp.c:854
char * PGTYPEStimestamp_to_asc(timestamp tstamp)
Definition timestamp.c:264
void PGTYPEStimestamp_current(timestamp *ts)
Definition timestamp.c:286
int PGTYPEStimestamp_fmt_asc(timestamp *ts, char *output, int str_len, const char *fmtstr)
Definition timestamp.c:774
int PGTYPEStimestamp_defmt_asc(const char *str, const char *fmt, timestamp *d)
Definition timestamp.c:802
static int dttofmtasc_replace(timestamp *ts, date dDate, int dow, struct tm *tm, char *output, int *pstr_len, const char *fmtstr)
Definition timestamp.c:296
int i
Definition isn.c:77
static struct pg_tm tm
Definition localtime.c:104
static char buf[DEFAULT_XLOG_SEG_SIZE]
date PGTYPESdate_from_timestamp(timestamp dt)
Definition datetime.c:31
int PGTYPESdate_dayofweek(date dDate)
Definition datetime.c:138
long date
Definition pgtypes_date.h:9
#define PGTYPES_TS_BAD_TIMESTAMP
#define PGTYPES_TS_ERR_EINFTIME
int64 timestamp
#define PGTYPES_TYPE_STRING_CONSTANT
#define PGTYPES_TYPE_NOTHING
#define PGTYPES_TYPE_UINT
#define PGTYPES_TYPE_CHAR
#define PGTYPES_TYPE_UINT_2_LS
#define PGTYPES_TYPE_UINT_2_LZ
#define PGTYPES_TYPE_INT64
#define PGTYPES_TYPE_UINT_3_LZ
#define TIMEZONE_GLOBAL
Definition port.h:290
#define TZNAME_GLOBAL
Definition port.h:291
static int fb(int x)
#define free(a)
static void fmtstr(const char *value, int leftjust, int minlen, int maxwidth, int pointflag, PrintfTarget *target)
Definition snprintf.c:974
int tm_hour
Definition pgtime.h:38
int tm_mday
Definition pgtime.h:39
int tm_mon
Definition pgtime.h:40
int tm_min
Definition pgtime.h:37
const char * tm_zone
Definition pgtime.h:46
int tm_yday
Definition pgtime.h:43
int tm_sec
Definition pgtime.h:36
int tm_isdst
Definition pgtime.h:44
long int tm_gmtoff
Definition pgtime.h:45
int tm_year
Definition pgtime.h:41