summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/timestamp.c
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>1997-07-01 00:22:46 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>1997-07-01 00:22:46 +0000
commit8507ddb9c63bc341e52c82acf52770ecd423a994 (patch)
tree3547f66ed836a02a5893019afaf0b912c027e90b /src/backend/utils/adt/timestamp.c
parent43deb7a45f3861e592a9ae325fb9f5e4f290f625 (diff)
downloadpostgresql-8507ddb9c63bc341e52c82acf52770ecd423a994.tar.gz
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.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r--src/backend/utils/adt/timestamp.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index e884f7eb08..58113955e5 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -3,8 +3,10 @@
#include <time.h>
#include <ctype.h>
#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(&timestamp);
- 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;
}