summaryrefslogtreecommitdiff
path: root/decode.c
diff options
context:
space:
mode:
authorChristoph Berg2022-03-30 12:22:43 +0000
committerChristoph Berg2022-03-30 12:22:43 +0000
commitbdb930a415af61dac8edcd18b7f3ce863b5533dd (patch)
treed651f3c32b2ca32c69e0db0ddaf426521d708af3 /decode.c
parent476ddcae7c4fd619243f4d93d428eda9770f70c4 (diff)
Decode date and timestamp infinity values
Diffstat (limited to 'decode.c')
-rw-r--r--decode.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/decode.c b/decode.c
index 5785aae..534b301 100644
--- a/decode.c
+++ b/decode.c
@@ -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;