diff options
| author | Christoph Berg | 2022-03-30 12:22:43 +0000 |
|---|---|---|
| committer | Christoph Berg | 2022-03-30 12:22:43 +0000 |
| commit | bdb930a415af61dac8edcd18b7f3ce863b5533dd (patch) | |
| tree | d651f3c32b2ca32c69e0db0ddaf426521d708af3 /decode.c | |
| parent | 476ddcae7c4fd619243f4d93d428eda9770f70c4 (diff) | |
Decode date and timestamp infinity values
Diffstat (limited to 'decode.c')
| -rw-r--r-- | decode.c | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -768,7 +768,8 @@ decode_date(const char *buffer, unsigned int buff_size, unsigned int *out_size) { const char *new_buffer = (const char *) INTALIGN(buffer); unsigned int delta = (unsigned int) ((uintptr_t) new_buffer - (uintptr_t) buffer); - int32 jd, + int32 d, + jd, year, month, day; @@ -784,7 +785,19 @@ decode_date(const char *buffer, unsigned int buff_size, unsigned int *out_size) *out_size = sizeof(int32) + delta; - jd = *(int32 *) buffer + POSTGRES_EPOCH_JDATE; + d = *(int32 *) buffer; + if (d == PG_INT32_MIN) + { + CopyAppend("-infinity"); + return 0; + } + if (d == PG_INT32_MAX) + { + CopyAppend("infinity"); + return 0; + } + + jd = d + POSTGRES_EPOCH_JDATE; j2date(jd, &year, &month, &day); CopyAppendFmt("%04d-%02d-%02d%s", (year <= 0) ? -year + 1 : year, month, day, (year <= 0) ? " BC" : ""); @@ -817,6 +830,17 @@ decode_timestamp(const char *buffer, unsigned int buff_size, unsigned int *out_s *out_size = sizeof(int64) + delta; timestamp = *(int64 *) buffer; + if (timestamp == DT_NOBEGIN) + { + CopyAppend("-infinity"); + return 0; + } + if (timestamp == DT_NOEND) + { + CopyAppend("infinity"); + return 0; + } + jd = timestamp / USECS_PER_DAY; if (jd != 0) timestamp -= jd * USECS_PER_DAY; |
