1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

From: "D'Arcy J.M. Cain" <darcy@druid.net>

Subject: [HACKERS] backend/utils/adt/timestamp.c

Back to this timezone stuff.  The struct tm has a field (tm_gmtoff) which
is the offset from UTC (GMT is archaic BTW) in seconds.  Is this the
value you are looking for when you use timezone?  Note that this applies
to NetBSD but it does not appear to be in either ANSI C or POSIX.  This
looks like one of those things that is just going to have to be hand
coded for each platform.

Why not just store the values in UTC and use localtime instead of
gmtime when retrieving the value?

Also, you assume the time is returned as a 4 byte integer.  In fact,
there is not even any requirement that time be an integral value.  You
should use time_t here.

The input function seems unduly restrictive.  Somewhere in the sources
there is an input function that allows words for months.  Can't we do
the same here?

There is a standard function, difftime, for subtracting two times.  It
deals with cases where time_t is not integral.  There is, however, a
small performance hit since it returns a double and I don't believe
there is any system currently which uses anything but an integral for
time_t.  Still, this is technically the correct and portable thing to do.

The returns from the various comparisons should probably be a bool.
This commit is contained in:
Marc G. Fournier
1997-03-25 09:25:33 +00:00
parent c2e73db87a
commit 070381482f
2 changed files with 34 additions and 42 deletions

View File

@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: builtins.h,v 1.12 1997/03/14 23:33:18 scrappy Exp $
* $Id: builtins.h,v 1.13 1997/03/25 09:25:33 scrappy Exp $
*
* NOTES
* This should normally only be included by fmgr.h.
@@ -407,15 +407,15 @@ extern ItemPointer tidin(char *str);
extern char *tidout(ItemPointer itemPtr);
/* timestamp.c */
extern int4 timestamp_in(char *timestamp_str);
extern char *timestamp_out(int4 timestamp);
extern int4 now(void);
int4 timestampeq(int4 t1, int4 t2);
int4 timestampne(int4 t1, int4 t2);
int4 timestamplt(int4 t1, int4 t2);
int4 timestampgt(int4 t1, int4 t2);
int4 timestample(int4 t1, int4 t2);
int4 timestampge(int4 t1, int4 t2);
extern time_t timestamp_in(const char *timestamp_str);
extern char *timestamp_out(time_t timestamp);
extern time_t now(void);
bool timestampeq(time_t t1, time_t t2);
bool timestampne(time_t t1, time_t t2);
bool timestamplt(time_t t1, time_t t2);
bool timestampgt(time_t t1, time_t t2);
bool timestample(time_t t1, time_t t2);
bool timestampge(time_t t1, time_t t2);
/* varchar.c */
extern char *bpcharin(char *s, int dummy, int typlen);