break;
case DTK_EPOCH:
- GetEpochTime(tm);
+ if (GetEpochTime(tm) < 0)
+ {
+ errno = PGTYPES_DATE_BAD_DATE;
+ return INT_MIN;
+ }
break;
default:
struct tm ts;
GetCurrentDateTime(&ts);
- *d = date2j(ts.tm_year, ts.tm_mon, ts.tm_mday) - date2j(2000, 1, 1);
+ if (errno == 0)
+ *d = date2j(ts.tm_year, ts.tm_mon, ts.tm_mday) - date2j(2000, 1, 1);
return;
}
int DecodeUnits(int field, char *lowtoken, int *val);
bool CheckDateTokenTables(void);
int EncodeDateOnly(struct tm *, int, char *, bool);
-void GetEpochTime(struct tm *);
+int GetEpochTime(struct tm *);
int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
void j2date(int, int *, int *, int *);
return TRUE;
} /* EncodeDateTime() */
-void
+int
GetEpochTime(struct tm * tm)
{
struct tm *t0;
t0 = gmtime(&epoch);
- tm->tm_year = t0->tm_year + 1900;
- tm->tm_mon = t0->tm_mon + 1;
- tm->tm_mday = t0->tm_mday;
- tm->tm_hour = t0->tm_hour;
- tm->tm_min = t0->tm_min;
- tm->tm_sec = t0->tm_sec;
+ if (t0)
+ {
+ tm->tm_year = t0->tm_year + 1900;
+ tm->tm_mon = t0->tm_mon + 1;
+ tm->tm_mday = t0->tm_mday;
+ tm->tm_hour = t0->tm_hour;
+ tm->tm_min = t0->tm_min;
+ tm->tm_sec = t0->tm_sec;
+
+ return 0;
+ }
- return;
+ return -1;
} /* GetEpochTime() */
static void
time_t time = (time_t) _time;
struct tm *tx;
+ errno = 0;
if (tzp != NULL)
tx = localtime((time_t *) &time);
else
tx = gmtime((time_t *) &time);
+ if (!tx)
+ {
+ errno = PGTYPES_TS_BAD_TIMESTAMP;
+ return;
+ }
+
tm->tm_year = tx->tm_year + 1900;
tm->tm_mon = tx->tm_mon + 1;
tm->tm_mday = tx->tm_mday;
time_t et = (time_t) scan_val.luint_val;
tms = gmtime(&et);
- *year = tms->tm_year + 1900;
- *month = tms->tm_mon + 1;
- *day = tms->tm_mday;
- *hour = tms->tm_hour;
- *minute = tms->tm_min;
- *second = tms->tm_sec;
+
+ if (tms)
+ {
+ *year = tms->tm_year + 1900;
+ *month = tms->tm_mon + 1;
+ *day = tms->tm_mday;
+ *hour = tms->tm_hour;
+ *minute = tms->tm_min;
+ *second = tms->tm_sec;
+ }
+ else
+ err = 1;
}
break;
case 'S':
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "postgres_fe.h"
static timestamp
SetEpochTimestamp(void)
{
+#ifdef HAVE_INT64_TIMESTAMP
+ int64 noresult = 0;
+#else
+ double noresult = 0.0;
+#endif
timestamp dt;
struct tm tt,
*tm = &tt;
- GetEpochTime(tm);
+ if (GetEpochTime(tm) < 0)
+ return noresult;
+
tm2timestamp(tm, 0, NULL, &dt);
return dt;
} /* SetEpochTimestamp() */
struct tm tm;
GetCurrentDateTime(&tm);
- tm2timestamp(&tm, 0, NULL, ts);
+ if (errno == 0)
+ tm2timestamp(&tm, 0, NULL, ts);
return;
}