1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

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.
This commit is contained in:
Thomas G. Lockhart
1997-07-01 00:22:46 +00:00
parent 43deb7a45f
commit 8507ddb9c6
3 changed files with 625 additions and 33 deletions

View File

@ -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;
}