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

◆ postgis_JsonEncodeDateTime()

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

Definition at line 715 of file lwgeom_out_geojson.c.

716{
717 if (!buf)
718 buf = palloc(MAXDATELEN + 1);
719
720 switch (typid)
721 {
722 case DATEOID:
723 {
724 DateADT date;
725 struct pg_tm tm;
726
727 date = DatumGetDateADT(value);
728
729 /* Same as date_out(), but forcing DateStyle */
730 if (DATE_NOT_FINITE(date))
731 EncodeSpecialDate(date, buf);
732 else
733 {
734 j2date(date + POSTGRES_EPOCH_JDATE,
735 &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
736 EncodeDateOnly(&tm, USE_XSD_DATES, buf);
737 }
738 }
739 break;
740 case TIMEOID:
741 {
742 TimeADT time = DatumGetTimeADT(value);
743 struct pg_tm tt,
744 *tm = &tt;
745 fsec_t fsec;
746
747 /* Same as time_out(), but forcing DateStyle */
748 postgis_time2tm(time, tm, &fsec);
749 EncodeTimeOnly(tm, fsec, false, 0, USE_XSD_DATES, buf);
750 }
751 break;
752 case TIMETZOID:
753 {
754 TimeTzADT *time = DatumGetTimeTzADTP(value);
755 struct pg_tm tt,
756 *tm = &tt;
757 fsec_t fsec;
758 int tz;
759
760 /* Same as timetz_out(), but forcing DateStyle */
761 postgis_timetz2tm(time, tm, &fsec, &tz);
762 EncodeTimeOnly(tm, fsec, true, tz, USE_XSD_DATES, buf);
763 }
764 break;
765 case TIMESTAMPOID:
766 {
767 Timestamp timestamp;
768 struct pg_tm tm;
769 fsec_t fsec;
770
771 timestamp = DatumGetTimestamp(value);
772 /* Same as timestamp_out(), but forcing DateStyle */
773 if (TIMESTAMP_NOT_FINITE(timestamp))
774 EncodeSpecialTimestamp(timestamp, buf);
775 else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0)
776 EncodeDateTime(&tm, fsec, false, 0, NULL, USE_XSD_DATES, buf);
777 else
778 ereport(ERROR,
779 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
780 errmsg("timestamp out of range")));
781 }
782 break;
783 case TIMESTAMPTZOID:
784 {
785 TimestampTz timestamp;
786 struct pg_tm tm;
787 int tz;
788 fsec_t fsec;
789 const char *tzn = NULL;
790
791 timestamp = DatumGetTimestampTz(value);
792 /* Same as timestamptz_out(), but forcing DateStyle */
793 if (TIMESTAMP_NOT_FINITE(timestamp))
794 EncodeSpecialTimestamp(timestamp, buf);
795 else if (timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL) == 0)
796 EncodeDateTime(&tm, fsec, true, tz, tzn, USE_XSD_DATES, buf);
797 else
798 ereport(ERROR,
799 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
800 errmsg("timestamp out of range")));
801 }
802 break;
803 default:
804 elog(ERROR, "unknown jsonb value datetime type oid %d", typid);
805 return NULL;
806 }
807
808 return buf;
809}
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: