PostgreSQL Source Code: src/interfaces/ecpg/pgtypeslib/dt.h File Reference (original) (raw)
Go to the source code of this file.
Macros | ||
---|---|---|
#define | MAXTZLEN 10 | |
#define | USE_POSTGRES_DATES 0 | |
#define | USE_ISO_DATES 1 | |
#define | USE_SQL_DATES 2 | |
#define | USE_GERMAN_DATES 3 | |
#define | INTSTYLE_POSTGRES 0 | |
#define | INTSTYLE_POSTGRES_VERBOSE 1 | |
#define | INTSTYLE_SQL_STANDARD 2 | |
#define | INTSTYLE_ISO_8601 3 | |
#define | INTERVAL_FULL_RANGE (0x7FFF) | |
#define | INTERVAL_MASK(b) (1 << (b)) | |
#define | MAX_INTERVAL_PRECISION 6 | |
#define | DTERR_BAD_FORMAT (-1) | |
#define | DTERR_FIELD_OVERFLOW (-2) | |
#define | DTERR_MD_FIELD_OVERFLOW (-3) /* triggers hint about DateStyle */ | |
#define | DTERR_INTERVAL_OVERFLOW (-4) | |
#define | DTERR_TZDISP_OVERFLOW (-5) | |
#define | DAGO "ago" | |
#define | DCURRENT "current" | |
#define | EPOCH "epoch" | |
#define | INVALID "invalid" | |
#define | EARLY "-infinity" | |
#define | LATE "infinity" | |
#define | NOW "now" | |
#define | TODAY "today" | |
#define | TOMORROW "tomorrow" | |
#define | YESTERDAY "yesterday" | |
#define | ZULU "zulu" | |
#define | DMICROSEC "usecond" | |
#define | DMILLISEC "msecond" | |
#define | DSECOND "second" | |
#define | DMINUTE "minute" | |
#define | DHOUR "hour" | |
#define | DDAY "day" | |
#define | DWEEK "week" | |
#define | DMONTH "month" | |
#define | DQUARTER "quarter" | |
#define | DYEAR "year" | |
#define | DDECADE "decade" | |
#define | DCENTURY "century" | |
#define | DMILLENNIUM "millennium" | |
#define | DA_D "ad" | |
#define | DB_C "bc" | |
#define | DTIMEZONE "timezone" | |
#define | AM 0 | |
#define | PM 1 | |
#define | HR24 2 | |
#define | AD 0 | |
#define | BC 1 | |
#define | RESERV 0 | |
#define | MONTH 1 | |
#define | YEAR 2 | |
#define | DAY 3 | |
#define | JULIAN 4 | |
#define | TZ 5 /* fixed-offset timezone abbreviation */ | |
#define | DTZ 6 /* fixed-offset timezone abbrev, DST */ | |
#define | DYNTZ 7 /* dynamic timezone abbr (unimplemented) */ | |
#define | IGNORE_DTF 8 | |
#define | AMPM 9 | |
#define | HOUR 10 | |
#define | MINUTE 11 | |
#define | SECOND 12 | |
#define | MILLISECOND 13 | |
#define | MICROSECOND 14 | |
#define | DOY 15 | |
#define | DOW 16 | |
#define | UNITS 17 | |
#define | ADBC 18 | |
#define | AGO 19 | |
#define | ABS_BEFORE 20 | |
#define | ABS_AFTER 21 | |
#define | ISODATE 22 | |
#define | ISOTIME 23 | |
#define | DTZMOD 28 /* "DST" as a separate word */ | |
#define | UNKNOWN_FIELD 31 | |
#define | DTK_NUMBER 0 | |
#define | DTK_STRING 1 | |
#define | DTK_DATE 2 | |
#define | DTK_TIME 3 | |
#define | DTK_TZ 4 | |
#define | DTK_AGO 5 | |
#define | DTK_SPECIAL 6 | |
#define | DTK_EARLY 9 | |
#define | DTK_LATE 10 | |
#define | DTK_EPOCH 11 | |
#define | DTK_NOW 12 | |
#define | DTK_YESTERDAY 13 | |
#define | DTK_TODAY 14 | |
#define | DTK_TOMORROW 15 | |
#define | DTK_ZULU 16 | |
#define | DTK_DELTA 17 | |
#define | DTK_SECOND 18 | |
#define | DTK_MINUTE 19 | |
#define | DTK_HOUR 20 | |
#define | DTK_DAY 21 | |
#define | DTK_WEEK 22 | |
#define | DTK_MONTH 23 | |
#define | DTK_QUARTER 24 | |
#define | DTK_YEAR 25 | |
#define | DTK_DECADE 26 | |
#define | DTK_CENTURY 27 | |
#define | DTK_MILLENNIUM 28 | |
#define | DTK_MILLISEC 29 | |
#define | DTK_MICROSEC 30 | |
#define | DTK_JULIAN 31 | |
#define | DTK_DOW 32 | |
#define | DTK_DOY 33 | |
#define | DTK_TZ_HOUR 34 | |
#define | DTK_TZ_MINUTE 35 | |
#define | DTK_ISOYEAR 36 | |
#define | DTK_ISODOW 37 | |
#define | DTK_M(t) (0x01 << (t)) | |
#define | DTK_ALL_SECS_M (DTK_M(SECOND) | DTK_M(MILLISECOND) | DTK_M(MICROSECOND)) |
#define | DTK_DATE_M (DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY)) |
#define | DTK_TIME_M (DTK_M(HOUR) | DTK_M(MINUTE) | DTK_M(SECOND)) |
#define | MAXDATELEN 128 | |
#define | MAXDATEFIELDS 25 | |
#define | TOKMAXLEN 10 | |
#define | FMODULO(t, q, u) | |
#define | TMODULO(t, q, u) | |
#define | DAYS_PER_YEAR 365.25 /* assumes leap year every four years */ | |
#define | MONTHS_PER_YEAR 12 | |
#define | DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ | |
#define | HOURS_PER_DAY 24 /* assume no daylight savings time changes */ | |
#define | SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ | |
#define | SECS_PER_DAY 86400 | |
#define | SECS_PER_HOUR 3600 | |
#define | SECS_PER_MINUTE 60 | |
#define | MINS_PER_HOUR 60 | |
#define | USECS_PER_DAY INT64CONST(86400000000) | |
#define | USECS_PER_HOUR INT64CONST(3600000000) | |
#define | USECS_PER_MINUTE INT64CONST(60000000) | |
#define | USECS_PER_SEC INT64CONST(1000000) | |
#define | isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 | | ((y) % 400) == 0)) |
#define | JULIAN_MINYEAR (-4713) | |
#define | JULIAN_MINMONTH (11) | |
#define | JULIAN_MINDAY (24) | |
#define | JULIAN_MAXYEAR (5874898) | |
#define | JULIAN_MAXMONTH (6) | |
#define | JULIAN_MAXDAY (3) | |
#define | IS_VALID_JULIAN(y, m, d) | |
#define | MIN_TIMESTAMP INT64CONST(-211813488000000000) | |
#define | END_TIMESTAMP INT64CONST(9223371331200000000) | |
#define | IS_VALID_TIMESTAMP(t) (MIN_TIMESTAMP <= (t) && (t) < END_TIMESTAMP) | |
#define | UTIME_MINYEAR (1901) | |
#define | UTIME_MINMONTH (12) | |
#define | UTIME_MINDAY (14) | |
#define | UTIME_MAXYEAR (2038) | |
#define | UTIME_MAXMONTH (01) | |
#define | UTIME_MAXDAY (18) | |
#define | IS_VALID_UTIME(y, m, d) | |
#define | DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1) | |
#define | DT_NOEND (INT64CONST(0x7fffffffffffffff)) | |
#define | TIMESTAMP_NOBEGIN(j) do {(j) = DT_NOBEGIN;} while (0) | |
#define | TIMESTAMP_NOEND(j) do {(j) = DT_NOEND;} while (0) | |
#define | TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN) | |
#define | TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND) | |
#define | TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) | | TIMESTAMP_IS_NOEND(j)) |
Functions | |
---|---|
int | DecodeInterval (char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec) |
int | DecodeTime (char *str, int *tmask, struct tm *tm, fsec_t *fsec) |
void | EncodeDateTime (struct tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str, bool EuroDates) |
void | EncodeInterval (struct tm *tm, fsec_t fsec, int style, char *str) |
int | tm2timestamp (struct tm *tm, fsec_t fsec, int *tzp, timestamp *result) |
int | DecodeUnits (int field, char *lowtoken, int *val) |
bool | CheckDateTokenTables (void) |
void | EncodeDateOnly (struct tm *tm, int style, char *str, bool EuroDates) |
int | GetEpochTime (struct tm *tm) |
int | ParseDateTime (char *timestr, char *lowstr, char **field, int *ftype, int *numfields, char **endstr) |
int | DecodeDateTime (char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec, bool EuroDates) |
void | j2date (int jd, int *year, int *month, int *day) |
void | GetCurrentDateTime (struct tm *tm) |
int | date2j (int y, int m, int d) |
void | TrimTrailingZeros (char *str) |
void | dt2time (double jd, int *hour, int *min, int *sec, fsec_t *fsec) |
int | PGTYPEStimestamp_defmt_scan (char **str, char *fmt, timestamp *d, int *year, int *month, int *day, int *hour, int *minute, int *second, int *tz) |
Variables | |
---|---|
char * | pgtypes_date_weekdays_short [] |
char * | pgtypes_date_months [] |
char * | months [] |
char * | days [] |
const int | day_tab [2][13] |
◆ ABS_AFTER
Definition at line 114 of file dt.h.
◆ ABS_BEFORE
Definition at line 113 of file dt.h.
◆ AD
Definition at line 75 of file dt.h.
◆ ADBC
Definition at line 110 of file dt.h.
◆ AGO
Definition at line 112 of file dt.h.
◆ AM
Definition at line 71 of file dt.h.
◆ AMPM
Definition at line 101 of file dt.h.
◆ BC
Definition at line 76 of file dt.h.
◆ DA_D
Definition at line 60 of file dt.h.
◆ DAGO
Definition at line 35 of file dt.h.
◆ DAY
Definition at line 95 of file dt.h.
◆ DAYS_PER_MONTH
#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */
Definition at line 244 of file dt.h.
◆ DAYS_PER_YEAR
#define DAYS_PER_YEAR 365.25 /* assumes leap year every four years */
Definition at line 235 of file dt.h.
◆ DB_C
Definition at line 61 of file dt.h.
◆ DCENTURY
#define DCENTURY "century"
Definition at line 58 of file dt.h.
◆ DCURRENT
#define DCURRENT "current"
Definition at line 36 of file dt.h.
◆ DDAY
Definition at line 52 of file dt.h.
◆ DDECADE
Definition at line 57 of file dt.h.
◆ DHOUR
Definition at line 51 of file dt.h.
◆ DMICROSEC
#define DMICROSEC "usecond"
Definition at line 47 of file dt.h.
◆ DMILLENNIUM
#define DMILLENNIUM "millennium"
Definition at line 59 of file dt.h.
◆ DMILLISEC
#define DMILLISEC "msecond"
Definition at line 48 of file dt.h.
◆ DMINUTE
Definition at line 50 of file dt.h.
◆ DMONTH
Definition at line 54 of file dt.h.
◆ DOW
Definition at line 108 of file dt.h.
◆ DOY
Definition at line 107 of file dt.h.
◆ DQUARTER
#define DQUARTER "quarter"
Definition at line 55 of file dt.h.
◆ DSECOND
Definition at line 49 of file dt.h.
◆ DT_NOBEGIN
#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1)
Definition at line 305 of file dt.h.
◆ DT_NOEND
Definition at line 306 of file dt.h.
◆ DTERR_BAD_FORMAT
#define DTERR_BAD_FORMAT (-1)
Definition at line 28 of file dt.h.
◆ DTERR_FIELD_OVERFLOW
#define DTERR_FIELD_OVERFLOW (-2)
Definition at line 29 of file dt.h.
◆ DTERR_INTERVAL_OVERFLOW
#define DTERR_INTERVAL_OVERFLOW (-4)
Definition at line 31 of file dt.h.
◆ DTERR_MD_FIELD_OVERFLOW
#define DTERR_MD_FIELD_OVERFLOW (-3) /* triggers hint about DateStyle */
Definition at line 30 of file dt.h.
◆ DTERR_TZDISP_OVERFLOW
#define DTERR_TZDISP_OVERFLOW (-5)
Definition at line 32 of file dt.h.
◆ DTIMEZONE
#define DTIMEZONE "timezone"
Definition at line 62 of file dt.h.
◆ DTK_AGO
Definition at line 145 of file dt.h.
◆ DTK_ALL_SECS_M
Definition at line 186 of file dt.h.
◆ DTK_CENTURY
Definition at line 167 of file dt.h.
◆ DTK_DATE
Definition at line 142 of file dt.h.
◆ DTK_DATE_M
Definition at line 187 of file dt.h.
◆ DTK_DAY
Definition at line 161 of file dt.h.
◆ DTK_DECADE
Definition at line 166 of file dt.h.
◆ DTK_DELTA
Definition at line 157 of file dt.h.
◆ DTK_DOW
Definition at line 173 of file dt.h.
◆ DTK_DOY
Definition at line 174 of file dt.h.
◆ DTK_EARLY
Definition at line 148 of file dt.h.
◆ DTK_EPOCH
Definition at line 150 of file dt.h.
◆ DTK_HOUR
Definition at line 160 of file dt.h.
◆ DTK_ISODOW
Definition at line 178 of file dt.h.
◆ DTK_ISOYEAR
Definition at line 177 of file dt.h.
◆ DTK_JULIAN
Definition at line 171 of file dt.h.
◆ DTK_LATE
Definition at line 149 of file dt.h.
◆ DTK_M
| #define DTK_M | ( | | t | ) | (0x01 << (t)) | | -------------- | - | | - | - | ------------- |
Definition at line 185 of file dt.h.
◆ DTK_MICROSEC
Definition at line 170 of file dt.h.
◆ DTK_MILLENNIUM
#define DTK_MILLENNIUM 28
Definition at line 168 of file dt.h.
◆ DTK_MILLISEC
Definition at line 169 of file dt.h.
◆ DTK_MINUTE
Definition at line 159 of file dt.h.
◆ DTK_MONTH
Definition at line 163 of file dt.h.
◆ DTK_NOW
Definition at line 151 of file dt.h.
◆ DTK_NUMBER
Definition at line 139 of file dt.h.
◆ DTK_QUARTER
Definition at line 164 of file dt.h.
◆ DTK_SECOND
Definition at line 158 of file dt.h.
◆ DTK_SPECIAL
Definition at line 147 of file dt.h.
◆ DTK_STRING
Definition at line 140 of file dt.h.
◆ DTK_TIME
Definition at line 143 of file dt.h.
◆ DTK_TIME_M
Definition at line 188 of file dt.h.
◆ DTK_TODAY
Definition at line 153 of file dt.h.
◆ DTK_TOMORROW
Definition at line 154 of file dt.h.
◆ DTK_TZ
Definition at line 144 of file dt.h.
◆ DTK_TZ_HOUR
Definition at line 175 of file dt.h.
◆ DTK_TZ_MINUTE
Definition at line 176 of file dt.h.
◆ DTK_WEEK
Definition at line 162 of file dt.h.
◆ DTK_YEAR
Definition at line 165 of file dt.h.
◆ DTK_YESTERDAY
Definition at line 152 of file dt.h.
◆ DTK_ZULU
Definition at line 155 of file dt.h.
◆ DTZ
#define DTZ 6 /* fixed-offset timezone abbrev, DST */
Definition at line 98 of file dt.h.
◆ DTZMOD
#define DTZMOD 28 /* "DST" as a separate word */
Definition at line 119 of file dt.h.
◆ DWEEK
Definition at line 53 of file dt.h.
◆ DYEAR
Definition at line 56 of file dt.h.
◆ DYNTZ
#define DYNTZ 7 /* dynamic timezone abbr (unimplemented) */
Definition at line 99 of file dt.h.
◆ EARLY
#define EARLY "-infinity"
Definition at line 39 of file dt.h.
◆ END_TIMESTAMP
#define END_TIMESTAMP INT64CONST(9223371331200000000)
Definition at line 287 of file dt.h.
◆ EPOCH
Definition at line 37 of file dt.h.
◆ FMODULO
| #define FMODULO | ( | | t, | | --------------- | - | | -- | | | q, | | | | | | u | | | | | ) | | | |
Value:
do { \
(q) = (((t) < 0) ? ceil((t) / (u)): floor((t) / (u))); \
if ((q) != 0) (t) -= rint((q) * (u)); \
} while(0)
Definition at line 217 of file dt.h.
◆ HOUR
Definition at line 102 of file dt.h.
◆ HOURS_PER_DAY
#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */
Definition at line 245 of file dt.h.
◆ HR24
Definition at line 73 of file dt.h.
◆ IGNORE_DTF
Definition at line 100 of file dt.h.
◆ INTERVAL_FULL_RANGE
#define INTERVAL_FULL_RANGE (0x7FFF)
Definition at line 24 of file dt.h.
◆ INTERVAL_MASK
| #define INTERVAL_MASK | ( | | b | ) | (1 << (b)) | | ---------------------- | - | | ---------------------------------------------------- | - | ------------------------------------------------------------- |
Definition at line 25 of file dt.h.
◆ INTSTYLE_ISO_8601
#define INTSTYLE_ISO_8601 3
Definition at line 22 of file dt.h.
◆ INTSTYLE_POSTGRES
#define INTSTYLE_POSTGRES 0
Definition at line 19 of file dt.h.
◆ INTSTYLE_POSTGRES_VERBOSE
#define INTSTYLE_POSTGRES_VERBOSE 1
Definition at line 20 of file dt.h.
◆ INTSTYLE_SQL_STANDARD
#define INTSTYLE_SQL_STANDARD 2
Definition at line 21 of file dt.h.
◆ INVALID
#define INVALID "invalid"
Definition at line 38 of file dt.h.
◆ IS_VALID_JULIAN
| #define IS_VALID_JULIAN | ( | | y, | | ------------------------- | - | | ----------------------------------------------------- | | | m, | | | | | | d | | | | | ) | | | |
Value:
Definition at line 280 of file dt.h.
◆ IS_VALID_TIMESTAMP
Definition at line 289 of file dt.h.
◆ IS_VALID_UTIME
| #define IS_VALID_UTIME | ( | | y, | | ------------------------ | - | | ----------------------------------------------------- | | | m, | | | | | | d | | | | | ) | | | |
Value:
Definition at line 298 of file dt.h.
◆ isleap
| #define isleap | ( | | y | ) | (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) | | -------------- | - | | ---------------------------------------------------- | - | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Definition at line 267 of file dt.h.
◆ ISODATE
Definition at line 116 of file dt.h.
◆ ISOTIME
Definition at line 117 of file dt.h.
◆ JULIAN
Definition at line 96 of file dt.h.
◆ JULIAN_MAXDAY
#define JULIAN_MAXDAY (3)
Definition at line 278 of file dt.h.
◆ JULIAN_MAXMONTH
#define JULIAN_MAXMONTH (6)
Definition at line 277 of file dt.h.
◆ JULIAN_MAXYEAR
#define JULIAN_MAXYEAR (5874898)
Definition at line 276 of file dt.h.
◆ JULIAN_MINDAY
#define JULIAN_MINDAY (24)
Definition at line 275 of file dt.h.
◆ JULIAN_MINMONTH
#define JULIAN_MINMONTH (11)
Definition at line 274 of file dt.h.
◆ JULIAN_MINYEAR
#define JULIAN_MINYEAR (-4713)
Definition at line 273 of file dt.h.
◆ LATE
Definition at line 40 of file dt.h.
◆ MAX_INTERVAL_PRECISION
#define MAX_INTERVAL_PRECISION 6
Definition at line 26 of file dt.h.
◆ MAXDATEFIELDS
Definition at line 198 of file dt.h.
◆ MAXDATELEN
Definition at line 196 of file dt.h.
◆ MAXTZLEN
Definition at line 10 of file dt.h.
◆ MICROSECOND
Definition at line 106 of file dt.h.
◆ MILLISECOND
Definition at line 105 of file dt.h.
◆ MIN_TIMESTAMP
#define MIN_TIMESTAMP INT64CONST(-211813488000000000)
Definition at line 286 of file dt.h.
◆ MINS_PER_HOUR
Definition at line 256 of file dt.h.
◆ MINUTE
Definition at line 103 of file dt.h.
◆ MONTH
Definition at line 93 of file dt.h.
◆ MONTHS_PER_YEAR
#define MONTHS_PER_YEAR 12
Definition at line 236 of file dt.h.
◆ NOW
Definition at line 41 of file dt.h.
◆ PM
Definition at line 72 of file dt.h.
◆ RESERV
Definition at line 92 of file dt.h.
◆ SECOND
Definition at line 104 of file dt.h.
◆ SECS_PER_DAY
#define SECS_PER_DAY 86400
Definition at line 253 of file dt.h.
◆ SECS_PER_HOUR
#define SECS_PER_HOUR 3600
Definition at line 254 of file dt.h.
◆ SECS_PER_MINUTE
#define SECS_PER_MINUTE 60
Definition at line 255 of file dt.h.
◆ SECS_PER_YEAR
#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */
Definition at line 252 of file dt.h.
◆ TIMESTAMP_IS_NOBEGIN
Definition at line 310 of file dt.h.
◆ TIMESTAMP_IS_NOEND
Definition at line 311 of file dt.h.
◆ TIMESTAMP_NOBEGIN
Definition at line 308 of file dt.h.
◆ TIMESTAMP_NOEND
Definition at line 309 of file dt.h.
◆ TIMESTAMP_NOT_FINITE
Definition at line 312 of file dt.h.
◆ TMODULO
| #define TMODULO | ( | | t, | | --------------- | - | | -- | | | q, | | | | | | u | | | | | ) | | | |
Value:
do { \
(q) = ((t) / (u)); \
if ((q) != 0) (t) -= ((q) * (u)); \
} while(0)
Definition at line 228 of file dt.h.
◆ TODAY
Definition at line 42 of file dt.h.
◆ TOKMAXLEN
Definition at line 200 of file dt.h.
◆ TOMORROW
#define TOMORROW "tomorrow"
Definition at line 43 of file dt.h.
◆ TZ
#define TZ 5 /* fixed-offset timezone abbreviation */
Definition at line 97 of file dt.h.
◆ UNITS
Definition at line 109 of file dt.h.
◆ UNKNOWN_FIELD
Definition at line 121 of file dt.h.
◆ USE_GERMAN_DATES
#define USE_GERMAN_DATES 3
Definition at line 17 of file dt.h.
◆ USE_ISO_DATES
Definition at line 15 of file dt.h.
◆ USE_POSTGRES_DATES
#define USE_POSTGRES_DATES 0
Definition at line 14 of file dt.h.
◆ USE_SQL_DATES
Definition at line 16 of file dt.h.
◆ USECS_PER_DAY
Definition at line 258 of file dt.h.
◆ USECS_PER_HOUR
Definition at line 259 of file dt.h.
◆ USECS_PER_MINUTE
Definition at line 260 of file dt.h.
◆ USECS_PER_SEC
Definition at line 261 of file dt.h.
◆ UTIME_MAXDAY
#define UTIME_MAXDAY (18)
Definition at line 296 of file dt.h.
◆ UTIME_MAXMONTH
#define UTIME_MAXMONTH (01)
Definition at line 295 of file dt.h.
◆ UTIME_MAXYEAR
#define UTIME_MAXYEAR (2038)
Definition at line 294 of file dt.h.
◆ UTIME_MINDAY
#define UTIME_MINDAY (14)
Definition at line 293 of file dt.h.
◆ UTIME_MINMONTH
#define UTIME_MINMONTH (12)
Definition at line 292 of file dt.h.
◆ UTIME_MINYEAR
#define UTIME_MINYEAR (1901)
Definition at line 291 of file dt.h.
◆ YEAR
Definition at line 94 of file dt.h.
◆ YESTERDAY
#define YESTERDAY "yesterday"
Definition at line 44 of file dt.h.
◆ ZULU
Definition at line 45 of file dt.h.
◆ fsec_t
Definition at line 12 of file dt.h.
◆ CheckDateTokenTables()
bool CheckDateTokenTables | ( | void | ) |
---|
Definition at line 4927 of file datetime.c.
4928{
4929 bool ok = true;
4930
4933
4936 return ok;
4937}
static bool CheckDateTokenTable(const char *tablename, const datetkn *base, int nel)
static const datetkn datetktbl[]
static const int szdeltatktbl
static const int szdatetktbl
int date2j(int year, int month, int day)
static const datetkn deltatktbl[]
#define POSTGRES_EPOCH_JDATE
Assert(PointerIsAligned(start, uint64))
References Assert(), CheckDateTokenTable(), date2j(), datetktbl, deltatktbl, POSTGRES_EPOCH_JDATE, szdatetktbl, szdeltatktbl, and UNIX_EPOCH_JDATE.
Referenced by PostmasterMain().
◆ date2j()
int date2j | ( | int | y, |
---|---|---|---|
int | m, | ||
int | d | ||
) |
Definition at line 296 of file datetime.c.
297{
298 int julian;
299 int century;
300
301 if (month > 2)
302 {
303 month += 1;
304 year += 4800;
305 }
306 else
307 {
308 month += 13;
309 year += 4799;
310 }
311
312 century = year / 100;
313 julian = year * 365 - 32167;
314 julian += year / 4 - century + century / 4;
315 julian += 7834 * month / 256 + day;
316
317 return julian;
318}
References y.
Referenced by CheckDateTokenTables(), date2isoweek(), date2isoyear(), date2isoyearday(), date_in(), DCH_to_char(), DecodeDateTime(), DecodeNumber(), DetermineTimeZoneOffsetInternal(), EncodeDateTime(), extract_date(), GetSQLCurrentDate(), isoweek2j(), make_date(), make_timestamp_internal(), parse_datetime(), PGTYPESdate_dayofweek(), PGTYPESdate_defmt_asc(), PGTYPESdate_fmt_asc(), PGTYPESdate_from_asc(), PGTYPESdate_julmdy(), PGTYPESdate_mdyjul(), PGTYPESdate_to_asc(), PGTYPESdate_today(), timestamp2tm(), timestamp_date(), timestamp_part_common(), timestamp_pl_interval(), timestamp_to_char(), timestamptz_date(), timestamptz_part_common(), timestamptz_pl_interval_internal(), timestamptz_to_char(), tm2timestamp(), to_date(), and ValidateDate().
◆ DecodeDateTime()
int DecodeDateTime | ( | char ** | field, |
---|---|---|---|
int * | ftype, | ||
int | nf, | ||
int * | dtype, | ||
struct tm * | tm, | ||
fsec_t * | fsec, | ||
bool | EuroDates | ||
) |
Definition at line 1782 of file dt_common.c.
1784{
1785 int fmask = 0,
1786 tmask,
1788 int ptype = 0;
1789 int i;
1790 int val;
1791 int mer = HR24;
1792 bool haveTextMonth = false;
1793 bool is2digits = false;
1794 bool bc = false;
1795 int t = 0;
1796 int *tzp = &t;
1797
1798
1799
1800
1801
1806 *fsec = 0;
1807
1809 if (tzp != NULL)
1810 *tzp = 0;
1811
1813 {
1814 switch (ftype[i])
1815 {
1817
1818
1819
1820
1821
1823 {
1824 char *cp;
1825 int jday;
1826
1827 if (tzp == NULL)
1828 return -1;
1829
1830 jday = strtoint(field[i], &cp, 10);
1831 if (*cp != '-')
1832 return -1;
1833
1835
1837 return -1;
1838
1840 ptype = 0;
1841 break;
1842 }
1843
1844
1845
1846
1847
1848
1850 || (ptype != 0))
1851 {
1852
1853 if (tzp == NULL)
1854 return -1;
1855
1856 if (isdigit((unsigned char) *field[i]) || ptype != 0)
1857 {
1858 char *cp;
1859
1860 if (ptype != 0)
1861 {
1862
1864 return -1;
1865 ptype = 0;
1866 }
1867
1868
1869
1870
1871
1872
1874 return -1;
1875
1876 if ((cp = strchr(field[i], '-')) == NULL)
1877 return -1;
1878
1879
1881 return -1;
1882 *cp = '\0';
1883
1884
1885
1886
1887
1889 &tmask, tm, fsec, &is2digits)) < 0)
1890 return -1;
1891
1892
1893
1894
1895
1897 }
1898 else
1899 {
1901 return -1;
1902
1905 }
1906 }
1907 else if (DecodeDate(field[i], fmask, &tmask, tm, EuroDates) != 0)
1908 return -1;
1909 break;
1910
1912 if (DecodeTime(field[i], &tmask, tm, fsec) != 0)
1913 return -1;
1914
1915
1916
1917
1918
1919
1922 return -1;
1923 break;
1924
1926 {
1927 int tz;
1928
1929 if (tzp == NULL)
1930 return -1;
1931
1933 return -1;
1934
1935
1936
1937
1938
1939 if (i > 0 && (fmask & DTK_M(TZ)) != 0 &&
1940 ftype[i - 1] == DTK_TZ &&
1941 isalpha((unsigned char) *field[i - 1]))
1942 {
1943 *tzp -= tz;
1944 tmask = 0;
1945 }
1946 else
1947 {
1948 *tzp = tz;
1950 }
1951 }
1952 break;
1953
1955
1956
1957
1958
1959
1960 if (ptype != 0)
1961 {
1962 char *cp;
1964
1966
1967
1968
1969
1970
1971 if (*cp == '.')
1972 switch (ptype)
1973 {
1977 break;
1978 default:
1979 return 1;
1980 break;
1981 }
1982 else if (*cp != '\0')
1983 return -1;
1984
1985 switch (ptype)
1986 {
1990 break;
1991
1993
1994
1995
1996
1997
2000 {
2003 }
2004 else
2005 {
2008 }
2009 break;
2010
2014 break;
2015
2019 break;
2020
2024 break;
2025
2029 if (*cp == '.')
2030 {
2031 double frac;
2032
2033 frac = strtod(cp, &cp);
2034 if (*cp != '\0')
2035 return -1;
2036 *fsec = frac * 1000000;
2037 }
2038 break;
2039
2043 return -1;
2044 break;
2045
2047
2048
2049
2052
2053 if (*cp == '.')
2054 {
2055 double time;
2056
2057 time = strtod(cp, &cp);
2058 if (*cp != '\0')
2059 return -1;
2060
2063 }
2064 break;
2065
2067
2069 &tmask, tm, fsec, &is2digits)) < 0)
2070 return -1;
2071
2073 return -1;
2074 break;
2075
2076 default:
2077 return -1;
2078 break;
2079 }
2080
2081 ptype = 0;
2083 }
2084 else
2085 {
2086 char *cp;
2087 int flen;
2088
2089 flen = strlen(field[i]);
2090 cp = strchr(field[i], '.');
2091
2092
2093 if (cp != NULL && !(fmask & DTK_DATE_M))
2094 {
2095 if (DecodeDate(field[i], fmask, &tmask, tm, EuroDates) != 0)
2096 return -1;
2097 }
2098
2099 else if (cp != NULL && flen - strlen(cp) > 2)
2100 {
2101
2102
2103
2104
2105
2107 &tmask, tm, fsec, &is2digits)) < 0)
2108 return -1;
2109 }
2110 else if (flen > 4)
2111 {
2113 &tmask, tm, fsec, &is2digits)) < 0)
2114 return -1;
2115 }
2116
2118 &tmask, tm, fsec, &is2digits, EuroDates) != 0)
2119 return -1;
2120 }
2121 break;
2122
2127 continue;
2128
2130 switch (type)
2131 {
2133 switch (val)
2134 {
2139 break;
2140
2150 break;
2151
2159 break;
2160
2170 break;
2171
2178 if (tzp != NULL)
2179 *tzp = 0;
2180 break;
2181
2182 default:
2183 *dtype = val;
2184 }
2185
2186 break;
2187
2189
2190
2191
2192
2193
2194 if ((fmask & DTK_M(MONTH)) && !haveTextMonth &&
2196 {
2199 }
2200 haveTextMonth = true;
2202 break;
2203
2205
2206
2207
2208
2209
2212 if (tzp == NULL)
2213 return -1;
2214 *tzp -= val;
2215 break;
2216
2217 case DTZ:
2218
2219
2220
2221
2222
2225 if (tzp == NULL)
2226 return -1;
2227 *tzp = -val;
2229 break;
2230
2231 case TZ:
2233 if (tzp == NULL)
2234 return -1;
2235 *tzp = -val;
2237 break;
2238
2240 break;
2241
2243 mer = val;
2244 break;
2245
2248 break;
2249
2250 case DOW:
2252 break;
2253
2255 tmask = 0;
2256 ptype = val;
2257 break;
2258
2260
2261
2262
2263
2264
2265 tmask = 0;
2266
2267
2269 return -1;
2270
2271
2272
2273
2274
2275
2276
2277 if (i >= nf - 1 ||
2281 return -1;
2282
2283 ptype = val;
2284 break;
2285
2286 default:
2287 return -1;
2288 }
2289 break;
2290
2291 default:
2292 return -1;
2293 }
2294
2295 if (tmask & fmask)
2296 return -1;
2297 fmask |= tmask;
2298 }
2299
2300
2301 if (bc)
2302 {
2305 else
2306 return -1;
2307 }
2308 else if (is2digits)
2309 {
2314 }
2315
2317 return -1;
2320 else if (mer == PM && tm->tm_hour != 12)
2322
2323
2325 {
2328
2329
2330
2331
2332
2334 return -1;
2335
2336
2337
2338
2339
2340
2342 return -1;
2343 }
2344
2345 return 0;
2346}
void GetCurrentDateTime(struct tm *tm)
static int DecodeTimezone(char *str, int *tzp)
static int DecodePosixTimezone(char *str, int *tzp)
int DecodeTime(char *str, int *tmask, struct tm *tm, fsec_t *fsec)
int date2j(int y, int m, int d)
static int DecodeNumber(int flen, char *str, int fmask, int *tmask, struct tm *tm, fsec_t *fsec, bool *is2digits, bool EuroDates)
static int DecodeSpecial(int field, char *lowtoken, int *val)
void j2date(int jd, int *year, int *month, int *day)
static int DecodeNumberField(int len, char *str, int fmask, int *tmask, struct tm *tm, fsec_t *fsec, bool *is2digits)
void dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
static int DecodeDate(char *str, int fmask, int *tmask, struct tm *tm, bool EuroDates)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
References ADBC, AM, AMPM, BC, date2j(), DAY, day_tab, DecodeDate(), DecodeNumber(), DecodeNumberField(), DecodePosixTimezone(), DecodeSpecial(), DecodeTime(), DecodeTimezone(), DOW, dt2time(), DTK_DATE, DTK_DATE_M, DTK_DAY, DTK_HOUR, DTK_JULIAN, DTK_M, DTK_MINUTE, DTK_MONTH, DTK_NOW, DTK_NUMBER, DTK_SECOND, DTK_SPECIAL, DTK_STRING, DTK_TIME, DTK_TIME_M, DTK_TODAY, DTK_TOMORROW, DTK_TZ, DTK_YEAR, DTK_YESTERDAY, DTK_ZULU, DTZ, DTZMOD, GetCurrentDateTime(), HOUR, HR24, i, IGNORE_DTF, isleap, ISOTIME, j2date(), MINUTE, MONTH, PM, RESERV, SECOND, strtoint(), tm, pg_tm::tm_hour, pg_tm::tm_isdst, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_wday, pg_tm::tm_year, type, TZ, UNITS, USECS_PER_DAY, val, value, and YEAR.
◆ DecodeInterval()
int DecodeInterval | ( | char ** | field, |
---|---|---|---|
int * | ftype, | ||
int | nf, | ||
int * | dtype, | ||
struct tm * | tm, | ||
fsec_t * | fsec | ||
) |
Definition at line 326 of file interval.c.
328{
331 bool is_before = false;
332 char *cp;
333 int fmask = 0,
334 tmask,
336 int i;
337 int dterr;
339 double fval;
340
344
345
346 for (i = nf - 1; i >= 0; i--)
347 {
348 switch (ftype[i])
349 {
351 dterr = DecodeTime(field[i],
352 &tmask, tm, fsec);
353 if (dterr)
354 return dterr;
356 break;
357
359
360
361
362
363
364
365 Assert(*field[i] == '-' || *field[i] == '+');
366
367
368
369
370
371
372 if (strchr(field[i] + 1, ':') != NULL &&
373 DecodeTime(field[i] + 1,
374 &tmask, tm, fsec) == 0)
375 {
376 if (*field[i] == '-')
377 {
378
382 *fsec = -(*fsec);
383 }
384
385
386
387
388
389
392 break;
393 }
394
395
399 {
400
402 {
405 break;
409 break;
412 break;
418 break;
422 break;
427 break;
428 default:
430 break;
431 }
432 }
433
434 errno = 0;
436 if (errno == ERANGE)
438
439 if (*cp == '-')
440 {
441
442 int val2;
443
444 val2 = strtoint(cp + 1, &cp, 10);
445 if (errno == ERANGE || val2 < 0 || val2 >= MONTHS_PER_YEAR)
447 if (*cp != '\0')
450 if (*field[i] == '-')
451 val2 = -val2;
453 fval = 0;
454 }
455 else if (*cp == '.')
456 {
457 errno = 0;
458 fval = strtod(cp, &cp);
459 if (*cp != '\0' || errno != 0)
461
462 if (*field[i] == '-')
463 fval = -fval;
464 }
465 else if (*cp == '\0')
466 fval = 0;
467 else
469
470 tmask = 0;
471
472 switch (type)
473 {
475 *fsec += rint(val + fval);
477 break;
478
480 *fsec += rint((val + fval) * 1000);
482 break;
483
486 *fsec += rint(fval * 1000000);
487
488
489
490
491
492 if (fval == 0)
494 else
496 break;
497
502 break;
503
509 break;
510
515 break;
516
521 break;
522
527 break;
528
533 break;
534
539 break;
540
545 break;
546
551 break;
552
553 default:
555 }
556 break;
557
562 continue;
563
564 tmask = 0;
565 switch (type)
566 {
569 break;
570
571 case AGO:
572 is_before = true;
574 break;
575
578 *dtype = val;
579 break;
580
581 default:
583 }
584 break;
585
586 default:
588 }
589
590 if (tmask & fmask)
592 fmask |= tmask;
593 }
594
595
596 if (fmask == 0)
598
599
600 if (*fsec != 0)
601 {
602 int sec;
603
607 }
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
626 {
627
628 bool more_signs = false;
629
631 {
632 if (*field[i] == '-' || *field[i] == '+')
633 {
634 more_signs = true;
635 break;
636 }
637 }
638
639 if (!more_signs)
640 {
641
642
643
644
645 if (*fsec > 0)
646 *fsec = -(*fsec);
659 }
660 }
661
662
663 if (is_before)
664 {
665 *fsec = -(*fsec);
672 }
673
674 return 0;
675}
int DecodeUnits(int field, const char *lowtoken, int *val)
static int DecodeTime(char *str, int fmask, int range, int *tmask, struct pg_tm *tm, fsec_t *fsec)
#define DTERR_FIELD_OVERFLOW
static void AdjustFractDays(double frac, struct tm *tm, fsec_t *fsec, int scale)
static void ClearPgTm(struct tm *tm, fsec_t *fsec)
static void AdjustFractSeconds(double frac, struct tm *tm, fsec_t *fsec, int scale)
#define INTSTYLE_SQL_STANDARD
#define INTSTYLE_POSTGRES_VERBOSE
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
#define INTERVAL_FULL_RANGE
References AdjustFractDays(), AdjustFractSeconds(), AGO, Assert(), ClearPgTm(), DAY, DAYS_PER_MONTH, DecodeTime(), DecodeUnits(), DTERR_BAD_FORMAT, DTERR_FIELD_OVERFLOW, DTK_ALL_SECS_M, DTK_CENTURY, DTK_DATE, DTK_DATE_M, DTK_DAY, DTK_DECADE, DTK_DELTA, DTK_HOUR, DTK_M, DTK_MICROSEC, DTK_MILLENNIUM, DTK_MILLISEC, DTK_MINUTE, DTK_MONTH, DTK_NUMBER, DTK_SECOND, DTK_SPECIAL, DTK_STRING, DTK_TIME, DTK_TIME_M, DTK_TZ, DTK_WEEK, DTK_YEAR, HOUR, i, IGNORE_DTF, INTERVAL_FULL_RANGE, INTERVAL_MASK, IntervalStyle, INTSTYLE_POSTGRES_VERBOSE, INTSTYLE_SQL_STANDARD, MICROSECOND, MILLISECOND, MINUTE, MONTH, MONTHS_PER_YEAR, range(), RESERV, SECOND, SECS_PER_DAY, SECS_PER_HOUR, SECS_PER_MINUTE, strtoint(), tm, pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_year, type, TZ, UNITS, USECS_PER_SEC, val, and YEAR.
Referenced by PGTYPESinterval_from_asc().
◆ DecodeTime()
int DecodeTime | ( | char * | str, |
---|---|---|---|
int * | tmask, | ||
struct tm * | tm, | ||
fsec_t * | fsec | ||
) |
Definition at line 1437 of file dt_common.c.
1438{
1439 char *cp;
1440
1442
1444 if (*cp != ':')
1445 return -1;
1446 str = cp + 1;
1448 if (*cp == '\0')
1449 {
1451 *fsec = 0;
1452 }
1453 else if (*cp != ':')
1454 return -1;
1455 else
1456 {
1457 str = cp + 1;
1459 if (*cp == '\0')
1460 *fsec = 0;
1461 else if (*cp == '.')
1462 {
1463 char fstr[7];
1464 int i;
1465
1466 cp++;
1467
1468
1469
1470
1471
1472
1473
1474
1475
1477 fstr[i] = *cp != '\0' ? *cp++ : '0';
1478 fstr[i] = '\0';
1479 *fsec = strtoint(fstr, &cp, 10);
1480 if (*cp != '\0')
1481 return -1;
1482 }
1483 else
1484 return -1;
1485 }
1486
1487
1490 return -1;
1491
1492 return 0;
1493}
References DTK_TIME_M, i, str, strtoint(), tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.
Referenced by DecodeDateTime().
◆ DecodeUnits()
int DecodeUnits | ( | int | field, |
---|---|---|---|
char * | lowtoken, | ||
int * | val | ||
) |
Definition at line 536 of file dt_common.c.
537{
540
541
545 else
548 if (tp == NULL)
549 {
551 *val = 0;
552 }
553 else
554 {
557 }
558
560}
static const datetkn * deltacache[MAXDATEFIELDS]
static const datetkn * datebsearch(const char *key, const datetkn *base, unsigned int nel)
static const unsigned int szdeltatktbl
static const datetkn deltatktbl[]
References datebsearch(), deltacache, deltatktbl, szdeltatktbl, TOKMAXLEN, type, datetkn::type, UNKNOWN_FIELD, val, and datetkn::value.
◆ dt2time()
void dt2time | ( | double | jd, |
---|---|---|---|
int * | hour, | ||
int * | min, | ||
int * | sec, | ||
fsec_t * | fsec | ||
) |
◆ EncodeDateOnly()
void EncodeDateOnly | ( | struct tm * | tm, |
---|---|---|---|
int | style, | ||
char * | str, | ||
bool | EuroDates | ||
) |
Definition at line 669 of file dt_common.c.
670{
672
673 switch (style)
674 {
676
680 else
683 break;
684
686
687 if (EuroDates)
689 else
693 else
695 break;
696
698
702 else
704 break;
705
707 default:
708
709 if (EuroDates)
711 else
715 else
717 break;
718 }
719}
#define USE_POSTGRES_DATES
References Assert(), MONTHS_PER_YEAR, sprintf, str, tm, pg_tm::tm_mday, pg_tm::tm_mon, pg_tm::tm_year, USE_GERMAN_DATES, USE_ISO_DATES, USE_POSTGRES_DATES, and USE_SQL_DATES.
◆ EncodeDateTime()
void EncodeDateTime | ( | struct tm * | tm, |
---|---|---|---|
fsec_t | fsec, | ||
bool | print_tz, | ||
int | tz, | ||
const char * | tzn, | ||
int | style, | ||
char * | str, | ||
bool | EuroDates | ||
) |
Definition at line 753 of file dt_common.c.
754{
755 int day,
756 hour,
757 min;
758
759
760
761
763 print_tz = false;
764
765 switch (style)
766 {
768
769
770 sprintf(str, "%04d-%02d-%02d %02d:%02d",
773
774
775
776
777
778 if (fsec != 0)
779 {
782 }
783 else
785
788
789 if (print_tz)
790 {
793 if (min != 0)
794 sprintf(str + strlen(str), "%+03d:%02d", hour, min);
795 else
797 }
798 break;
799
801
802
803 if (EuroDates)
805 else
807
811
812
813
814
815
816 if (fsec != 0)
817 {
820 }
821 else
823
826
827
828
829
830
831
832
833
834 if (print_tz)
835 {
836 if (tzn)
838 else
839 {
842 if (min != 0)
843 sprintf(str + strlen(str), "%+03d:%02d", hour, min);
844 else
846 }
847 }
848 break;
849
851
852
854
858
859
860
861
862
863 if (fsec != 0)
864 {
867 }
868 else
870
873
874 if (print_tz)
875 {
876 if (tzn)
878 else
879 {
882 if (min != 0)
883 sprintf(str + strlen(str), "%+03d:%02d", hour, min);
884 else
886 }
887 }
888 break;
889
891 default:
892
893
895 tm->tm_wday = (int) ((day + date2j(2000, 1, 1) + 1) % 7);
896
898 strcpy(str + 3, " ");
899
900 if (EuroDates)
902 else
904
906
907
908
909
910
911 if (fsec != 0)
912 {
915 }
916 else
918
923
924 if (print_tz)
925 {
926 if (tzn)
928 else
929 {
930
931
932
933
934
935
938 if (min != 0)
939 sprintf(str + strlen(str), " %+03d:%02d", hour, min);
940 else
942 }
943 }
944 break;
945 }
946}
void TrimTrailingZeros(char *str)
References date2j(), days, MAXTZLEN, MINS_PER_HOUR, months, SECS_PER_HOUR, sprintf, str, tm, pg_tm::tm_hour, pg_tm::tm_isdst, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_wday, pg_tm::tm_year, TrimTrailingZeros(), USE_GERMAN_DATES, USE_ISO_DATES, USE_POSTGRES_DATES, and USE_SQL_DATES.
◆ EncodeInterval()
void EncodeInterval | ( | struct tm * | tm, |
---|---|---|---|
fsec_t | fsec, | ||
int | style, | ||
char * | str | ||
) |
Definition at line 759 of file interval.c.
760{
761 char *cp = str;
768 bool is_before = false;
769 bool is_zero = true;
770
771
772
773
774
775
776
777 switch (style)
778 {
779
781 {
782 bool has_negative = year < 0 || mon < 0 ||
783 mday < 0 || hour < 0 ||
784 min < 0 || sec < 0 || fsec < 0;
785 bool has_positive = year > 0 || mon > 0 ||
786 mday > 0 || hour > 0 ||
787 min > 0 || sec > 0 || fsec > 0;
788 bool has_year_month = year != 0 || mon != 0;
789 bool has_day_time = mday != 0 || hour != 0 ||
790 min != 0 || sec != 0 || fsec != 0;
791 bool has_day = mday != 0;
792 bool sql_standard_value = !(has_negative && has_positive) &&
793 !(has_year_month && has_day_time);
794
795
796
797
798
799 if (has_negative && sql_standard_value)
800 {
801 *cp++ = '-';
802 year = -year;
803 mon = -mon;
804 mday = -mday;
805 hour = -hour;
806 min = -min;
807 sec = -sec;
808 fsec = -fsec;
809 }
810
811 if (!has_negative && !has_positive)
812 {
814 }
815 else if (!sql_standard_value)
816 {
817
818
819
820
821
822 char year_sign = (year < 0 || mon < 0) ? '-' : '+';
823 char day_sign = (mday < 0) ? '-' : '+';
824 char sec_sign = (hour < 0 || min < 0 ||
825 sec < 0 || fsec < 0) ? '-' : '+';
826
827 sprintf(cp, "%c%d-%d %c%d %c%d:%02d:",
828 year_sign, abs(year), abs(mon),
829 day_sign, abs(mday),
830 sec_sign, abs(hour), abs(min));
831 cp += strlen(cp);
833 }
834 else if (has_year_month)
835 {
836 sprintf(cp, "%d-%d", year, mon);
837 }
838 else if (has_day)
839 {
840 sprintf(cp, "%d %d:%02d:", mday, hour, min);
841 cp += strlen(cp);
843 }
844 else
845 {
846 sprintf(cp, "%d:%02d:", hour, min);
847 cp += strlen(cp);
849 }
850 }
851 break;
852
853
855
856 if (year == 0 && mon == 0 && mday == 0 &&
857 hour == 0 && min == 0 && sec == 0 && fsec == 0)
858 {
860 break;
861 }
862 *cp++ = 'P';
866 if (hour != 0 || min != 0 || sec != 0 || fsec != 0)
867 *cp++ = 'T';
870 if (sec != 0 || fsec != 0)
871 {
872 if (sec < 0 || fsec < 0)
873 *cp++ = '-';
875 cp += strlen(cp);
876 *cp++ = 'S';
877 *cp = '\0';
878 }
879 break;
880
881
886 if (is_zero || hour != 0 || min != 0 || sec != 0 || fsec != 0)
887 {
888 bool minus = (hour < 0 || min < 0 || sec < 0 || fsec < 0);
889
890 sprintf(cp, "%s%s%02d:%02d:",
891 is_zero ? "" : " ",
892 (minus ? "-" : (is_before ? "+" : "")),
893 abs(hour), abs(min));
894 cp += strlen(cp);
896 }
897 break;
898
899
901 default:
902 strcpy(cp, "@");
903 cp++;
909 if (sec != 0 || fsec != 0)
910 {
911 *cp++ = ' ';
912 if (sec < 0 || (sec == 0 && fsec < 0))
913 {
914 if (is_zero)
915 is_before = true;
916 else if (!is_before)
917 *cp++ = '-';
918 }
919 else if (is_before)
920 *cp++ = '-';
922 cp += strlen(cp);
923
925 (abs(sec) != 1 || fsec != 0) ? "s" : "");
926 is_zero = false;
927 }
928
929 if (is_zero)
930 strcat(cp, " 0");
931 if (is_before)
932 strcat(cp, " ago");
933 break;
934 }
935}
#define MAX_INTERVAL_PRECISION
static char * AddISO8601IntPart(char *cp, int value, char units)
static char * AddPostgresIntPart(char *cp, int value, const char *units, bool *is_zero, bool *is_before)
static void AppendSeconds(char *cp, int sec, fsec_t fsec, int precision, bool fillzeros)
static char * AddVerboseIntPart(char *cp, int value, const char *units, bool *is_zero, bool *is_before)
#define INTSTYLE_ISO_8601
#define INTSTYLE_POSTGRES
References AddISO8601IntPart(), AddPostgresIntPart(), AddVerboseIntPart(), AppendSeconds(), INTSTYLE_ISO_8601, INTSTYLE_POSTGRES, INTSTYLE_POSTGRES_VERBOSE, INTSTYLE_SQL_STANDARD, MAX_INTERVAL_PRECISION, sprintf, str, tm, pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, and pg_tm::tm_year.
Referenced by PGTYPESinterval_to_asc().
◆ GetCurrentDateTime()
void GetCurrentDateTime | ( | struct tm * | tm | ) |
---|
◆ GetEpochTime()
int GetEpochTime | ( | struct tm * | tm | ) |
---|
◆ j2date()
void j2date | ( | int | jd, |
---|---|---|---|
int * | year, | ||
int * | month, | ||
int * | day | ||
) |
Definition at line 321 of file datetime.c.
322{
323 unsigned int julian;
324 unsigned int quad;
325 unsigned int extra;
326 int y;
327
328 julian = jd;
329 julian += 32044;
330 quad = julian / 146097;
331 extra = (julian - quad * 146097) * 4 + 3;
332 julian += 60 + quad * 3 + extra / 146097;
333 quad = julian / 1461;
334 julian -= quad * 1461;
335 y = julian * 4 / 1461;
336 julian = ((y != 0) ? ((julian + 305) % 365) : ((julian + 306) % 366))
337 + 123;
338 y += quad * 4;
339 *year = y - 4800;
340 quad = julian * 2141 / 65536;
341 *day = julian - 7834 * quad / 256;
343}
References MONTHS_PER_YEAR, and y.
Referenced by date2timestamptz_opt_overflow(), date_out(), DecodeDateTime(), DecodeNumber(), DecodeTimeOnly(), do_to_timestamp(), executeDateTimeMethod(), extract_date(), isoweek2date(), isoweekdate2date(), JsonEncodeDateTime(), map_sql_value_to_xml_value(), PGTYPESdate_fmt_asc(), PGTYPESdate_julmdy(), PGTYPESdate_to_asc(), timestamp2tm(), timestamp_pl_interval(), timestamptz_pl_interval_internal(), and ValidateDate().
◆ ParseDateTime()
int ParseDateTime | ( | char * | timestr, |
---|---|---|---|
char * | lowstr, | ||
char ** | field, | ||
int * | ftype, | ||
int * | numfields, | ||
char ** | endstr | ||
) |
Definition at line 1600 of file dt_common.c.
1602{
1603 int nf = 0;
1604 char *lp = lowstr;
1605
1606 *endstr = timestr;
1607
1608 while (*(*endstr) != '\0')
1609 {
1610
1612 return -1;
1613 field[nf] = lp;
1614
1615
1616 if (isdigit((unsigned char) *(*endstr)))
1617 {
1618 *lp++ = *(*endstr)++;
1619 while (isdigit((unsigned char) *(*endstr)))
1620 *lp++ = *(*endstr)++;
1621
1622
1623 if (*(*endstr) == ':')
1624 {
1626 *lp++ = *(*endstr)++;
1627 while (isdigit((unsigned char) *(*endstr)) ||
1628 (*(*endstr) == ':') || (*(*endstr) == '.'))
1629 *lp++ = *(*endstr)++;
1630 }
1631
1632 else if (*(*endstr) == '-' || *(*endstr) == '/' || *(*endstr) == '.')
1633 {
1634
1635 char *dp = (*endstr);
1636
1637 *lp++ = *(*endstr)++;
1638
1639 if (isdigit((unsigned char) *(*endstr)))
1640 {
1642 while (isdigit((unsigned char) *(*endstr)))
1643 *lp++ = *(*endstr)++;
1644
1645
1646
1647
1648
1649 if (*(*endstr) == *dp)
1650 {
1652 *lp++ = *(*endstr)++;
1653 while (isdigit((unsigned char) *(*endstr)) || (*(*endstr) == *dp))
1654 *lp++ = *(*endstr)++;
1655 }
1656 }
1657 else
1658 {
1660 while (isalnum((unsigned char) *(*endstr)) || (*(*endstr) == *dp))
1661 *lp++ = pg_tolower((unsigned char) *(*endstr)++);
1662 }
1663 }
1664
1665
1666
1667
1668
1669 else
1671 }
1672
1673 else if (*(*endstr) == '.')
1674 {
1675 *lp++ = *(*endstr)++;
1676 while (isdigit((unsigned char) *(*endstr)))
1677 *lp++ = *(*endstr)++;
1678
1680 }
1681
1682
1683
1684
1685 else if (isalpha((unsigned char) *(*endstr)))
1686 {
1688 *lp++ = pg_tolower((unsigned char) *(*endstr)++);
1689 while (isalpha((unsigned char) *(*endstr)))
1690 *lp++ = pg_tolower((unsigned char) *(*endstr)++);
1691
1692
1693
1694
1695
1696 if (*(*endstr) == '-' || *(*endstr) == '/' || *(*endstr) == '.')
1697 {
1698 char *dp = (*endstr);
1699
1701 *lp++ = *(*endstr)++;
1702 while (isdigit((unsigned char) *(*endstr)) || *(*endstr) == *dp)
1703 *lp++ = *(*endstr)++;
1704 }
1705 }
1706
1707 else if (isspace((unsigned char) *(*endstr)))
1708 {
1709 (*endstr)++;
1710 continue;
1711 }
1712
1713 else if (*(*endstr) == '+' || *(*endstr) == '-')
1714 {
1715 *lp++ = *(*endstr)++;
1716
1717 while (isspace((unsigned char) *(*endstr)))
1718 (*endstr)++;
1719
1720 if (isdigit((unsigned char) *(*endstr)))
1721 {
1723 *lp++ = *(*endstr)++;
1724 while (isdigit((unsigned char) *(*endstr)) ||
1725 (*(*endstr) == ':') || (*(*endstr) == '.'))
1726 *lp++ = *(*endstr)++;
1727 }
1728
1729 else if (isalpha((unsigned char) *(*endstr)))
1730 {
1732 *lp++ = pg_tolower((unsigned char) *(*endstr)++);
1733 while (isalpha((unsigned char) *(*endstr)))
1734 *lp++ = pg_tolower((unsigned char) *(*endstr)++);
1735 }
1736
1737 else
1738 return -1;
1739 }
1740
1741 else if (ispunct((unsigned char) *(*endstr)))
1742 {
1743 (*endstr)++;
1744 continue;
1745 }
1746
1747 else
1748 return -1;
1749
1750
1751 *lp++ = '\0';
1752 nf++;
1753 }
1754
1755 *numfields = nf;
1756
1757 return 0;
1758}
unsigned char pg_tolower(unsigned char ch)
References DTK_DATE, DTK_NUMBER, DTK_SPECIAL, DTK_STRING, DTK_TIME, DTK_TZ, MAXDATEFIELDS, and pg_tolower().
◆ PGTYPEStimestamp_defmt_scan()
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 at line 2521 of file dt_common.c.
2525{
2527 int scan_type;
2528
2529 char *pstr,
2530 *pfmt,
2531 *tmp;
2532 int err = 1;
2533 unsigned int j;
2535
2536 pfmt = fmt;
2537 pstr = *str;
2538
2539 while (*pfmt)
2540 {
2541 err = 0;
2542 while (*pfmt == ' ')
2543 pfmt++;
2544 while (*pstr == ' ')
2545 pstr++;
2546 if (*pfmt != '%')
2547 {
2548 if (*pfmt == *pstr)
2549 {
2550 pfmt++;
2551 pstr++;
2552 }
2553 else
2554 {
2555
2556 err = 1;
2557 return err;
2558 }
2559 continue;
2560 }
2561
2562 pfmt++;
2563 switch (*pfmt)
2564 {
2565 case 'a':
2566 pfmt++;
2567
2568
2569
2570
2571
2572 err = 1;
2573 j = 0;
2575 {
2578 {
2579
2580 err = 0;
2582 break;
2583 }
2584 j++;
2585 }
2586 break;
2587 case 'A':
2588
2589 pfmt++;
2590 err = 1;
2591 j = 0;
2593 {
2594 if (strncmp(days[j], pstr, strlen(days[j])) == 0)
2595 {
2596
2597 err = 0;
2599 break;
2600 }
2601 j++;
2602 }
2603 break;
2604 case 'b':
2605 case 'h':
2606 pfmt++;
2607 err = 1;
2608 j = 0;
2610 {
2611 if (strncmp(months[j], pstr, strlen(months[j])) == 0)
2612 {
2613
2614 err = 0;
2615 pstr += strlen(months[j]);
2616 *month = j + 1;
2617 break;
2618 }
2619 j++;
2620 }
2621 break;
2622 case 'B':
2623
2624 pfmt++;
2625 err = 1;
2626 j = 0;
2628 {
2630 {
2631
2632 err = 0;
2634 *month = j + 1;
2635 break;
2636 }
2637 j++;
2638 }
2639 break;
2640 case 'c':
2641
2642 break;
2643 case 'C':
2644 pfmt++;
2647 *year = scan_val.uint_val * 100;
2648 break;
2649 case 'd':
2650 case 'e':
2651 pfmt++;
2654 *day = scan_val.uint_val;
2655 break;
2656 case 'D':
2657
2658
2659
2660
2661
2662 pfmt++;
2663 tmp = pgtypes_alloc(strlen("%m/%d/%y") + strlen(pstr) + 1);
2664 if (!tmp)
2665 return 1;
2666 strcpy(tmp, "%m/%d/%y");
2667 strcat(tmp, pfmt);
2670 return err;
2671 case 'm':
2672 pfmt++;
2675 *month = scan_val.uint_val;
2676 break;
2677 case 'y':
2678 case 'g':
2679 pfmt++;
2682 if (*year < 0)
2683 {
2684
2685 *year = scan_val.uint_val;
2686 }
2687 else
2688 *year += scan_val.uint_val;
2689 if (*year < 100)
2690 *year += 1900;
2691 break;
2692 case 'G':
2693
2694 pfmt++;
2697 *year = scan_val.uint_val;
2698 break;
2699 case 'H':
2700 case 'I':
2701 case 'k':
2702 case 'l':
2703 pfmt++;
2706 *hour += scan_val.uint_val;
2707 break;
2708 case 'j':
2709 pfmt++;
2712
2713
2714
2715
2716
2717
2718 break;
2719 case 'M':
2720 pfmt++;
2723 *minute = scan_val.uint_val;
2724 break;
2725 case 'n':
2726 pfmt++;
2727 if (*pstr == '\n')
2728 pstr++;
2729 else
2730 err = 1;
2731 break;
2732 case 'p':
2733 err = 1;
2734 pfmt++;
2735 if (strncmp(pstr, "am", 2) == 0)
2736 {
2737 *hour += 0;
2738 err = 0;
2739 pstr += 2;
2740 }
2741 if (strncmp(pstr, "a.m.", 4) == 0)
2742 {
2743 *hour += 0;
2744 err = 0;
2745 pstr += 4;
2746 }
2747 if (strncmp(pstr, "pm", 2) == 0)
2748 {
2749 *hour += 12;
2750 err = 0;
2751 pstr += 2;
2752 }
2753 if (strncmp(pstr, "p.m.", 4) == 0)
2754 {
2755 *hour += 12;
2756 err = 0;
2757 pstr += 4;
2758 }
2759 break;
2760 case 'P':
2761 err = 1;
2762 pfmt++;
2763 if (strncmp(pstr, "AM", 2) == 0)
2764 {
2765 *hour += 0;
2766 err = 0;
2767 pstr += 2;
2768 }
2769 if (strncmp(pstr, "A.M.", 4) == 0)
2770 {
2771 *hour += 0;
2772 err = 0;
2773 pstr += 4;
2774 }
2775 if (strncmp(pstr, "PM", 2) == 0)
2776 {
2777 *hour += 12;
2778 err = 0;
2779 pstr += 2;
2780 }
2781 if (strncmp(pstr, "P.M.", 4) == 0)
2782 {
2783 *hour += 12;
2784 err = 0;
2785 pstr += 4;
2786 }
2787 break;
2788 case 'r':
2789 pfmt++;
2790 tmp = pgtypes_alloc(strlen("%I:%M:%S %p") + strlen(pstr) + 1);
2791 if (!tmp)
2792 return 1;
2793 strcpy(tmp, "%I:%M:%S %p");
2794 strcat(tmp, pfmt);
2797 return err;
2798 case 'R':
2799 pfmt++;
2800 tmp = pgtypes_alloc(strlen("%H:%M") + strlen(pstr) + 1);
2801 if (!tmp)
2802 return 1;
2803 strcpy(tmp, "%H:%M");
2804 strcat(tmp, pfmt);
2807 return err;
2808 case 's':
2809 pfmt++;
2812
2813 {
2814 struct tm *tms;
2815 struct tm tmbuf;
2816 time_t et = (time_t) scan_val.luint_val;
2817
2818 tms = gmtime_r(&et, &tmbuf);
2819
2820 if (tms)
2821 {
2822 *year = tms->tm_year + 1900;
2823 *month = tms->tm_mon + 1;
2824 *day = tms->tm_mday;
2825 *hour = tms->tm_hour;
2826 *minute = tms->tm_min;
2827 *second = tms->tm_sec;
2828 }
2829 else
2830 err = 1;
2831 }
2832 break;
2833 case 'S':
2834 pfmt++;
2837 *second = scan_val.uint_val;
2838 break;
2839 case 't':
2840 pfmt++;
2841 if (*pstr == '\t')
2842 pstr++;
2843 else
2844 err = 1;
2845 break;
2846 case 'T':
2847 pfmt++;
2848 tmp = pgtypes_alloc(strlen("%H:%M:%S") + strlen(pstr) + 1);
2849 if (!tmp)
2850 return 1;
2851 strcpy(tmp, "%H:%M:%S");
2852 strcat(tmp, pfmt);
2855 return err;
2856 case 'u':
2857 pfmt++;
2860 if (scan_val.uint_val < 1 || scan_val.uint_val > 7)
2861 err = 1;
2862 break;
2863 case 'U':
2864 pfmt++;
2867 if (scan_val.uint_val > 53)
2868 err = 1;
2869 break;
2870 case 'V':
2871 pfmt++;
2874 if (scan_val.uint_val < 1 || scan_val.uint_val > 53)
2875 err = 1;
2876 break;
2877 case 'w':
2878 pfmt++;
2881 if (scan_val.uint_val > 6)
2882 err = 1;
2883 break;
2884 case 'W':
2885 pfmt++;
2888 if (scan_val.uint_val > 53)
2889 err = 1;
2890 break;
2891 case 'x':
2892 case 'X':
2893
2894 break;
2895 case 'Y':
2896 pfmt++;
2899 *year = scan_val.uint_val;
2900 break;
2901 case 'z':
2902 pfmt++;
2905 if ()
2906 {
2908 free(scan_val.str_val);
2909 }
2910 break;
2911 case 'Z':
2912 pfmt++;
2915 if ()
2916 {
2917
2918
2919
2920
2921 err = 1;
2923 {
2926 scan_val.str_val) == 0)
2927 {
2929 err = 0;
2930 break;
2931 }
2932 }
2933 free(scan_val.str_val);
2934 }
2935 break;
2936 case '+':
2937
2938 break;
2939 case '%':
2940 pfmt++;
2941 if (*pstr == '%')
2942 pstr++;
2943 else
2944 err = 1;
2945 break;
2946 default:
2947 err = 1;
2948 }
2949 }
2950 if ()
2951 {
2952 if (*second < 0)
2953 *second = 0;
2954 if (*minute < 0)
2955 *minute = 0;
2956 if (*hour < 0)
2957 *hour = 0;
2958 if (*day < 0)
2959 {
2960 err = 1;
2961 *day = 1;
2962 }
2963 if (*month < 0)
2964 {
2965 err = 1;
2966 *month = 1;
2967 }
2968 if (*year < 0)
2969 {
2970 err = 1;
2971 *year = 1970;
2972 }
2973
2974 if (*second > 59)
2975 {
2976 err = 1;
2977 *second = 0;
2978 }
2979 if (*minute > 59)
2980 {
2981 err = 1;
2982 *minute = 0;
2983 }
2984 if (*hour > 24 ||
2985 (*hour == 24 && (*minute > 0 || *second > 0)))
2986 {
2987 err = 1;
2988 *hour = 0;
2989 }
2991 {
2992 err = 1;
2993 *month = 1;
2994 }
2996 {
2998 err = 1;
2999 }
3000
3007
3009 }
3010 return err;
3011}
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
int PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d, int *year, int *month, int *day, int *hour, int *minute, int *second, int *tz)
static const datetkn datetktbl[]
static const unsigned int szdatetktbl
char * pgtypes_date_months[]
char * pgtypes_date_weekdays_short[]
static int pgtypes_defmt_scan(union un_fmt_comb *scan_val, int scan_type, char **pstr, char *pfmt)
void err(int eval, const char *fmt,...)
char * pgtypes_alloc(long size)
#define PGTYPES_TYPE_UINT
#define PGTYPES_TYPE_STRING_MALLOCED
#define PGTYPES_TYPE_UINT_LONG
int pg_strcasecmp(const char *s1, const char *s2)
References datetktbl, day_tab, days, DecodeTimezone(), DTZ, err(), free, isleap, j, un_fmt_comb::luint_val, months, MONTHS_PER_YEAR, pg_strcasecmp(), pgtypes_alloc(), pgtypes_date_months, pgtypes_date_weekdays_short, pgtypes_defmt_scan(), PGTYPES_TYPE_STRING_MALLOCED, PGTYPES_TYPE_UINT, PGTYPES_TYPE_UINT_LONG, PGTYPEStimestamp_defmt_scan(), str, un_fmt_comb::str_val, szdatetktbl, tm, tm2timestamp(), pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_year, type, TZ, un_fmt_comb::uint_val, and datetkn::value.
Referenced by PGTYPEStimestamp_defmt_asc(), and PGTYPEStimestamp_defmt_scan().
◆ tm2timestamp()
Definition at line 41 of file timestamp.c.
42{
43 int dDate;
45
46
48 return -1;
49
54 return -1;
55 if (tzp != NULL)
56 *result = dt2local(*result, -(*tzp));
57
58
60 return -1;
61
62 return 0;
63}
#define IS_VALID_JULIAN(y, m, d)
#define IS_VALID_TIMESTAMP(t)
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
static timestamp dt2local(timestamp dt, int tz)
static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec)
References date2j(), dt2local(), IS_VALID_JULIAN, IS_VALID_TIMESTAMP, pg_add_s64_overflow(), pg_mul_s64_overflow(), time2t(), tm, pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_year, unlikely, and USECS_PER_DAY.
◆ TrimTrailingZeros()
void TrimTrailingZeros | ( | char * | str | ) |
---|
◆ day_tab
◆ days
Definition at line 84 of file datetime.c.
Referenced by AdjustDays(), brin_minmax_multi_distance_interval(), date_mii(), date_pli(), DCH_from_char(), DCH_to_char(), dttofmtasc_replace(), EncodeDateTime(), interval_cmp_value(), make_interval(), PGTYPEStimestamp_defmt_scan(), and PrintTiming().
◆ months
◆ pgtypes_date_months
char* pgtypes_date_months[] | extern |
---|
◆ pgtypes_date_weekdays_short
char* pgtypes_date_weekdays_short[] | extern |
---|