#include "utils/typcache.h"
#include "utils/syscache.h"
-/* String to output for infinite dates and timestamps */
-#define DT_INFINITY "\"infinity\""
-
/*
* The context of the parser is maintained by the recursive descent
* mechanism, but is passed explicitly to the error reporting routine
char buf[MAXDATELEN + 1];
date = DatumGetDateADT(val);
-
+ /* Same as date_out(), but forcing DateStyle */
if (DATE_NOT_FINITE(date))
- {
- /* we have to format infinity ourselves */
- appendStringInfoString(result,DT_INFINITY);
- }
+ EncodeSpecialDate(date, buf);
else
{
j2date(date + POSTGRES_EPOCH_JDATE,
&(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
EncodeDateOnly(&tm, USE_XSD_DATES, buf);
- appendStringInfo(result, "\"%s\"", buf);
}
+ appendStringInfo(result, "\"%s\"", buf);
}
break;
case JSONTYPE_TIMESTAMP:
char buf[MAXDATELEN + 1];
timestamp = DatumGetTimestamp(val);
-
+ /* Same as timestamp_out(), but forcing DateStyle */
if (TIMESTAMP_NOT_FINITE(timestamp))
- {
- /* we have to format infinity ourselves */
- appendStringInfoString(result,DT_INFINITY);
- }
+ EncodeSpecialTimestamp(timestamp, buf);
else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0)
- {
EncodeDateTime(&tm, fsec, false, 0, NULL, USE_XSD_DATES, buf);
- appendStringInfo(result, "\"%s\"", buf);
- }
else
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
+ appendStringInfo(result, "\"%s\"", buf);
}
break;
case JSONTYPE_TIMESTAMPTZ:
const char *tzn = NULL;
char buf[MAXDATELEN + 1];
- timestamp = DatumGetTimestamp(val);
-
+ timestamp = DatumGetTimestampTz(val);
+ /* Same as timestamptz_out(), but forcing DateStyle */
if (TIMESTAMP_NOT_FINITE(timestamp))
- {
- /* we have to format infinity ourselves */
- appendStringInfoString(result,DT_INFINITY);
- }
+ EncodeSpecialTimestamp(timestamp, buf);
else if (timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL) == 0)
- {
EncodeDateTime(&tm, fsec, true, tz, tzn, USE_XSD_DATES, buf);
- appendStringInfo(result, "\"%s\"", buf);
- }
else
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
+ appendStringInfo(result, "\"%s\"", buf);
}
break;
case JSONTYPE_JSON:
extern void EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, bool print_tz, int tz, int style, char *str);
extern void EncodeDateTime(struct pg_tm * tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str);
extern void EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str);
+extern void EncodeSpecialTimestamp(Timestamp dt, char *str);
extern int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc,
struct pg_tm * tm);