Commit 8507ddb9 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

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.
parent 43deb7a4
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.9 1997/06/23 14:47:26 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.10 1997/07/01 00:22:40 thomas Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -114,15 +114,24 @@ char *
date_out(DateADT date)
{
char *result;
struct tm tt, *tm = &tt;
char buf[MAXDATELEN+1];
#if FALSE
int year, month, day;
#endif
j2date( (date + date2j(2000,1,1)), &year, &month, &day);
j2date( (date + date2j(2000,1,1)),
&(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
EncodeDateOnly( tm, DateStyle, buf);
#if FALSE
if (EuroDates == 1) /* Output European-format dates */
sprintf(buf, "%02d-%02d-%04d", day, month, year);
else
sprintf(buf, "%02d-%02d-%04d", month, day, year);
#endif
result = PALLOC(strlen(buf)+1);
......@@ -445,19 +454,25 @@ char *
time_out(TimeADT *time)
{
char *result;
struct tm tt, *tm = &tt;
#if FALSE
int hour, min, sec;
#endif
double fsec;
char buf[32];
char buf[MAXDATELEN+1];
if (!PointerIsValid(time))
return NULL;
hour = (*time / (60*60));
min = (((int) (*time / 60)) % 60);
sec = (((int) *time) % 60);
tm->tm_hour = (*time / (60*60));
tm->tm_min = (((int) (*time / 60)) % 60);
tm->tm_sec = (((int) *time) % 60);
fsec = 0;
EncodeTimeOnly( tm, fsec, DateStyle, buf);
#if FALSE
if (sec == 0.0) {
sprintf(buf, "%02d:%02d", hour, min);
......@@ -468,6 +483,7 @@ time_out(TimeADT *time)
sprintf(buf, "%02d:%02d:%05.2f", hour, min, (sec+fsec));
};
};
#endif
result = PALLOC(strlen(buf)+1);
......
This diff is collapsed.
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment