PostgreSQL Source Code: src/backend/utils/adt/datetime.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
17#include <ctype.h>
18#include <limits.h>
19#include <math.h>
20
34
70 int *offset, int *isdst);
73
74
76{
77 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0},
78 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}
79};
80
81const char *const months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
82"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
83
84const char *const days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
85"Thursday", "Friday", "Saturday", NULL};
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
106
107 {"+infinity", RESERV, DTK_LATE},
112 {"apr", MONTH, 4},
113 {"april", MONTH, 4},
114 {"at", IGNORE_DTF, 0},
115 {"aug", MONTH, 8},
116 {"august", MONTH, 8},
119 {"dec", MONTH, 12},
120 {"december", MONTH, 12},
125 {"feb", MONTH, 2},
126 {"february", MONTH, 2},
127 {"fri", DOW, 5},
128 {"friday", DOW, 5},
131 {"isodow", UNITS, DTK_ISODOW},
132 {"isoyear", UNITS, DTK_ISOYEAR},
134 {"jan", MONTH, 1},
135 {"january", MONTH, 1},
137 {"jul", MONTH, 7},
139 {"july", MONTH, 7},
140 {"jun", MONTH, 6},
141 {"june", MONTH, 6},
143 {"mar", MONTH, 3},
144 {"march", MONTH, 3},
145 {"may", MONTH, 5},
147 {"mon", DOW, 1},
148 {"monday", DOW, 1},
149 {"nov", MONTH, 11},
150 {"november", MONTH, 11},
152 {"oct", MONTH, 10},
153 {"october", MONTH, 10},
154 {"on", IGNORE_DTF, 0},
157 {"sat", DOW, 6},
158 {"saturday", DOW, 6},
159 {"sep", MONTH, 9},
160 {"sept", MONTH, 9},
161 {"september", MONTH, 9},
162 {"sun", DOW, 0},
163 {"sunday", DOW, 0},
165 {"thu", DOW, 4},
166 {"thur", DOW, 4},
167 {"thurs", DOW, 4},
168 {"thursday", DOW, 4},
171 {"tue", DOW, 2},
172 {"tues", DOW, 2},
173 {"tuesday", DOW, 2},
174 {"wed", DOW, 3},
175 {"wednesday", DOW, 3},
176 {"weds", DOW, 3},
179};
180
182
183
184
185
186
188
189 {"@", IGNORE_DTF, 0},
193 {"centuries", UNITS, DTK_CENTURY},
204 {"hours", UNITS, DTK_HOUR},
208 {"microsecon", UNITS, DTK_MICROSEC},
235 {"timezone_h", UNITS, DTK_TZ_HOUR},
244 {"weeks", UNITS, DTK_WEEK},
247 {"years", UNITS, DTK_YEAR},
250};
251
253
255
256
257
259
261
262
263
271
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295int
296date2j(int year, int month, int day)
297{
300
301 if (month > 2)
302 {
303 month += 1;
304 year += 4800;
305 }
306 else
307 {
308 month += 13;
309 year += 4799;
310 }
311
313 julian = year * 365 - 32167;
315 julian += 7834 * month / 256 + day;
316
318}
319
320void
321j2date(int jd, int *year, int *month, int *day)
322{
324 unsigned int quad;
325 unsigned int extra;
326 int y;
327
331 extra = (julian - quad * 146097) * 4 + 3;
332 julian += 60 + quad * 3 + extra / 146097;
337 + 123;
339 *year = y - 4800;
343}
344
345
346
347
348
349
350
351
352
353int
355{
358
359 if (date < 0)
361
363}
364
365
366
367
368
369
370
371
372
373
374
375void
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396void
398{
400
401
402
403
404
405
406
407
408
414
416 {
417
418
419
420
422
423
424
425
426
427
432 errmsg("timestamp out of range")));
433
434
437 }
438
441 if (tzp != NULL)
443}
444
445
446
447
448
449
450
451
452
453
454
455
456
457static char *
459{
460 Assert(precision >= 0);
461
464 else
466
467
468 if (fsec != 0)
469 {
471 char *end = &cp[precision + 1];
473
474 *cp++ = '.';
475
476
477
478
479
480
481 while (precision--)
482 {
485
488
489
492
495 else
496 end = &cp[precision];
497 }
498
499
500
501
502
503
506
507 return end;
508 }
509 else
510 return cp;
511}
512
513
514
515
516
517
518
519
520static char *
525
526
527
528
529
530
531static bool
533{
535
538 return false;
539 return true;
540}
541
542
543
544
545
546static bool
549{
551
552
553 if (frac == 0)
554 return true;
555
556
557
558
559
562
563
565 if (frac > 0.5)
567 else if (frac < -0.5)
569
571}
572
573
574
575
576
577
578static bool
581{
583
584
585 if (frac == 0)
586 return true;
587
588
589
590
591
594
595
597 return false;
598
599
602}
603
604
605
606
607
608
609
610static bool
613{
614
615
616
617
619
621}
622
623
624
625
626
627static bool
630{
631
633 return false;
634
636}
637
638
639
640
641
642static bool
644{
646
648 return false;
651}
652
653
654
655
656
657
658static bool
660{
662 return false;
664}
665
666
667
668
669
670static bool
673{
675
677 return false;
680}
681
682
683
684
685
686
687
688
689static int
691{
692
694
695
696
697
698
699 if (cp[1] == '\0')
700 {
702 }
703 else
704 {
705
706
707
708
709
710
713
716
717 if (*cp != '\0' || errno != 0)
719 }
720 return 0;
721}
722
723
724
725
726
727static int
729{
732
736 *fsec = rint(frac * 1000000);
737 return 0;
738}
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772int
775{
776 int nf = 0;
779 const char *bufend = workbuf + buflen;
780
781
782
783
784
785
786
787#define APPEND_CHAR(bufptr, end, newchar) \
788 do \
789 { \
790 if (((bufptr) + 1) >= (end)) \
791 return DTERR_BAD_FORMAT; \
792 *(bufptr)++ = newchar; \
793 } while (0)
794
795
796 while (*cp != '\0')
797 {
798
799 if (isspace((unsigned char) *cp))
800 {
801 cp++;
802 continue;
803 }
804
805
809
810
811 if (isdigit((unsigned char) *cp))
812 {
814 while (isdigit((unsigned char) *cp))
816
817
818 if (*cp == ':')
819 {
822 while (isdigit((unsigned char) *cp) ||
823 (*cp == ':') || (*cp == '.'))
825 }
826
827 else if (*cp == '-' || *cp == '/' || *cp == '.')
828 {
829
830 char delim = *cp;
831
833
834 if (isdigit((unsigned char) *cp))
835 {
837 while (isdigit((unsigned char) *cp))
839
840
841
842
843
844 if (*cp == delim)
845 {
848 while (isdigit((unsigned char) *cp) || *cp == delim)
850 }
851 }
852 else
853 {
855 while (isalnum((unsigned char) *cp) || *cp == delim)
857 }
858 }
859
860
861
862
863
864 else
866 }
867
868 else if (*cp == '.')
869 {
871 while (isdigit((unsigned char) *cp))
873
875 }
876
877
878
879
880 else if (isalpha((unsigned char) *cp))
881 {
883
886 while (isalpha((unsigned char) *cp))
888
889
890
891
892
893
894
895
896
898 if (*cp == '-' || *cp == '/' || *cp == '.')
900 else if (*cp == '+' || isdigit((unsigned char) *cp))
901 {
902 *bufp = '\0';
903
906 }
908 {
910 do
911 {
913 } while (*cp == '+' || *cp == '-' ||
914 *cp == '/' || *cp == '_' ||
915 *cp == '.' || *cp == ':' ||
917 }
918 }
919
920 else if (*cp == '+' || *cp == '-')
921 {
923
924 while (isspace((unsigned char) *cp))
925 cp++;
926
927
928 if (isdigit((unsigned char) *cp))
929 {
932 while (isdigit((unsigned char) *cp) ||
933 *cp == ':' || *cp == '.' || *cp == '-')
935 }
936
937 else if (isalpha((unsigned char) *cp))
938 {
941 while (isalpha((unsigned char) *cp))
943 }
944
945 else
947 }
948
949 else if (ispunct((unsigned char) *cp))
950 {
951 cp++;
952 continue;
953 }
954
955 else
957
958
959 *bufp++ = '\0';
960 nf++;
961 }
962
964
965 return 0;
966}
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996int
998 int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp,
1000{
1004 int ptype = 0;
1005 int i;
1006 int val;
1012 bool bc = false;
1016 char *abbrev = NULL;
1018
1019
1020
1021
1022
1027 *fsec = 0;
1028
1030 if (tzp != NULL)
1031 *tzp = 0;
1032
1034 {
1035 switch (ftype[i])
1036 {
1038
1039
1040
1041
1042
1043
1045 {
1046 char *cp;
1048
1049 if (tzp == NULL)
1051
1056
1059
1060
1064
1066 ptype = 0;
1067 break;
1068 }
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080 else if (ptype != 0 ||
1083 {
1084
1085 if (tzp == NULL)
1087
1088 if (isdigit((unsigned char) *field[i]) || ptype != 0)
1089 {
1090 char *cp;
1091
1092
1093
1094
1095 if (ptype != 0)
1096 {
1097
1100 ptype = 0;
1101 }
1102
1103
1104
1105
1106
1107
1110
1113
1114
1118 *cp = '\0';
1119
1120
1121
1122
1123
1130
1131
1132
1133
1134
1136 }
1137 else
1138 {
1141 {
1144 }
1145
1147 }
1148 }
1149 else
1150 {
1155 }
1156 break;
1157
1159
1160
1161
1162
1163 if (ptype != 0)
1164 {
1165
1168 ptype = 0;
1169 }
1174
1175
1177 *fsec))
1179 break;
1180
1182 {
1183 int tz;
1184
1185 if (tzp == NULL)
1187
1191 *tzp = tz;
1193 }
1194 break;
1195
1197
1198
1199
1200
1201 if (ptype != 0)
1202 {
1203 char *cp;
1205
1210 if (*cp != '.' && *cp != '\0')
1212
1213 switch (ptype)
1214 {
1216
1222
1223
1224 if (*cp == '.')
1225 {
1226 double time;
1227
1236 }
1237 break;
1238
1240
1249 break;
1250
1251 default:
1253 break;
1254 }
1255
1256 ptype = 0;
1258 }
1259 else
1260 {
1261 char *cp;
1263
1266
1267
1269 {
1274 }
1275
1277 {
1278
1279
1280
1281
1282
1288 }
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1301 {
1307 }
1308
1309 else
1310 {
1317 }
1318 }
1319 break;
1320
1323
1331 continue;
1332
1334 switch (type)
1335 {
1337 switch (val)
1338 {
1343 break;
1344
1351 break;
1352
1360 break;
1361
1368 break;
1369
1376 if (tzp != NULL)
1377 *tzp = 0;
1378 break;
1379
1384 *dtype = val;
1385
1386 break;
1387
1388 default:
1389 elog(ERROR, "unrecognized RESERV datetime token: %d",
1391 }
1392
1393 break;
1394
1396
1397
1398
1399
1400
1404 {
1407 }
1410 break;
1411
1413
1414
1415
1416
1417
1420 if (tzp == NULL)
1422 *tzp -= val;
1423 break;
1424
1425 case DTZ:
1426
1427
1428
1429
1430
1433 if (tzp == NULL)
1435 *tzp = -val;
1436 break;
1437
1438 case TZ:
1440 if (tzp == NULL)
1442 *tzp = -val;
1443 break;
1444
1447 if (tzp == NULL)
1449
1451 abbrev = field[i];
1452 break;
1453
1456 break;
1457
1460 break;
1461
1462 case DOW:
1464 break;
1465
1468
1469 if (ptype != 0)
1471 ptype = val;
1472 break;
1473
1475
1476
1477
1478
1479
1481
1482
1485
1486
1487 if (ptype != 0)
1489 ptype = val;
1490 break;
1491
1493
1494
1495
1496
1497
1501
1503 break;
1504
1505 default:
1507 }
1508 break;
1509
1510 default:
1512 }
1513
1517 }
1518
1519
1520 if (ptype != 0)
1522
1523
1525 {
1526
1530
1531
1538
1539
1541 {
1543 return 1;
1545 }
1546
1547
1548
1549
1550
1552 {
1553
1556
1558 }
1559
1560
1561
1562
1563
1565 {
1566
1569
1571 }
1572
1573
1575 {
1576
1577
1578
1579
1582
1584 }
1585 }
1586
1587 return 0;
1588}
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603int
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625static int
1627{
1629 sec;
1633 boundary,
1640 int res;
1641
1642
1643
1644
1645
1646
1647
1649 goto overflow;
1651
1654 goto overflow;
1657
1659 goto overflow;
1660
1661
1662
1663
1664
1665
1666
1669 goto overflow;
1670
1673 &boundary,
1675 tzp);
1676 if (res < 0)
1677 goto overflow;
1678
1679 if (res == 0)
1680 {
1681
1685 }
1686
1687
1688
1689
1695 goto overflow;
1701 goto overflow;
1702
1703
1704
1705
1706
1707
1709 {
1713 }
1715 {
1719 }
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1733 {
1737 }
1741
1742overflow:
1743
1745 *tp = 0;
1746 return 0;
1747}
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764int
1766{
1771
1772
1773
1774
1775
1777
1778
1779
1780
1783 {
1784
1787 }
1788
1789
1790
1791
1792
1794}
1795
1796
1797
1798
1799
1800
1801
1802int
1805{
1809 int tz;
1812
1813
1814
1815
1819
1820
1821
1822
1826 errmsg("timestamp out of range")));
1827
1831}
1832
1833
1834
1835
1836
1837
1838
1839static bool
1841 int *offset, int *isdst)
1842{
1844 unsigned char *p;
1846
1847
1849 for (p = (unsigned char *) upabbr; *p; p++)
1851
1852
1854 &t,
1857 tzp))
1858 {
1859
1861 return true;
1862 }
1863 return false;
1864}
1865
1866
1867
1868
1869
1870
1871
1872
1873static bool
1875 bool *isfixed, int *offset, int *isdst)
1876{
1878 unsigned char *p;
1880
1881
1883 for (p = (unsigned char *) upabbr; *p; p++)
1885
1886
1888 isfixed,
1891 tzp))
1892 {
1893
1895 return true;
1896 }
1897 return false;
1898}
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916int
1918 int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp,
1920{
1924 int ptype = 0;
1925 int i;
1926 int val;
1930 bool bc = false;
1934 char *abbrev = NULL;
1936
1941 *fsec = 0;
1942
1944
1945 if (tzp != NULL)
1946 *tzp = 0;
1947
1949 {
1950 switch (ftype[i])
1951 {
1953
1954
1955
1956
1957
1958 if (tzp == NULL)
1960
1961
1964 {
1969 }
1970
1971 else
1972 {
1973 if (isdigit((unsigned char) *field[i]))
1974 {
1975 char *cp;
1976
1977
1978
1979
1980
1983
1984
1985
1986
1989
1990
1994 *cp = '\0';
1995
1996
1997
1998
1999
2007
2009 }
2010 else
2011 {
2014 {
2017 }
2018
2021 }
2022 }
2023 break;
2024
2026
2027
2028
2029
2030 if (ptype != 0)
2031 {
2034 ptype = 0;
2035 }
2036
2042 break;
2043
2045 {
2046 int tz;
2047
2048 if (tzp == NULL)
2050
2054 *tzp = tz;
2056 }
2057 break;
2058
2060
2061
2062
2063
2064 if (ptype != 0)
2065 {
2066 char *cp;
2068
2073 if (*cp != '.' && *cp != '\0')
2075
2076 switch (ptype)
2077 {
2079
2080 if (tzp == NULL)
2087
2088 if (*cp == '.')
2089 {
2090 double time;
2091
2100 }
2101 break;
2102
2104
2112
2115 break;
2116
2117 default:
2119 break;
2120 }
2121
2122 ptype = 0;
2124 }
2125 else
2126 {
2127 char *cp;
2129
2132
2133
2135 {
2136
2137
2138
2139
2140 if (i == 0 && nf >= 2 && ftype[nf - 1] == DTK_DATE)
2141 {
2146 }
2147
2149 {
2150
2151
2152
2153
2154
2162 }
2163 else
2165 }
2166 else if (flen > 4)
2167 {
2175 }
2176
2177 else
2178 {
2180 false,
2186 }
2187 }
2188 break;
2189
2192
2200 continue;
2201
2203 switch (type)
2204 {
2206 switch (val)
2207 {
2212 break;
2213
2221 break;
2222
2223 default:
2225 }
2226
2227 break;
2228
2230
2231
2232
2233
2234
2237 if (tzp == NULL)
2239 *tzp -= val;
2240 break;
2241
2242 case DTZ:
2243
2244
2245
2246
2247
2250 if (tzp == NULL)
2252 *tzp = -val;
2254 break;
2255
2256 case TZ:
2258 if (tzp == NULL)
2260 *tzp = -val;
2262 break;
2263
2266 if (tzp == NULL)
2268
2270 abbrev = field[i];
2272 break;
2273
2276 break;
2277
2280 break;
2281
2284
2285 if (ptype != 0)
2287 ptype = val;
2288 break;
2289
2292
2293 if (ptype != 0)
2295 ptype = val;
2296 break;
2297
2299
2300
2301
2302
2303
2307
2309 break;
2310
2311 default:
2313 }
2314 break;
2315
2316 default:
2318 }
2319
2323 }
2324
2325
2326 if (ptype != 0)
2328
2329
2333
2334
2341
2342
2345
2348
2349
2350
2351
2352
2354 {
2356
2357
2360
2361
2363 {
2365 }
2366 else
2367 {
2368
2372 }
2373 }
2374
2375
2376
2377
2379 {
2381 *tmp = &tt;
2382
2383
2384
2385
2388
2391 else
2392 {
2393
2399 }
2405 }
2406
2407
2409 {
2411 *tmp = &tt;
2412
2413
2414
2415
2418
2421 else
2422 {
2423
2429 }
2435 }
2436
2437 return 0;
2438}
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450static int
2453{
2455 int nf = 0;
2456 int i,
2464
2466
2467
2469 {
2470
2471 while (*str != '\0' && ((unsigned char) *str))
2473
2474 if (*str == '\0')
2475 return DTERR_BAD_FORMAT;
2476
2479 {
2480 while (isdigit((unsigned char) *str))
2482 }
2483 else if (isalpha((unsigned char) *str))
2484 {
2485 while (isalpha((unsigned char) *str))
2487 }
2488
2489
2490 if (*str != '\0')
2491 *str++ = '\0';
2492 nf++;
2493 }
2494
2495
2497 {
2498 if (isalpha((unsigned char) *field[i]))
2499 {
2502 continue;
2503
2505 switch (type)
2506 {
2510 break;
2511
2512 default:
2514 }
2517
2520
2521
2523 }
2524 }
2525
2526
2528 {
2530 continue;
2531
2534
2540
2543
2546 }
2547
2550
2551
2552
2553 return 0;
2554}
2555
2556
2557
2558
2559
2560int
2563{
2565 {
2567 {
2568
2569 }
2570 else if (bc)
2571 {
2572
2575
2577 }
2579 {
2580
2587 }
2588 else
2589 {
2590
2593 }
2594 }
2595
2596
2598 {
2601 }
2602
2603
2605 {
2608 }
2609
2610
2612 {
2615 }
2616
2618 {
2619
2620
2621
2622
2623
2626 }
2627
2628 return 0;
2629}
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642static int
2645{
2646 char *cp;
2649
2651
2656 if (*cp != ':')
2662 if (*cp == '\0')
2663 {
2664 itm->tm_sec = 0;
2665
2667 {
2670 itm->tm_sec = itm->tm_min;
2671 itm->tm_min = (int) itm->tm_hour;
2672 itm->tm_hour = 0;
2673 }
2674 }
2675 else if (*cp == '.')
2676 {
2677
2683 itm->tm_sec = itm->tm_min;
2684 itm->tm_min = (int) itm->tm_hour;
2685 itm->tm_hour = 0;
2686 }
2687 else if (*cp == ':')
2688 {
2693 if (*cp == '.')
2694 {
2698 }
2699 else if (*cp != '\0')
2701 }
2702 else
2704
2705
2706 if (itm->tm_hour < 0 ||
2711
2712 itm->tm_usec = (int) fsec;
2713
2714 return 0;
2715}
2716
2717
2718
2719
2720
2721
2722
2723
2724static int
2727{
2730
2735
2741 *fsec = itm.tm_usec;
2742
2743 return 0;
2744}
2745
2746
2747
2748
2749
2750
2751
2752
2753static int
2756{
2759
2764
2770
2771 return 0;
2772}
2773
2774
2775
2776
2777
2778
2779static int
2782{
2783 int val;
2784 char *cp;
2786
2788
2795
2796 if (*cp == '.')
2797 {
2798
2799
2800
2801
2803 {
2810 return 0;
2811 }
2812
2816 }
2817 else if (*cp != '\0')
2819
2820
2822 val <= 366)
2823 {
2826
2827 return 0;
2828 }
2829
2830
2832 {
2833 case 0:
2834
2835
2836
2837
2838
2839
2840
2841
2843 {
2846 }
2848 {
2851 }
2852 else
2853 {
2856 }
2857 break;
2858
2860
2863 break;
2864
2867 {
2868
2869
2870
2871
2872
2873
2874
2876 {
2879 }
2880 else
2881 {
2884 }
2885 }
2886 else
2887 {
2888
2891 }
2892 break;
2893
2896 {
2897
2899 {
2900
2905 }
2906 else
2907 {
2910 }
2911 }
2912 else
2913 {
2914
2917 }
2918 break;
2919
2921
2924 break;
2925
2927
2930 break;
2931
2933
2939 return 0;
2940
2941 default:
2942
2944 }
2945
2946
2947
2948
2949
2952
2953 return 0;
2954}
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964static int
2967{
2968 char *cp;
2969
2970
2971
2972
2973
2974
2975
2976
2979
2980
2981
2982
2983
2985 {
2987
2988
2992
2993 *cp = '\0';
2995 }
2996
2998 {
2999 if (len >= 6)
3000 {
3002
3003
3004
3005
3006
3008 *(str + (len - 2)) = '\0';
3010 *(str + (len - 4)) = '\0';
3012 if ((len - 4) == 2)
3014
3016 }
3017 }
3018
3019
3021 {
3022
3023 if (len == 6)
3024 {
3027 *(str + 4) = '\0';
3029 *(str + 2) = '\0';
3031
3033 }
3034
3035 else if (len == 4)
3036 {
3040 *(str + 2) = '\0';
3042
3044 }
3045 }
3046
3048}
3049
3050
3051
3052
3053
3054
3055
3056int
3058{
3059 int tz;
3060 int hr,
3061 min,
3062 sec = 0;
3063 char *cp;
3064
3065
3066 if (*str != '+' && *str != '-')
3068
3073
3074
3075 if (*cp == ':')
3076 {
3081 if (*cp == ':')
3082 {
3087 }
3088 }
3089
3090 else if (*cp == '\0' && strlen(str) > 3)
3091 {
3092 min = hr % 100;
3094
3095 }
3096 else
3097 min = 0;
3098
3099
3106
3108 if (*str == '-')
3109 tz = -tz;
3110
3111 *tzp = -tz;
3112
3113 if (*cp != '\0')
3115
3116 return 0;
3117}
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140int
3142 int *ftype, int *offset, pg_tz **tz,
3144{
3146 bool isfixed;
3149
3150
3151
3152
3153
3154
3156 {
3157 *ftype = tzc->ftype;
3158 *offset = tzc->offset;
3159 *tz = tzc->tz;
3160 return 0;
3161 }
3162
3163
3164
3165
3166
3167
3170 &isfixed, offset, &isdst))
3171 {
3174
3175 *offset = -(*offset);
3176
3178 tzc->ftype = *ftype;
3179 tzc->offset = *offset;
3180 tzc->tz = *tz;
3181 return 0;
3182 }
3183
3184
3188 else
3190 if (tp == NULL)
3191 {
3193 *offset = 0;
3195
3196 }
3197 else
3198 {
3199 *ftype = tp->type;
3201 {
3202 *offset = 0;
3204 if (*tz == NULL)
3206 }
3207 else
3208 {
3209 *offset = tp->value;
3211 }
3212
3213
3215 tzc->ftype = *ftype;
3216 tzc->offset = *offset;
3217 tzc->tz = *tz;
3218 }
3219
3220 return 0;
3221}
3222
3223
3224
3225
3226void
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245int
3247{
3250
3252
3254 {
3256 }
3257 if (tp == NULL)
3258 {
3260 *val = 0;
3261 }
3262 else
3263 {
3267 }
3268
3269 return type;
3270}
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287int
3289{
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3307 false);
3308
3312
3314 {
3315
3317 }
3319 {
3320
3322 }
3323 else
3324 {
3325
3327 if (*tz == NULL)
3330 errmsg("time zone \"%s\" not recognized", tzname)));
3332 }
3333}
3334
3335
3336
3337
3338
3339
3340
3341
3344{
3346 int offset;
3347
3349 {
3350
3351 result = pg_tzset_offset(-offset);
3352 }
3353 return result;
3354}
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370int
3372{
3374 int len;
3375
3376 *offset = 0;
3378
3379
3381 {
3382 if (*str == '\0' || ((unsigned char) *str))
3383 break;
3385 }
3387
3388
3389
3390
3391
3392
3393
3394
3395 while (len > 0)
3396 {
3397 bool isfixed;
3400
3401
3404 &isfixed, offset, &isdst))
3405 {
3406 if (isfixed)
3407 {
3408
3409 *offset = -(*offset);
3410 }
3411 else
3412 {
3413
3415 }
3416 return len;
3417 }
3418
3419
3423 else
3425 if (tp != NULL)
3426 {
3428 {
3431 &extra);
3432
3433 if (tzp != NULL)
3434 {
3435
3436 *tz = tzp;
3437 return len;
3438 }
3439 }
3440 else
3441 {
3442
3443 *offset = tp->value;
3444 return len;
3445 }
3446 }
3447
3448
3450 }
3451
3452
3453 return -1;
3454}
3455
3456
3457
3458
3459
3460
3461static inline void
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485int
3488{
3492 char *cp;
3497 int i;
3500 double fval;
3501
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3523 {
3525
3527 {
3528 if (*field[i] == '-' || *field[i] == '+')
3529 {
3531 break;
3532 }
3533 }
3534 }
3535
3536
3537 for (i = nf - 1; i >= 0; i--)
3538 {
3539 switch (ftype[i])
3540 {
3547 itm_in->tm_usec > 0)
3551 break;
3552
3554
3555
3556
3557
3558
3559
3560 Assert(*field[i] == '-' || *field[i] == '+');
3561
3562
3563
3564
3565
3566 if (strchr(field[i] + 1, ':') != NULL &&
3569 {
3570 if (*field[i] == '-')
3571 {
3572
3576 }
3577
3579 itm_in->tm_usec > 0)
3581
3582
3583
3584
3585
3586
3589 break;
3590 }
3591
3592
3593
3594
3595
3596
3598
3602 {
3603
3605 {
3608 break;
3612 break;
3615 break;
3619 break;
3624 break;
3630 break;
3631 default:
3633 break;
3634 }
3635 }
3636
3641
3642 if (*cp == '-')
3643 {
3644
3646
3650 if (*cp != '\0')
3653 if (*field[i] == '-')
3659 fval = 0;
3660 }
3661 else if (*cp == '.')
3662 {
3666 if (*field[i] == '-')
3667 fval = -fval;
3668 }
3669 else if (*cp == '\0')
3670 fval = 0;
3671 else
3673
3674 tmask = 0;
3675
3677 {
3678
3679 if (val > 0)
3681 if (fval > 0)
3682 fval = -fval;
3683 }
3684
3685 switch (type)
3686 {
3691 break;
3692
3697 break;
3698
3702
3703
3704
3705
3706
3707 if (fval == 0)
3709 else
3711 break;
3712
3717 break;
3718
3724 break;
3725
3731 break;
3732
3738 break;
3739
3745 break;
3746
3752 break;
3753
3759 break;
3760
3766 break;
3767
3773 break;
3774
3775 default:
3777 }
3779 break;
3780
3783
3790 continue;
3791
3792 tmask = 0;
3793 switch (type)
3794 {
3798 break;
3799
3800 case AGO:
3801
3802
3803
3804
3805
3810 break;
3811
3814
3815
3816
3817
3818
3821
3822
3823
3824
3825
3826
3829
3830 *dtype = uval;
3831 break;
3832
3833 default:
3835 }
3836 break;
3837
3838 default:
3840 }
3841
3845 }
3846
3847
3850
3851
3854
3855
3857 {
3863
3868 }
3869
3870 return 0;
3871}
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881static int
3883{
3884 double val;
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898 if (!(isdigit((unsigned char) *str) || *str == '-' || *str == '.'))
3902
3903 if (*endptr == str || errno != 0)
3905
3908
3909 if (val >= 0)
3911 else
3914
3916 return 0;
3917}
3918
3919
3920
3921
3922
3923static int
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950int
3953{
3956
3959
3962
3964 while (*str)
3965 {
3968 double fval;
3969 char unit;
3971
3972 if (*str == 'T')
3973 {
3977 continue;
3978 }
3979
3984
3985
3986
3987
3988
3989 unit = *str++;
3990
3992 {
3993 switch (unit)
3994 {
3995 case 'Y':
3999 break;
4000 case 'M':
4004 break;
4005 case 'W':
4009 break;
4010 case 'D':
4014 break;
4015 case 'T':
4016 case '\0':
4018 {
4024 if (unit == '\0')
4025 return 0;
4028 continue;
4029 }
4030
4032 case '-':
4033
4036
4040 if (unit == '\0')
4041 return 0;
4042 if (unit == 'T')
4043 {
4046 continue;
4047 }
4048
4055 if (*str == '\0')
4056 return 0;
4057 if (*str == 'T')
4058 {
4061 continue;
4062 }
4063 if (*str != '-')
4066
4073 if (*str == '\0')
4074 return 0;
4075 if (*str == 'T')
4076 {
4079 continue;
4080 }
4082 default:
4083
4085 }
4086 }
4087 else
4088 {
4089 switch (unit)
4090 {
4091 case 'H':
4094 break;
4095 case 'M':
4098 break;
4099 case 'S':
4102 break;
4103 case '\0':
4105 {
4111 return 0;
4112 }
4113
4115 case ':':
4116
4119
4122 if (unit == '\0')
4123 return 0;
4124
4130 if (*str == '\0')
4131 return 0;
4132 if (*str != ':')
4135
4141 if (*str == '\0')
4142 return 0;
4144
4145 default:
4146
4148 }
4149 }
4150
4152 }
4153
4154 return 0;
4155}
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168int
4170{
4173
4175
4177 {
4179 }
4180 if (tp == NULL)
4181 {
4183 *val = 0;
4184 }
4185 else
4186 {
4190 }
4191
4192 return type;
4193}
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213void
4215 const char *str, const char *datatype,
4216 Node *escontext)
4217{
4219 {
4223 errmsg("date/time field value out of range: \"%s\"",
4225 break;
4227
4230 errmsg("date/time field value out of range: \"%s\"",
4232 errhint("Perhaps you need a different \"DateStyle\" setting.")));
4233 break;
4237 errmsg("interval field value out of range: \"%s\"",
4239 break;
4243 errmsg("time zone displacement out of range: \"%s\"",
4245 break;
4249 errmsg("time zone \"%s\" not recognized",
4251 break;
4255 errmsg("time zone \"%s\" not recognized",
4257 errdetail("This time zone name appears in the configuration file for time zone abbreviation \"%s\".",
4259 break;
4261 default:
4264 errmsg("invalid input syntax for type %s: \"%s\"",
4265 datatype, str)));
4266 break;
4267 }
4268}
4269
4270
4271
4272
4273
4276{
4277 if (nel > 0)
4278 {
4279 const datetkn *last = base + nel - 1,
4280 *position;
4281 int result;
4282
4283 while (last >= base)
4284 {
4285 position = base + ((last - base) >> 1);
4286
4287 result = (int) key[0] - (int) position->token[0];
4288 if (result == 0)
4289 {
4290
4292 if (result == 0)
4293 return position;
4294 }
4295 if (result < 0)
4296 last = position - 1;
4297 else
4298 base = position + 1;
4299 }
4300 }
4301 return NULL;
4302}
4303
4304
4305
4306
4307
4308
4309
4310static char *
4312{
4314 min,
4315 sec;
4316
4317 sec = abs(tz);
4322
4323
4324 *str++ = (tz <= 0 ? '+' : '-');
4325
4326 if (sec != 0)
4327 {
4329 *str++ = ':';
4331 *str++ = ':';
4333 }
4335 {
4337 *str++ = ':';
4339 }
4340 else
4342 return str;
4343}
4344
4345
4346
4347
4348void
4350{
4352
4354 {
4357
4360 *str++ = '-';
4362 *str++ = '-';
4364 break;
4365
4367
4369 {
4371 *str++ = '/';
4373 }
4374 else
4375 {
4377 *str++ = '/';
4379 }
4380 *str++ = '/';
4383 break;
4384
4386
4388 *str++ = '.';
4390 *str++ = '.';
4393 break;
4394
4396 default:
4397
4399 {
4401 *str++ = '-';
4403 }
4404 else
4405 {
4407 *str++ = '-';
4409 }
4410 *str++ = '-';
4413 break;
4414 }
4415
4417 {
4419 str += 3;
4420 }
4421 *str = '\0';
4422}
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433void
4435{
4437 *str++ = ':';
4439 *str++ = ':';
4443 *str = '\0';
4444}
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463void
4465{
4466 int day;
4467
4469
4470
4471
4472
4475
4477 {
4480
4483 *str++ = '-';
4485 *str++ = '-';
4489 *str++ = ':';
4491 *str++ = ':';
4495 break;
4496
4498
4500 {
4502 *str++ = '/';
4504 }
4505 else
4506 {
4508 *str++ = '/';
4510 }
4511 *str++ = '/';
4514 *str++ = ' ';
4516 *str++ = ':';
4518 *str++ = ':';
4520
4521
4522
4523
4524
4525
4526
4528 {
4529 if (tzn)
4530 {
4533 }
4534 else
4536 }
4537 break;
4538
4540
4542 *str++ = '.';
4544 *str++ = '.';
4547 *str++ = ' ';
4549 *str++ = ':';
4551 *str++ = ':';
4553
4555 {
4556 if (tzn)
4557 {
4560 }
4561 else
4563 }
4564 break;
4565
4567 default:
4568
4572 str += 3;
4573 *str++ = ' ';
4575 {
4577 *str++ = ' ';
4579 str += 3;
4580 }
4581 else
4582 {
4584 str += 3;
4585 *str++ = ' ';
4587 }
4588 *str++ = ' ';
4590 *str++ = ':';
4592 *str++ = ':';
4594 *str++ = ' ';
4597
4599 {
4600 if (tzn)
4601 {
4604 }
4605 else
4606 {
4607
4608
4609
4610
4611
4612
4613 *str++ = ' ';
4615 }
4616 }
4617 break;
4618 }
4619
4621 {
4623 str += 3;
4624 }
4625 *str = '\0';
4626}
4627
4628
4629
4630
4631
4632
4633
4634static char *
4636{
4638 return cp;
4641}
4642
4643
4644static char *
4647{
4649 return cp;
4655 (value != 1) ? "s" : "");
4656
4657
4658
4659
4660
4664}
4665
4666
4667static char *
4670{
4672 return cp;
4673
4675 {
4678 }
4684}
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706void
4708{
4710 int year = itm->tm_year;
4711 int mon = itm->tm_mon;
4712 int64 mday = itm->tm_mday;
4714 int min = itm->tm_min;
4715 int sec = itm->tm_sec;
4716 int fsec = itm->tm_usec;
4719
4720
4721
4722
4723
4724
4725
4727 {
4728
4730 {
4733 min < 0 || sec < 0 || fsec < 0;
4736 min > 0 || sec > 0 || fsec > 0;
4739 min != 0 || sec != 0 || fsec != 0;
4743
4744
4745
4746
4747
4749 {
4750 *cp++ = '-';
4751 year = -year;
4752 mon = -mon;
4755 min = -min;
4756 sec = -sec;
4757 fsec = -fsec;
4758 }
4759
4761 {
4763 }
4765 {
4766
4767
4768
4769
4770
4771 char year_sign = (year < 0 || mon < 0) ? '-' : '+';
4774 sec < 0 || fsec < 0) ? '-' : '+';
4775
4782 *cp = '\0';
4783 }
4785 {
4786 sprintf(cp, "%d-%d", year, mon);
4787 }
4789 {
4794 *cp = '\0';
4795 }
4796 else
4797 {
4801 *cp = '\0';
4802 }
4803 }
4804 break;
4805
4806
4808
4809 if (year == 0 && mon == 0 && mday == 0 &&
4810 hour == 0 && min == 0 && sec == 0 && fsec == 0)
4811 {
4813 break;
4814 }
4815 *cp++ = 'P';
4819 if (hour != 0 || min != 0 || sec != 0 || fsec != 0)
4820 *cp++ = 'T';
4823 if (sec != 0 || fsec != 0)
4824 {
4825 if (sec < 0 || fsec < 0)
4826 *cp++ = '-';
4828 *cp++ = 'S';
4829 *cp++ = '\0';
4830 }
4831 break;
4832
4833
4836
4837
4838
4839
4840
4841
4844 if (is_zero || hour != 0 || min != 0 || sec != 0 || fsec != 0)
4845 {
4846 bool minus = (hour < 0 || min < 0 || sec < 0 || fsec < 0);
4847
4854 *cp = '\0';
4855 }
4856 break;
4857
4858
4860 default:
4862 cp++;
4868 if (sec != 0 || fsec != 0)
4869 {
4870 *cp++ = ' ';
4871 if (sec < 0 || (sec == 0 && fsec < 0))
4872 {
4876 *cp++ = '-';
4877 }
4879 *cp++ = '-';
4881
4883 (abs(sec) != 1 || fsec != 0) ? "s" : "");
4885 }
4886
4891 break;
4892 }
4893}
4894
4895
4896
4897
4898
4899
4900static bool
4902{
4903 bool ok = true;
4904 int i;
4905
4906 for (i = 0; i < nel; i++)
4907 {
4908
4910 {
4911
4912 elog(LOG, "token too long in %s table: \"%.*s\"",
4913 tablename,
4915 ok = false;
4916 break;
4917 }
4918
4919 if (i > 0 &&
4921 {
4922 elog(LOG, "ordering error in %s table: \"%s\" >= \"%s\"",
4923 tablename,
4926 ok = false;
4927 }
4928 }
4929 return ok;
4930}
4931
4932bool
4934{
4935 bool ok = true;
4936
4939
4942 return ok;
4943}
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4963{
4966 Node *typmod;
4967
4969
4971
4972 if (IsA(typmod, Const) && !((Const *) typmod)->constisnull)
4973 {
4977
4981 }
4982
4983 return ret;
4984}
4985
4986
4987
4988
4989
4990
4991
4992
4993
4996{
4999 int i;
5000
5001
5005
5007 {
5009
5011 {
5013
5017 }
5018 }
5019
5020
5022 if ()
5023 return NULL;
5024
5025
5027 tbl->numabbrevs = n;
5028
5033 {
5036
5037
5040 {
5041
5044
5048
5050
5052
5056 }
5057 else
5058 {
5061 }
5062 }
5063
5064
5066
5067
5069
5070 return tbl;
5071}
5072
5073
5074
5075
5076
5077
5078void
5085
5086
5087
5088
5089
5090
5094{
5096
5097
5100
5102
5103
5105 {
5108 {
5109
5112 }
5113 }
5114 return dtza->tz;
5115}
5116
5117
5118
5119
5120
5121
5122
5125{
5131 bool nulls[3] = {0};
5139
5140
5142 {
5145
5146
5148
5149
5150
5151
5153
5154
5158
5160 elog(ERROR, "return type must be a row type");
5161 funcctx->tuple_desc = tupdesc;
5162
5164 }
5165
5166
5169
5172 {
5173
5174 if (strspn(abbrev, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") != strlen(abbrev))
5175 continue;
5176
5177
5179 &t,
5183 continue;
5184
5186
5187
5193
5195
5198
5200 }
5201
5203}
5204
5205
5206
5207
5208
5209
5212{
5218 bool nulls[3] = {0};
5221 int gmtoffset;
5222 bool is_dst;
5223 unsigned char *p;
5226
5227
5229 {
5232
5233
5235
5236
5237
5238
5240
5241
5245
5247 elog(ERROR, "return type must be a row type");
5248 funcctx->tuple_desc = tupdesc;
5249
5251 }
5252
5253
5256
5260
5262
5263 switch (tp->type)
5264 {
5265 case TZ:
5266 gmtoffset = tp->value;
5267 is_dst = false;
5268 break;
5269 case DTZ:
5270 gmtoffset = tp->value;
5271 is_dst = true;
5272 break;
5274 {
5275
5280
5282 if (tzp == NULL)
5288 tzp,
5291 break;
5292 }
5293 default:
5294 elog(ERROR, "unrecognized timezone type %d", (int) tp->type);
5295 gmtoffset = 0;
5296 is_dst = false;
5297 break;
5298 }
5299
5300
5301
5302
5303
5305 for (p = (unsigned char *) buffer; *p; p++)
5307
5309
5310
5316
5318
5319 (*pindex)++;
5320
5323
5325}
5326
5327
5328
5329
5330
5333{
5338 bool nulls[4] = {0};
5342 const char *tzn;
5345
5347
5348
5350
5351
5352 for (;;)
5353 {
5355 if (!tz)
5356 break;
5357
5358
5360 &tzoff, &tm, &fsec, &tzn, tz) != 0)
5361 continue;
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372 if (tzn && strlen(tzn) > 31)
5373 continue;
5374
5377
5378
5384
5386
5388 }
5389
5391 return (Datum) 0;
5392}
static char * EncodeTimezone(char *str, int tz, int style)
static int DecodeDate(char *str, int fmask, int *tmask, bool *is2digits, struct pg_tm *tm)
static int DetermineTimeZoneOffsetInternal(struct pg_tm *tm, pg_tz *tzp, pg_time_t *tp)
#define APPEND_CHAR(bufptr, end, newchar)
static int DecodeNumberField(int len, char *str, int fmask, int *tmask, struct pg_tm *tm, fsec_t *fsec, bool *is2digits)
Node * TemporalSimplify(int32 max_precis, Node *node)
pg_tz * DecodeTimezoneNameToTz(const char *tzname)
static bool CheckDateTokenTable(const char *tablename, const datetkn *base, int nel)
int DetermineTimeZoneAbbrevOffsetTS(TimestampTz ts, const char *abbr, pg_tz *tzp, int *isdst)
static int ParseFraction(char *cp, double *frac)
static TzAbbrevCache tzabbrevcache[MAXDATEFIELDS]
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
static const datetkn datetktbl[]
static bool int64_multiply_add(int64 val, int64 multiplier, int64 *sum)
int DecodeUnits(int field, const char *lowtoken, int *val)
int DecodeTimeOnly(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
static TimeZoneAbbrevTable * zoneabbrevtbl
static const datetkn * deltacache[MAXDATEFIELDS]
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
void EncodeInterval(struct pg_itm *itm, int style, char *str)
static bool AdjustDays(int64 val, int scale, struct pg_itm_in *itm_in)
static const datetkn * datecache[MAXDATEFIELDS]
static int DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask, int *tmask, struct pg_tm *tm, fsec_t *fsec, bool *is2digits)
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
static bool DetermineTimeZoneAbbrevOffsetInternal(pg_time_t t, const char *abbr, pg_tz *tzp, int *offset, int *isdst)
void DateTimeParseError(int dterr, DateTimeErrorExtra *extra, const char *str, const char *datatype, Node *escontext)
static int ParseFractionalSecond(char *cp, fsec_t *fsec)
static bool AdjustFractYears(double frac, int scale, struct pg_itm_in *itm_in)
static bool AdjustMicroseconds(int64 val, double fval, int64 scale, struct pg_itm_in *itm_in)
static int DecodeTimeCommon(char *str, int fmask, int range, int *tmask, struct pg_itm *itm)
int DecodeInterval(char **field, int *ftype, int nf, int range, int *dtype, struct pg_itm_in *itm_in)
Datum pg_timezone_abbrevs_abbrevs(PG_FUNCTION_ARGS)
static int DecodeTimeForInterval(char *str, int fmask, int range, int *tmask, struct pg_itm_in *itm_in)
static char * AddPostgresIntPart(char *cp, int64 value, const char *units, bool *is_zero, bool *is_before)
bool CheckDateTokenTables(void)
static const int szdeltatktbl
int DecodeTimezoneAbbrev(int field, const char *lowtoken, int *ftype, int *offset, pg_tz **tz, DateTimeErrorExtra *extra)
Datum pg_timezone_names(PG_FUNCTION_ARGS)
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
static int DecodeTime(char *str, int fmask, int range, int *tmask, struct pg_tm *tm, fsec_t *fsec)
static bool AdjustFractMicroseconds(double frac, int64 scale, struct pg_itm_in *itm_in)
int DecodeISO8601Interval(char *str, int *dtype, struct pg_itm_in *itm_in)
int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, struct pg_tm *tm)
int DecodeSpecial(int field, const char *lowtoken, int *val)
void j2date(int jd, int *year, int *month, int *day)
void GetCurrentDateTime(struct pg_tm *tm)
static int ISO8601IntegerWidth(char *fieldstart)
static bool AdjustYears(int64 val, int scale, struct pg_itm_in *itm_in)
void EncodeDateTime(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str)
int DecodeTimezone(const char *str, int *tzp)
TimeZoneAbbrevTable * ConvertTimeZoneAbbrevs(struct tzEntry *abbrevs, int n)
const char *const months[]
static bool AdjustMonths(int64 val, struct pg_itm_in *itm_in)
static char * AppendSeconds(char *cp, int sec, fsec_t fsec, int precision, bool fillzeros)
static const int szdatetktbl
Datum pg_timezone_abbrevs_zone(PG_FUNCTION_ARGS)
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
static char * AppendTimestampSeconds(char *cp, struct pg_tm *tm, fsec_t fsec)
static const datetkn * datebsearch(const char *key, const datetkn *base, int nel)
static char * AddISO8601IntPart(char *cp, int64 value, char units)
static int ParseISO8601Number(char *str, char **endptr, int64 *ipart, double *fpart)
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
int date2j(int year, int month, int day)
static bool TimeZoneAbbrevIsKnown(const char *abbr, pg_tz *tzp, bool *isfixed, int *offset, int *isdst)
static bool AdjustFractDays(double frac, int scale, struct pg_itm_in *itm_in)
static void ClearPgItmIn(struct pg_itm_in *itm_in)
static char * AddVerboseIntPart(char *cp, int64 value, const char *units, bool *is_zero, bool *is_before)
static const datetkn deltatktbl[]
void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp)
static pg_tz * FetchDynamicTimeZone(TimeZoneAbbrevTable *tbl, const datetkn *tp, DateTimeErrorExtra *extra)
void ClearTimeZoneAbbrevCache(void)
int DecodeTimezoneName(const char *tzname, int *offset, pg_tz **tz)
int DecodeTimezoneAbbrevPrefix(const char *str, int *offset, pg_tz **tz)
int DetermineTimeZoneAbbrevOffset(struct pg_tm *tm, const char *abbr, pg_tz *tzp)
void dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
int itmin2interval(struct pg_itm_in *itm_in, Interval *span)
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Datum now(PG_FUNCTION_ARGS)
pg_time_t timestamptz_to_time_t(TimestampTz t)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define Assert(condition)
#define MemSet(start, val, len)
#define MAX_TIMESTAMP_PRECISION
#define IS_VALID_JULIAN(y, m, d)
#define MAX_INTERVAL_PRECISION
#define POSTGRES_EPOCH_JDATE
bool time_overflows(int hour, int min, int sec, fsec_t fsec)
#define MAX_TIME_PRECISION
int errcode(int sqlerrcode)
#define errsave(context,...)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
#define palloc_object(type)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
void * guc_malloc(int elevel, size_t size)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define DTERR_BAD_ZONE_ABBREV
#define DTERR_INTERVAL_OVERFLOW
#define DTERR_BAD_TIMEZONE
#define TZNAME_FIXED_OFFSET
#define DTERR_TZDISP_OVERFLOW
#define DTERR_FIELD_OVERFLOW
#define DTERR_MD_FIELD_OVERFLOW
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
#define USE_POSTGRES_DATES
#define INTSTYLE_SQL_STANDARD
#define INTSTYLE_POSTGRES_VERBOSE
#define INTSTYLE_ISO_8601
#define INTSTYLE_POSTGRES
int32 exprTypmod(const Node *expr)
Node * relabel_to_typmod(Node *expr, int32 typmod)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
char * pg_ultostr_zeropad(char *str, uint32 value, int32 minwidth)
char * pg_ultostr(char *str, uint32 value)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int list_length(const List *l)
static rewind_source * source
pg_tz * pg_tzset_offset(long gmtoffset)
pg_tz * pg_tzenumerate_next(pg_tzenum *dir)
bool pg_timezone_abbrev_is_known(const char *abbrev, bool *isfixed, long int *gmtoff, int *isdst, const pg_tz *tz)
int pg_next_dst_boundary(const pg_time_t *timep, long int *before_gmtoff, int *before_isdst, pg_time_t *boundary, long int *after_gmtoff, int *after_isdst, const pg_tz *tz)
const char * pg_get_timezone_name(pg_tz *tz)
pg_tz * pg_tzset(const char *tzname)
bool pg_get_timezone_offset(const pg_tz *tz, long int *gmtoff)
const char * pg_get_next_timezone_abbrev(int *indx, const pg_tz *tz)
PGDLLIMPORT pg_tz * session_timezone
void pg_tzenumerate_end(pg_tzenum *dir)
pg_tzenum * pg_tzenumerate_start(void)
bool pg_interpret_timezone_abbrev(const char *abbrev, const pg_time_t *timep, long int *gmtoff, int *isdst, const pg_tz *tz)
unsigned char pg_toupper(unsigned char ch)
unsigned char pg_tolower(unsigned char ch)
size_t strlcpy(char *dst, const char *src, size_t siz)
static Datum BoolGetDatum(bool X)
static int32 DatumGetInt32(Datum X)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
datetkn abbrevs[FLEXIBLE_ARRAY_MEMBER]
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
#define INTERVAL_FULL_RANGE
static Datum IntervalPGetDatum(const Interval *X)
TimestampTz GetCurrentTransactionStartTimestamp(void)