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

◆ postgis_JsonEncodeDateTime()

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

Definition at line 678 of file lwgeom_out_geojson.c.

679{
680 if (!buf)
681 buf = palloc(MAXDATELEN + 1);
682
683 switch (typid)
684 {
685 case DATEOID:
686 {
687 DateADT date;
688 struct pg_tm tm;
689
690 date = DatumGetDateADT(value);
691
692 /* Same as date_out(), but forcing DateStyle */
693 if (DATE_NOT_FINITE(date))
694 EncodeSpecialDate(date, buf);
695 else
696 {
697 j2date(date + POSTGRES_EPOCH_JDATE,
698 &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
699 EncodeDateOnly(&tm, USE_XSD_DATES, buf);
700 }
701 }
702 break;
703 case TIMEOID:
704 {
705 TimeADT time = DatumGetTimeADT(value);
706 struct pg_tm tt,
707 *tm = &tt;
708 fsec_t fsec;
709
710 /* Same as time_out(), but forcing DateStyle */
711 postgis_time2tm(time, tm, &fsec);
712 EncodeTimeOnly(tm, fsec, false, 0, USE_XSD_DATES, buf);
713 }
714 break;
715 case TIMETZOID:
716 {
717 TimeTzADT *time = DatumGetTimeTzADTP(value);
718 struct pg_tm tt,
719 *tm = &tt;
720 fsec_t fsec;
721 int tz;
722
723 /* Same as timetz_out(), but forcing DateStyle */
724 postgis_timetz2tm(time, tm, &fsec, &tz);
725 EncodeTimeOnly(tm, fsec, true, tz, USE_XSD_DATES, buf);
726 }
727 break;
728 case TIMESTAMPOID:
729 {
730 Timestamp timestamp;
731 struct pg_tm tm;
732 fsec_t fsec;
733
734 timestamp = DatumGetTimestamp(value);
735 /* Same as timestamp_out(), but forcing DateStyle */
736 if (TIMESTAMP_NOT_FINITE(timestamp))
737 EncodeSpecialTimestamp(timestamp, buf);
738 else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0)
739 EncodeDateTime(&tm, fsec, false, 0, NULL, USE_XSD_DATES, buf);
740 else
741 ereport(ERROR,
742 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
743 errmsg("timestamp out of range")));
744 }
745 break;
746 case TIMESTAMPTZOID:
747 {
748 TimestampTz timestamp;
749 struct pg_tm tm;
750 int tz;
751 fsec_t fsec;
752 const char *tzn = NULL;
753
754 timestamp = DatumGetTimestampTz(value);
755 /* Same as timestamptz_out(), but forcing DateStyle */
756 if (TIMESTAMP_NOT_FINITE(timestamp))
757 EncodeSpecialTimestamp(timestamp, buf);
758 else if (timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL) == 0)
759 EncodeDateTime(&tm, fsec, true, tz, tzn, USE_XSD_DATES, buf);
760 else
761 ereport(ERROR,
762 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
763 errmsg("timestamp out of range")));
764 }
765 break;
766 default:
767 elog(ERROR, "unknown jsonb value datetime type oid %d", typid);
768 return NULL;
769 }
770
771 return buf;
772}
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: