PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ postgis_JsonEncodeDateTime()

static char * postgis_JsonEncodeDateTime ( char *  buf,
Datum  value,
Oid  typid 
)
static

Definition at line 623 of file lwgeom_out_geojson.c.

624{
625 if (!buf)
626 buf = palloc(MAXDATELEN + 1);
627
628 switch (typid)
629 {
630 case DATEOID:
631 {
632 DateADT date;
633 struct pg_tm tm;
634
635 date = DatumGetDateADT(value);
636
637 /* Same as date_out(), but forcing DateStyle */
638 if (DATE_NOT_FINITE(date))
639 EncodeSpecialDate(date, buf);
640 else
641 {
642 j2date(date + POSTGRES_EPOCH_JDATE,
643 &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
644 EncodeDateOnly(&tm, USE_XSD_DATES, buf);
645 }
646 }
647 break;
648 case TIMEOID:
649 {
650 TimeADT time = DatumGetTimeADT(value);
651 struct pg_tm tt,
652 *tm = &tt;
653 fsec_t fsec;
654
655 /* Same as time_out(), but forcing DateStyle */
656 postgis_time2tm(time, tm, &fsec);
657 EncodeTimeOnly(tm, fsec, false, 0, USE_XSD_DATES, buf);
658 }
659 break;
660 case TIMETZOID:
661 {
662 TimeTzADT *time = DatumGetTimeTzADTP(value);
663 struct pg_tm tt,
664 *tm = &tt;
665 fsec_t fsec;
666 int tz;
667
668 /* Same as timetz_out(), but forcing DateStyle */
669 postgis_timetz2tm(time, tm, &fsec, &tz);
670 EncodeTimeOnly(tm, fsec, true, tz, USE_XSD_DATES, buf);
671 }
672 break;
673 case TIMESTAMPOID:
674 {
675 Timestamp timestamp;
676 struct pg_tm tm;
677 fsec_t fsec;
678
679 timestamp = DatumGetTimestamp(value);
680 /* Same as timestamp_out(), but forcing DateStyle */
681 if (TIMESTAMP_NOT_FINITE(timestamp))
682 EncodeSpecialTimestamp(timestamp, buf);
683 else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0)
684 EncodeDateTime(&tm, fsec, false, 0, NULL, USE_XSD_DATES, buf);
685 else
686 ereport(ERROR,
687 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
688 errmsg("timestamp out of range")));
689 }
690 break;
691 case TIMESTAMPTZOID:
692 {
693 TimestampTz timestamp;
694 struct pg_tm tm;
695 int tz;
696 fsec_t fsec;
697 const char *tzn = NULL;
698
699 timestamp = DatumGetTimestampTz(value);
700 /* Same as timestamptz_out(), but forcing DateStyle */
701 if (TIMESTAMP_NOT_FINITE(timestamp))
702 EncodeSpecialTimestamp(timestamp, buf);
703 else if (timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL) == 0)
704 EncodeDateTime(&tm, fsec, true, tz, tzn, USE_XSD_DATES, buf);
705 else
706 ereport(ERROR,
707 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
708 errmsg("timestamp out of range")));
709 }
710 break;
711 default:
712 elog(ERROR, "unknown jsonb value datetime type oid %d", typid);
713 return NULL;
714 }
715
716 return buf;
717}
static int postgis_timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
static int postgis_time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)

References postgis_time2tm(), and postgis_timetz2tm().

Referenced by datum_to_json().

Here is the call graph for this function:
Here is the caller graph for this function: