From 8507ddb9c63bc341e52c82acf52770ecd423a994 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Tue, 1 Jul 1997 00:22:46 +0000 Subject: Use common parser and encoder for timestamp data type. Remove older date and time code (retain NEW_DATE_CODE and NEW_TIME_CODE). Use common encoder for date and time. Fix datetime +/- timespan math bug. --- src/backend/utils/adt/timestamp.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/backend/utils/adt/timestamp.c') diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index e884f7eb08c..58113955e5a 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -3,8 +3,10 @@ #include #include #include "postgres.h" +#include "miscadmin.h" #include "utils/builtins.h" +#if FALSE /* copy the next part of the string into a buffer */ static const char * cpstr(const char *s, char *buf) @@ -29,13 +31,16 @@ cpstr(const char *s, char *buf) buf[in] = 0; return s; } +#endif /* assumes dd/mm/yyyy unless first item is month in word form */ time_t timestamp_in(const char *timestamp_str) { - struct tm input_time; int4 result; + +#if FALSE + struct tm input_time; char buf[18]; const char *p; static const char *mstr[] = { @@ -105,6 +110,9 @@ timestamp_in(const char *timestamp_str) /* use mktime(), but make this GMT, not local time */ result = mktime(&input_time); +#endif + + result = nabstimein( (char *) timestamp_str); return result; } @@ -113,14 +121,24 @@ char * timestamp_out(time_t timestamp) { char *result; - struct tm *time; + int tz; + double fsec = 0; + struct tm tt, *tm = &tt; + char buf[MAXDATELEN+1]; + char zone[MAXDATELEN+1], *tzn = zone; +#if FALSE time = localtime(×tamp); - result = palloc(20); + sprintf(result, "%04d-%02d-%02d %02d:%02d:%02d", time->tm_year+1900, time->tm_mon+1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec); +#endif + abstime2tm( timestamp, &tz, tm, tzn); + EncodeDateTime( tm, fsec, &tz, &tzn, USE_ISO_DATES, buf); + result = palloc(strlen(buf)+1); + strcpy( result, buf); return result; } -- cgit v1.2.3