PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ postgis_JsonEncodeDateTime()

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

Definition at line 639 of file lwgeom_out_geojson.c.

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