1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Integrate src/timezone library for all platforms. There is more we can

and should do now that we control our own destiny for timezone handling,
but this commit gets the bulk of the picayune diffs in place.
Magnus Hagander and Tom Lane.
This commit is contained in:
Tom Lane
2004-05-21 05:08:06 +00:00
parent 260b513fc3
commit 63bd0db121
52 changed files with 1342 additions and 8101 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.96 2004/05/07 00:24:58 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.97 2004/05/21 05:08:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -17,13 +17,13 @@
#include <ctype.h>
#include <limits.h>
#include <time.h>
#include <float.h>
#include "access/hash.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/scansup.h"
#include "pgtime.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/nabstime.h"
@@ -38,10 +38,10 @@
#endif
static int time2tm(TimeADT time, struct tm * tm, fsec_t *fsec);
static int timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp);
static int tm2time(struct tm * tm, fsec_t fsec, TimeADT *result);
static int tm2timetz(struct tm * tm, fsec_t fsec, int tz, TimeTzADT *result);
static int time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec);
static int timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp);
static int tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result);
static int tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result);
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod);
/*****************************************************************************
@@ -58,7 +58,7 @@ date_in(PG_FUNCTION_ARGS)
char *str = PG_GETARG_CSTRING(0);
DateADT date;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tzp;
int dtype;
@@ -112,7 +112,7 @@ date_out(PG_FUNCTION_ARGS)
{
DateADT date = PG_GETARG_DATEADT(0);
char *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
@@ -293,7 +293,7 @@ static TimestampTz
date2timestamptz(DateADT dateVal)
{
TimestampTz result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
j2date(dateVal + POSTGRES_EPOCH_JDATE,
@@ -733,7 +733,7 @@ timestamp_date(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
DateADT result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -774,7 +774,7 @@ timestamptz_date(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
DateADT result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -802,7 +802,7 @@ abstime_date(PG_FUNCTION_ARGS)
{
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
DateADT result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
@@ -903,7 +903,7 @@ time_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
TimeADT result;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
int nf;
@@ -932,7 +932,7 @@ time_in(PG_FUNCTION_ARGS)
* Convert a tm structure to a time data type.
*/
static int
tm2time(struct tm * tm, fsec_t fsec, TimeADT *result)
tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
*result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
@@ -949,7 +949,7 @@ tm2time(struct tm * tm, fsec_t fsec, TimeADT *result)
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
static int
time2tm(TimeADT time, struct tm * tm, fsec_t *fsec)
time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
tm->tm_hour = (time / INT64CONST(3600000000));
@@ -977,7 +977,7 @@ time_out(PG_FUNCTION_ARGS)
{
TimeADT time = PG_GETARG_TIMEADT(0);
char *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char buf[MAXDATELEN + 1];
@@ -1338,7 +1338,7 @@ timestamp_time(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
TimeADT result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -1373,7 +1373,7 @@ timestamptz_time(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
TimeADT result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
fsec_t fsec;
@@ -1641,7 +1641,7 @@ time_part(PG_FUNCTION_ARGS)
if (type == UNITS)
{
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
time2tm(time, tm, &fsec);
@@ -1731,7 +1731,7 @@ time_part(PG_FUNCTION_ARGS)
* Convert a tm structure to a time data type.
*/
static int
tm2timetz(struct tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
result->time = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
@@ -1755,7 +1755,7 @@ timetz_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
TimeTzADT *result;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
int nf;
@@ -1786,7 +1786,7 @@ timetz_out(PG_FUNCTION_ARGS)
{
TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
char *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -1844,7 +1844,7 @@ timetz_send(PG_FUNCTION_ARGS)
* Convert TIME WITH TIME ZONE data type to POSIX time structure.
*/
static int
timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp)
timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 trem = time->time;
@@ -2237,7 +2237,7 @@ time_timetz(PG_FUNCTION_ARGS)
{
TimeADT time = PG_GETARG_TIMEADT(0);
TimeTzADT *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -2263,7 +2263,7 @@ timestamptz_timetz(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
TimeTzADT *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
fsec_t fsec;
@@ -2394,7 +2394,7 @@ timetz_part(PG_FUNCTION_ARGS)
double dummy;
int tz;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
timetz2tm(time, tm, &fsec, &tz);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.127 2004/05/07 00:24:58 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.128 2004/05/21 05:08:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,15 +27,16 @@
static int DecodeNumber(int flen, char *field, bool haveTextMonth,
int fmask, int *tmask,
struct tm * tm, fsec_t *fsec, int *is2digits);
struct pg_tm * tm, fsec_t *fsec, int *is2digits);
static int DecodeNumberField(int len, char *str,
int fmask, int *tmask,
struct tm * tm, fsec_t *fsec, int *is2digits);
struct pg_tm * tm, fsec_t *fsec, int *is2digits);
static int DecodeTime(char *str, int fmask, int *tmask,
struct tm * tm, fsec_t *fsec);
struct pg_tm * tm, fsec_t *fsec);
static int DecodeTimezone(char *str, int *tzp);
static int DecodePosixTimezone(char *str, int *tzp);
static datetkn *datebsearch(char *key, datetkn *base, unsigned int nel);
static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm);
static int DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm);
static void TrimTrailingZeros(char *str);
@@ -913,7 +914,7 @@ ParseDateTime(const char *timestr, char *lowstr,
*/
int
DecodeDateTime(char **field, int *ftype, int nf,
int *dtype, struct tm * tm, fsec_t *fsec, int *tzp)
int *dtype, struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
int fmask = 0,
tmask,
@@ -1566,9 +1567,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
/* DetermineLocalTimeZone()
*
* Given a struct tm in which tm_year, tm_mon, tm_mday, tm_hour, tm_min, and
* Given a struct pg_tm in which tm_year, tm_mon, tm_mday, tm_hour, tm_min, and
* tm_sec fields are set, attempt to determine the applicable local zone
* (ie, regular or daylight-savings time) at that time. Set the struct tm's
* (ie, regular or daylight-savings time) at that time. Set the struct pg_tm's
* tm_isdst field accordingly, and return the actual timezone offset.
*
* Note: this subroutine exists because mktime() has such a spectacular
@@ -1577,7 +1578,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
* mktime() anywhere else.
*/
int
DetermineLocalTimeZone(struct tm * tm)
DetermineLocalTimeZone(struct pg_tm * tm)
{
int tz;
@@ -1600,7 +1601,7 @@ DetermineLocalTimeZone(struct tm * tm)
delta1,
delta2;
time_t mytime;
struct tm *tx;
struct pg_tm *tx;
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - UNIX_EPOCH_JDATE;
mysec = tm->tm_sec + (tm->tm_min + (day * 24 + tm->tm_hour) * 60) * 60;
@@ -1610,7 +1611,7 @@ DetermineLocalTimeZone(struct tm * tm)
* Use localtime to convert that time_t to broken-down time,
* and reassemble to get a representation of local time.
*/
tx = localtime(&mytime);
tx = pg_localtime(&mytime);
if (!tx)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1624,7 +1625,6 @@ DetermineLocalTimeZone(struct tm * tm)
* computable as mysec - locsec.
*/
delta1 = mysec - locsec;
/*
* However, if that GMT time and the local time we are
* actually interested in are on opposite sides of a
@@ -1635,7 +1635,7 @@ DetermineLocalTimeZone(struct tm * tm)
*/
mysec += delta1;
mytime = (time_t) mysec;
tx = localtime(&mytime);
tx = pg_localtime(&mytime);
if (!tx)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1660,7 +1660,7 @@ DetermineLocalTimeZone(struct tm * tm)
{
mysec += (delta2 - delta1);
mytime = (time_t) mysec;
tx = localtime(&mytime);
tx = pg_localtime(&mytime);
if (!tx)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1698,7 +1698,7 @@ DetermineLocalTimeZone(struct tm * tm)
*/
int
DecodeTimeOnly(char **field, int *ftype, int nf,
int *dtype, struct tm * tm, fsec_t *fsec, int *tzp)
int *dtype, struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
int fmask = 0,
tmask,
@@ -2201,7 +2201,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
/* timezone not specified? then find local timezone if possible */
if ((tzp != NULL) && (!(fmask & DTK_M(TZ))))
{
struct tm tt,
struct pg_tm tt,
*tmp = &tt;
/*
@@ -2236,7 +2236,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
* Insist on a complete set of fields.
*/
static int
DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm)
{
fsec_t fsec;
int nf = 0;
@@ -2394,7 +2394,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
* can be used to represent time spans.
*/
static int
DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec)
{
char *cp;
@@ -2461,7 +2461,7 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
*/
static int
DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits)
int *tmask, struct pg_tm * tm, fsec_t *fsec, int *is2digits)
{
int val;
char *cp;
@@ -2651,7 +2651,7 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
*/
static int
DecodeNumberField(int len, char *str, int fmask,
int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits)
int *tmask, struct pg_tm * tm, fsec_t *fsec, int *is2digits)
{
char *cp;
@@ -2797,10 +2797,8 @@ DecodeTimezone(char *str, int *tzp)
* - thomas 2000-03-15
*
* Return 0 if okay (and set *tzp), a DTERR code if not okay.
*
* NB: this must *not* ereport on failure; see commands/variable.c.
*/
int
static int
DecodePosixTimezone(char *str, int *tzp)
{
int val,
@@ -2911,7 +2909,7 @@ DecodeSpecial(int field, char *lowtoken, int *val)
* preceding an hh:mm:ss field. - thomas 1998-04-30
*/
int
DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fsec_t *fsec)
DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, fsec_t *fsec)
{
int is_before = FALSE;
char *cp;
@@ -3365,7 +3363,7 @@ datebsearch(char *key, datetkn *base, unsigned int nel)
* Encode date as local time.
*/
int
EncodeDateOnly(struct tm * tm, int style, char *str)
EncodeDateOnly(struct pg_tm * tm, int style, char *str)
{
if ((tm->tm_mon < 1) || (tm->tm_mon > 12))
return -1;
@@ -3425,7 +3423,7 @@ EncodeDateOnly(struct tm * tm, int style, char *str)
* Encode time fields only.
*/
int
EncodeTimeOnly(struct tm * tm, fsec_t fsec, int *tzp, int style, char *str)
EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
{
if ((tm->tm_hour < 0) || (tm->tm_hour > 24))
return -1;
@@ -3478,7 +3476,7 @@ EncodeTimeOnly(struct tm * tm, fsec_t fsec, int *tzp, int style, char *str)
* European - dd/mm/yyyy
*/
int
EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str)
EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str)
{
int day,
hour,
@@ -3709,7 +3707,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
* - thomas 1998-04-30
*/
int
EncodeInterval(struct tm * tm, fsec_t fsec, int style, char *str)
EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
int is_before = FALSE;
int is_nonzero = FALSE;

View File

@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* formatting.c
*
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.74 2004/05/07 00:24:58 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.75 2004/05/21 05:08:02 tgl Exp $
*
*
* Portions Copyright (c) 1999-2003, PostgreSQL Global Development Group
@@ -70,7 +70,6 @@
#include "postgres.h"
#include <ctype.h>
#include <sys/time.h>
#include <unistd.h>
#include <math.h>
#include <float.h>
@@ -410,7 +409,7 @@ typedef struct
*/
typedef struct TmToChar
{
struct tm tm; /* classic 'tm' struct */
struct pg_tm tm; /* classic 'tm' struct */
fsec_t fsec; /* fractional seconds */
char *tzn; /* timezone */
} TmToChar;
@@ -897,7 +896,7 @@ static int dch_global(int arg, char *inout, int suf, int flag, FormatNode *node,
static int dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data);
static int dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data);
static void do_to_timestamp(text *date_txt, text *fmt,
struct tm *tm, fsec_t *fsec);
struct pg_tm *tm, fsec_t *fsec);
static char *fill_str(char *str, int c, int max);
static FormatNode *NUM_cache(int len, NUMDesc *Num, char *pars_str, bool *shouldFree);
static char *int_to_roman(int number);
@@ -1695,7 +1694,7 @@ static int
dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
{
char *p_inout = inout;
struct tm *tm = NULL;
struct pg_tm *tm = NULL;
TmFromChar *tmfc = NULL;
TmToChar *tmtc = NULL;
@@ -2057,7 +2056,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
*p_inout;
int i,
len;
struct tm *tm = NULL;
struct pg_tm *tm = NULL;
TmFromChar *tmfc = NULL;
TmToChar *tmtc = NULL;
@@ -2768,7 +2767,7 @@ static text *
datetime_to_char_body(TmToChar *tmtc, text *fmt)
{
FormatNode *format;
struct tm *tm = NULL;
struct pg_tm *tm = NULL;
char *fmt_str,
*result;
bool incache;
@@ -2962,7 +2961,7 @@ to_timestamp(PG_FUNCTION_ARGS)
text *fmt = PG_GETARG_TEXT_P(1);
Timestamp result;
int tz;
struct tm tm;
struct pg_tm tm;
fsec_t fsec;
do_to_timestamp(date_txt, fmt, &tm, &fsec);
@@ -2988,7 +2987,7 @@ to_date(PG_FUNCTION_ARGS)
text *date_txt = PG_GETARG_TEXT_P(0);
text *fmt = PG_GETARG_TEXT_P(1);
DateADT result;
struct tm tm;
struct pg_tm tm;
fsec_t fsec;
do_to_timestamp(date_txt, fmt, &tm, &fsec);
@@ -3001,12 +3000,12 @@ to_date(PG_FUNCTION_ARGS)
/*
* do_to_timestamp: shared code for to_timestamp and to_date
*
* Parse the 'date_txt' according to 'fmt', return results as a struct tm
* Parse the 'date_txt' according to 'fmt', return results as a struct pg_tm
* and fractional seconds.
*/
static void
do_to_timestamp(text *date_txt, text *fmt,
struct tm *tm, fsec_t *fsec)
struct pg_tm *tm, fsec_t *fsec)
{
FormatNode *format;
TmFromChar tmfc;

View File

@@ -8,14 +8,13 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.32 2003/11/29 19:51:58 pgsql Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.33 2004/05/21 05:08:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <sys/file.h>
#include <time.h>
#include "commands/dbcommands.h"
#include "miscadmin.h"

View File

@@ -10,21 +10,20 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.120 2004/05/05 17:28:46 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.121 2004/05/21 05:08:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
#include <float.h>
#include <limits.h>
#include "access/xact.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "pgtime.h"
#include "utils/builtins.h"
@@ -76,8 +75,8 @@
* Function prototypes -- internal to this file only
*/
static AbsoluteTime tm2abstime(struct tm * tm, int tz);
static void reltime2tm(RelativeTime time, struct tm * tm);
static AbsoluteTime tm2abstime(struct pg_tm * tm, int tz);
static void reltime2tm(RelativeTime time, struct pg_tm * tm);
static int istinterval(char *i_string,
AbsoluteTime *i_start,
AbsoluteTime *i_end);
@@ -142,10 +141,10 @@ AbsoluteTimeUsecToTimestampTz(AbsoluteTime sec, int usec)
/*
* GetCurrentDateTime()
*
* Get the transaction start time ("now()") broken down as a struct tm.
* Get the transaction start time ("now()") broken down as a struct pg_tm.
*/
void
GetCurrentDateTime(struct tm * tm)
GetCurrentDateTime(struct pg_tm * tm)
{
int tz;
@@ -155,11 +154,11 @@ GetCurrentDateTime(struct tm * tm)
/*
* GetCurrentTimeUsec()
*
* Get the transaction start time ("now()") broken down as a struct tm,
* Get the transaction start time ("now()") broken down as a struct pg_tm,
* including fractional seconds and timezone offset.
*/
void
GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
GetCurrentTimeUsec(struct pg_tm * tm, fsec_t *fsec, int *tzp)
{
int tz;
int usec;
@@ -177,10 +176,10 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
void
abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
{
time_t time = (time_t) _time;
struct tm *tx;
struct pg_tm *tx;
/*
* If HasCTZSet is true then we have a brute force time zone
@@ -191,9 +190,9 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
time -= CTimeZone;
if ((!HasCTZSet) && (tzp != NULL))
tx = localtime(&time);
tx = pg_localtime(&time);
else
tx = gmtime(&time);
tx = pg_gmtime(&time);
tm->tm_year = tx->tm_year + 1900;
tm->tm_mon = tx->tm_mon + 1;
@@ -203,7 +202,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
tm->tm_sec = tx->tm_sec;
tm->tm_isdst = tx->tm_isdst;
#if defined(HAVE_TM_ZONE)
tm->tm_gmtoff = tx->tm_gmtoff;
tm->tm_zone = tx->tm_zone;
@@ -248,66 +246,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
}
else
tm->tm_isdst = -1;
#elif defined(HAVE_INT_TIMEZONE)
if (tzp != NULL)
{
/*
* We have a brute force time zone per SQL99? Then use it without
* change since we have already rotated to the time zone.
*/
if (HasCTZSet)
{
*tzp = CTimeZone;
tm->tm_isdst = 0;
if (tzn != NULL)
*tzn = NULL;
}
else
{
*tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
if (tzn != NULL)
{
/*
* Copy no more than MAXTZLEN bytes of timezone to tzn, in
* case it contains an error message, which doesn't fit in
* the buffer
*/
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
ereport(WARNING,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid time zone name: \"%s\"",
tzname[tm->tm_isdst])));
}
}
}
else
tm->tm_isdst = -1;
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
if (tzp != NULL)
{
/*
* We have a brute force time zone per SQL99? Then use it without
* change since we have already rotated to the time zone.
*/
if (HasCTZSet)
{
*tzp = CTimeZone;
if (tzn != NULL)
*tzn = NULL;
}
else
{
/* default to UTC */
*tzp = 0;
if (tzn != NULL)
*tzn = NULL;
}
}
else
tm->tm_isdst = -1;
#endif
}
@@ -316,7 +254,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
* Note that tm has full year (not 1900-based) and 1-based month.
*/
static AbsoluteTime
tm2abstime(struct tm * tm, int tz)
tm2abstime(struct pg_tm * tm, int tz)
{
int day;
AbsoluteTime sec;
@@ -362,7 +300,7 @@ abstimein(PG_FUNCTION_ARGS)
AbsoluteTime result;
fsec_t fsec;
int tz = 0;
struct tm date,
struct pg_tm date,
*tm = &date;
int dterr;
char *field[MAXDATEFIELDS];
@@ -428,7 +366,7 @@ abstimeout(PG_FUNCTION_ARGS)
char *result;
int tz;
double fsec = 0;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
char zone[MAXDATELEN + 1],
@@ -611,7 +549,7 @@ timestamp_abstime(PG_FUNCTION_ARGS)
AbsoluteTime result;
fsec_t fsec;
int tz;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_IS_NOBEGIN(timestamp))
@@ -642,7 +580,7 @@ abstime_timestamp(PG_FUNCTION_ARGS)
{
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
Timestamp result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
char zone[MAXDATELEN + 1],
@@ -687,7 +625,7 @@ timestamptz_abstime(PG_FUNCTION_ARGS)
TimestampTz timestamp = PG_GETARG_TIMESTAMP(0);
AbsoluteTime result;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_IS_NOBEGIN(timestamp))
@@ -715,7 +653,7 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
{
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
TimestampTz result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
char zone[MAXDATELEN + 1],
@@ -763,7 +701,7 @@ reltimein(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
RelativeTime result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int dtype;
@@ -811,7 +749,7 @@ reltimeout(PG_FUNCTION_ARGS)
{
RelativeTime time = PG_GETARG_RELATIVETIME(0);
char *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
@@ -849,7 +787,7 @@ reltimesend(PG_FUNCTION_ARGS)
static void
reltime2tm(RelativeTime time, struct tm * tm)
reltime2tm(RelativeTime time, struct pg_tm * tm)
{
double dtime = time;
@@ -1732,8 +1670,8 @@ timeofday(PG_FUNCTION_ARGS)
gettimeofday(&tp, &tpz);
tt = (time_t) tp.tv_sec;
strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
localtime(&tt));
pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
pg_localtime(&tt));
snprintf(buf, sizeof(buf), templ, tp.tv_usec);
len = VARHDRSZ + strlen(buf);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.105 2004/05/07 00:24:58 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.106 2004/05/21 05:08:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -70,7 +70,7 @@ timestamp_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
Timestamp result;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
int dtype;
@@ -137,7 +137,7 @@ timestamp_out(PG_FUNCTION_ARGS)
{
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
char *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char *tzn = NULL;
@@ -296,7 +296,7 @@ timestamptz_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
TimestampTz result;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int tz;
int dtype;
@@ -364,7 +364,7 @@ timestamptz_out(PG_FUNCTION_ARGS)
TimestampTz dt = PG_GETARG_TIMESTAMPTZ(0);
char *result;
int tz;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char *tzn;
@@ -456,7 +456,7 @@ interval_in(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
Interval *result;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
int dtype;
int nf;
@@ -520,7 +520,7 @@ interval_out(PG_FUNCTION_ARGS)
{
Interval *span = PG_GETARG_INTERVAL_P(0);
char *result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char buf[MAXDATELEN + 1];
@@ -933,23 +933,19 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
int
timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn)
{
#ifdef HAVE_INT64_TIMESTAMP
int date,
date0;
int64 time;
#else
double date,
date0;
double time;
#endif
time_t utime;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
struct tm *tx;
#endif
struct pg_tm *tx;
date0 = POSTGRES_EPOCH_JDATE;
@@ -1006,10 +1002,8 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
{
*tzp = CTimeZone;
tm->tm_isdst = 0;
#if defined(HAVE_TM_ZONE)
tm->tm_gmtoff = CTimeZone;
tm->tm_zone = NULL;
#endif
if (tzn != NULL)
*tzn = NULL;
}
@@ -1027,46 +1021,20 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
utime = (dt + ((date0 - UNIX_EPOCH_JDATE) * 86400));
#endif
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
tx = localtime(&utime);
tx = pg_localtime(&utime);
tm->tm_year = tx->tm_year + 1900;
tm->tm_mon = tx->tm_mon + 1;
tm->tm_mday = tx->tm_mday;
tm->tm_hour = tx->tm_hour;
tm->tm_min = tx->tm_min;
#if NOT_USED
/* XXX HACK
* Argh! My Linux box puts in a 1 second offset for dates less than 1970
* but only if the seconds field was non-zero. So, don't copy the seconds
* field and instead carry forward from the original - thomas 97/06/18
* Note that Linux uses the standard freeware zic package as do
* many other platforms so this may not be Linux/ix86-specific.
* Still shows a problem on my up to date Linux box - thomas 2001-01-17
*/
tm->tm_sec = tx->tm_sec;
#endif
tm->tm_isdst = tx->tm_isdst;
#if defined(HAVE_TM_ZONE)
tm->tm_gmtoff = tx->tm_gmtoff;
tm->tm_zone = tx->tm_zone;
*tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
*tzp = -(tm->tm_gmtoff);
if (tzn != NULL)
*tzn = (char *) tm->tm_zone;
#elif defined(HAVE_INT_TIMEZONE)
*tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
if (tzn != NULL)
*tzn = tzname[(tm->tm_isdst > 0)];
#endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
*tzp = 0;
/* Mark this as *no* time zone available */
tm->tm_isdst = -1;
if (tzn != NULL)
*tzn = NULL;
#endif
}
else
{
@@ -1096,12 +1064,11 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
* Returns -1 on failure (value out of range).
*/
int
tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
{
#ifdef HAVE_INT64_TIMESTAMP
int date;
int64 time;
#else
double date,
time;
@@ -1135,11 +1102,10 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
* Convert a interval data type to a tm structure.
*/
int
interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
interval2tm(Interval span, struct pg_tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 time;
#else
double time;
#endif
@@ -1179,7 +1145,7 @@ interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
}
int
tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
{
span->month = ((tm->tm_year * 12) + tm->tm_mon);
#ifdef HAVE_INT64_TIMESTAMP
@@ -1251,12 +1217,12 @@ interval_finite(PG_FUNCTION_ARGS)
*---------------------------------------------------------*/
void
GetEpochTime(struct tm * tm)
GetEpochTime(struct pg_tm * tm)
{
struct tm *t0;
struct pg_tm *t0;
time_t epoch = 0;
t0 = gmtime(&epoch);
t0 = pg_gmtime(&epoch);
tm->tm_year = t0->tm_year;
tm->tm_mon = t0->tm_mon;
@@ -1276,7 +1242,7 @@ Timestamp
SetEpochTimestamp(void)
{
Timestamp dt;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
GetEpochTime(tm);
@@ -1896,7 +1862,7 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
{
if (span->month != 0)
{
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -1974,7 +1940,7 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
{
if (span->month != 0)
{
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
@@ -2296,11 +2262,11 @@ timestamp_age(PG_FUNCTION_ARGS)
fsec_t fsec,
fsec1,
fsec2;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
struct tm tt1,
struct pg_tm tt1,
*tm1 = &tt1;
struct tm tt2,
struct pg_tm tt2,
*tm2 = &tt2;
result = (Interval *) palloc(sizeof(Interval));
@@ -2407,11 +2373,11 @@ timestamptz_age(PG_FUNCTION_ARGS)
fsec_t fsec,
fsec1,
fsec2;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
struct tm tt1,
struct pg_tm tt1,
*tm1 = &tt1;
struct tm tt2,
struct pg_tm tt2,
*tm2 = &tt2;
result = (Interval *) palloc(sizeof(Interval));
@@ -2702,7 +2668,7 @@ timestamp_trunc(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -2806,7 +2772,7 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
char *lowunits;
fsec_t fsec;
char *tzn;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -2909,7 +2875,7 @@ interval_trunc(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
result = (Interval *) palloc(sizeof(Interval));
@@ -3142,7 +3108,7 @@ timestamp_part(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -3355,7 +3321,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
double dummy;
fsec_t fsec;
char *tzn;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
if (TIMESTAMP_NOT_FINITE(timestamp))
@@ -3544,7 +3510,7 @@ interval_part(PG_FUNCTION_ARGS)
val;
char *lowunits;
fsec_t fsec;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
lowunits = downcase_truncate_identifier(VARDATA(units),
@@ -3755,7 +3721,7 @@ static TimestampTz
timestamp2timestamptz(Timestamp timestamp)
{
TimestampTz result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
@@ -3788,7 +3754,7 @@ timestamptz_timestamp(PG_FUNCTION_ARGS)
{
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0);
Timestamp result;
struct tm tt,
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
char *tzn;