PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ postgis_JsonEncodeDateTime()

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

Definition at line 644 of file lwgeom_out_geojson.c.

645 {
646  if (!buf)
647  buf = palloc(MAXDATELEN + 1);
648 
649  switch (typid)
650  {
651  case DATEOID:
652  {
653  DateADT date;
654  struct pg_tm tm;
655 
656  date = DatumGetDateADT(value);
657 
658  /* Same as date_out(), but forcing DateStyle */
659  if (DATE_NOT_FINITE(date))
660  EncodeSpecialDate(date, buf);
661  else
662  {
663  j2date(date + POSTGRES_EPOCH_JDATE,
664  &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
665  EncodeDateOnly(&tm, USE_XSD_DATES, buf);
666  }
667  }
668  break;
669  case TIMEOID:
670  {
671  TimeADT time = DatumGetTimeADT(value);
672  struct pg_tm tt,
673  *tm = &tt;
674  fsec_t fsec;
675 
676  /* Same as time_out(), but forcing DateStyle */
677  postgis_time2tm(time, tm, &fsec);
678  EncodeTimeOnly(tm, fsec, false, 0, USE_XSD_DATES, buf);
679  }
680  break;
681  case TIMETZOID:
682  {
683  TimeTzADT *time = DatumGetTimeTzADTP(value);
684  struct pg_tm tt,
685  *tm = &tt;
686  fsec_t fsec;
687  int tz;
688 
689  /* Same as timetz_out(), but forcing DateStyle */
690  postgis_timetz2tm(time, tm, &fsec, &tz);
691  EncodeTimeOnly(tm, fsec, true, tz, USE_XSD_DATES, buf);
692  }
693  break;
694  case TIMESTAMPOID:
695  {
696  Timestamp timestamp;
697  struct pg_tm tm;
698  fsec_t fsec;
699 
700  timestamp = DatumGetTimestamp(value);
701  /* Same as timestamp_out(), but forcing DateStyle */
702  if (TIMESTAMP_NOT_FINITE(timestamp))
703  EncodeSpecialTimestamp(timestamp, buf);
704  else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0)
705  EncodeDateTime(&tm, fsec, false, 0, NULL, USE_XSD_DATES, buf);
706  else
707  ereport(ERROR,
708  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
709  errmsg("timestamp out of range")));
710  }
711  break;
712  case TIMESTAMPTZOID:
713  {
714  TimestampTz timestamp;
715  struct pg_tm tm;
716  int tz;
717  fsec_t fsec;
718  const char *tzn = NULL;
719 
720  timestamp = DatumGetTimestampTz(value);
721  /* Same as timestamptz_out(), but forcing DateStyle */
722  if (TIMESTAMP_NOT_FINITE(timestamp))
723  EncodeSpecialTimestamp(timestamp, buf);
724  else if (timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL) == 0)
725  EncodeDateTime(&tm, fsec, true, tz, tzn, USE_XSD_DATES, buf);
726  else
727  ereport(ERROR,
728  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
729  errmsg("timestamp out of range")));
730  }
731  break;
732  default:
733  elog(ERROR, "unknown jsonb value datetime type oid %d", typid);
734  return NULL;
735  }
736 
737  return buf;
738 }
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)
int value
Definition: genraster.py:62

References postgis_time2tm(), postgis_timetz2tm(), and genraster::value.

Referenced by datum_to_json().

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