Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6acdebb

Browse files
author
Thomas G. Lockhart
committed
Fix up "Postgres-style" time interval representation when fields have
mixed-signs. Previous effort left way too many minus signs, and was at least as broken as the one before that :(Clean up "ISO-style" time interval representation to omit zero fields if there is at least one non-zero field. Supress some leading plus signs when not necessary for clarity.Replace every #ifdef __CYGWIN__ block with a cleaner TIMEZONE_GLOBAL macro defined in datetime.h.
1 parent6439de1 commit6acdebb

File tree

6 files changed

+146
-160
lines changed

6 files changed

+146
-160
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.58 2001/01/17 16:46:56 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.59 2001/01/18 07:22:35 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -880,11 +880,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
880880
*tzp=-(tm->tm_gmtoff);/* tm_gmtoff is
881881
* Sun/DEC-ism */
882882
# elif defined(HAVE_INT_TIMEZONE)
883-
# ifdef__CYGWIN__
884-
*tzp= ((tm->tm_isdst>0) ? (_timezone-3600) :_timezone);
885-
# else
886-
*tzp= ((tm->tm_isdst>0) ? (timezone-3600) :timezone);
887-
# endif/* __CYGWIN__ */
883+
*tzp= ((tm->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
888884
# endif/* HAVE_INT_TIMEZONE */
889885

890886
#else/* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
@@ -1128,11 +1124,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
11281124
# if defined(HAVE_TM_ZONE)
11291125
*tzp=-(tmp->tm_gmtoff);/* tm_gmtoff is Sun/DEC-ism */
11301126
# elif defined(HAVE_INT_TIMEZONE)
1131-
# ifdef__CYGWIN__
1132-
*tzp= ((tmp->tm_isdst>0) ? (_timezone-3600) :_timezone);
1133-
# else
1134-
*tzp= ((tmp->tm_isdst>0) ? (timezone-3600) :timezone);
1135-
# endif
1127+
*tzp= ((tmp->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
11361128
# endif
11371129

11381130
#else/* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
@@ -2252,12 +2244,14 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
22522244
is_before= (tm->tm_mday<0);
22532245
is_nonzero= TRUE;
22542246
}
2247+
if ((!is_nonzero)|| (tm->tm_hour!=0)|| (tm->tm_min!=0)
2248+
|| (tm->tm_sec!=0)|| (fsec!=0))
22552249
{
22562250
intminus= ((tm->tm_hour<0)|| (tm->tm_min<0)
22572251
|| (tm->tm_sec<0)|| (fsec<0));
22582252

22592253
sprintf(cp,"%s%s%02d:%02d", (is_nonzero ?" " :""),
2260-
(minus ?"-" : (is_nonzero ?"+" :"")),
2254+
(minus ?"-" : (is_before ?"+" :"")),
22612255
abs(tm->tm_hour),abs(tm->tm_min));
22622256
cp+=strlen(cp);
22632257
/* Mark as "non-zero" since the fields are now filled in */
@@ -2289,7 +2283,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
22892283

22902284
if (tm->tm_year!=0)
22912285
{
2292-
intyear= ((tm->tm_year<0) ?-(tm->tm_year) :tm->tm_year);
2286+
intyear=tm->tm_year;
2287+
if (tm->tm_year<0)
2288+
year=-year;
22932289

22942290
sprintf(cp,"%d year%s",year,
22952291
((year!=1) ?"s" :""));
@@ -2300,7 +2296,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
23002296

23012297
if (tm->tm_mon!=0)
23022298
{
2303-
intmon= ((is_before&& (tm->tm_mon>0)) ?-(tm->tm_mon) :tm->tm_mon);
2299+
intmon=tm->tm_mon;
2300+
if (is_before|| ((!is_nonzero)&& (tm->tm_mon<0)))
2301+
mon=-mon;
23042302

23052303
sprintf(cp,"%s%d mon%s", (is_nonzero ?" " :""),mon,
23062304
((mon!=1) ?"s" :""));
@@ -2312,7 +2310,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
23122310

23132311
if (tm->tm_mday!=0)
23142312
{
2315-
intday= ((is_before&& (tm->tm_mday>0)) ?-(tm->tm_mday) :tm->tm_mday);
2313+
intday=tm->tm_mday;
2314+
if (is_before|| ((!is_nonzero)&& (tm->tm_mday<0)))
2315+
day=-day;
23162316

23172317
sprintf(cp,"%s%d day%s", (is_nonzero ?" " :""),day,
23182318
((day!=1) ?"s" :""));
@@ -2323,7 +2323,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
23232323
}
23242324
if (tm->tm_hour!=0)
23252325
{
2326-
inthour= ((is_before&& (tm->tm_hour>0)) ?-(tm->tm_hour) :tm->tm_hour);
2326+
inthour=tm->tm_hour;
2327+
if (is_before|| ((!is_nonzero)&& (tm->tm_hour<0)))
2328+
hour=-hour;
23272329

23282330
sprintf(cp,"%s%d hour%s", (is_nonzero ?" " :""),hour,
23292331
((hour!=1) ?"s" :""));
@@ -2335,7 +2337,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
23352337

23362338
if (tm->tm_min!=0)
23372339
{
2338-
intmin= ((is_before&& (tm->tm_min>0)) ?-(tm->tm_min) :tm->tm_min);
2340+
intmin=tm->tm_min;
2341+
if (is_before|| ((!is_nonzero)&& (tm->tm_min<0)))
2342+
min=-min;
23392343

23402344
sprintf(cp,"%s%d min%s", (is_nonzero ?" " :""),min,
23412345
((min!=1) ?"s" :""));
@@ -2348,9 +2352,13 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
23482352
/* fractional seconds? */
23492353
if (fsec!=0)
23502354
{
2355+
doublesec;
23512356
fsec+=tm->tm_sec;
2352-
sprintf(cp,"%s%.2f secs", (is_nonzero ?" " :""),
2353-
((is_before&& (fsec>0)) ?-(fsec) :fsec));
2357+
sec=fsec;
2358+
if (is_before|| ((!is_nonzero)&& (fsec<0)))
2359+
sec=-sec;
2360+
2361+
sprintf(cp,"%s%.2f secs", (is_nonzero ?" " :""),sec);
23542362
cp+=strlen(cp);
23552363
if (!is_nonzero)
23562364
is_before= (fsec<0);
@@ -2360,7 +2368,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
23602368
}
23612369
elseif (tm->tm_sec!=0)
23622370
{
2363-
intsec= ((is_before&& (tm->tm_sec>0)) ?-(tm->tm_sec) :tm->tm_sec);
2371+
intsec=tm->tm_sec;
2372+
if (is_before|| ((!is_nonzero)&& (tm->tm_sec<0)))
2373+
sec=-sec;
23642374

23652375
sprintf(cp,"%s%d sec%s", (is_nonzero ?" " :""),sec,
23662376
((sec!=1) ?"s" :""));

‎src/backend/utils/adt/formatting.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.29 2001/01/17 16:46:56 thomas Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.30 2001/01/18 07:22:36 thomas Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
@@ -2931,13 +2931,7 @@ to_timestamp(PG_FUNCTION_ARGS)
29312931
# if defined(HAVE_TM_ZONE)
29322932
tz=-(tm->tm_gmtoff);/* tm_gmtoff is Sun/DEC-ism */
29332933
# elif defined(HAVE_INT_TIMEZONE)
2934-
2935-
# ifdef__CYGWIN__
2936-
tz= ((tm->tm_isdst>0) ? (_timezone-3600) :_timezone);
2937-
# else
2938-
tz= ((tm->tm_isdst>0) ? (timezone-3600) :timezone);
2939-
# endif
2940-
2934+
tz= ((tm->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
29412935
# endif
29422936

29432937
#else/* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */

‎src/backend/utils/adt/nabstime.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.78 2001/01/17 16:46:56 thomas Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.79 2001/01/18 07:22:36 thomas Exp $
1313
*
1414
* NOTES
1515
*
@@ -160,12 +160,7 @@ GetCurrentAbsoluteTime(void)
160160
tm=localtime(&now);
161161

162162
CDayLight=tm->tm_isdst;
163-
CTimeZone=
164-
# ifdef__CYGWIN__
165-
((tm->tm_isdst>0) ? (_timezone-3600) :_timezone);
166-
# else
167-
((tm->tm_isdst>0) ? (timezone-3600) :timezone);
168-
# endif
163+
CTimeZone= ((tm->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
169164
strcpy(CTZName,tzname[tm->tm_isdst]);
170165
#else/* neither HAVE_TM_ZONE nor HAVE_INT_TIMEZONE */
171166
CTimeZone=tb.timezone*60;
@@ -244,11 +239,8 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn)
244239
}
245240
# elif defined(HAVE_INT_TIMEZONE)
246241
if (tzp!=NULL)
247-
# ifdef__CYGWIN__
248-
*tzp= ((tm->tm_isdst>0) ? (_timezone-3600) :_timezone);
249-
# else
250-
*tzp= ((tm->tm_isdst>0) ? (timezone-3600) :timezone);
251-
# endif
242+
*tzp= ((tm->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
243+
252244
if (tzn!=NULL)
253245
{
254246

‎src/backend/utils/adt/timestamp.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.42 2001/01/17 16:46:56 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.43 2001/01/18 07:22:36 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -324,9 +324,10 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn)
324324
/* XXX HACK
325325
* Argh! My Linux box puts in a 1 second offset for dates less than 1970
326326
*but only if the seconds field was non-zero. So, don't copy the seconds
327-
*field and instead carry forward from the original -tgl 97/06/18
327+
*field and instead carry forward from the original -thomas 97/06/18
328328
* Note that GNU/Linux uses the standard freeware zic package as do
329329
*many other platforms so this may not be GNU/Linux/ix86-specific.
330+
* Still shows a problem on my up to date Linux box - thomas 2001-01-17
330331
*/
331332
tm->tm_sec=tx->tm_sec;
332333
#endif
@@ -340,11 +341,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn)
340341
if (tzn!=NULL)
341342
*tzn= (char*)tm->tm_zone;
342343
# elif defined(HAVE_INT_TIMEZONE)
343-
# ifdef__CYGWIN__
344-
*tzp= ((tm->tm_isdst>0) ? (_timezone-3600) :_timezone);
345-
# else
346-
*tzp= ((tm->tm_isdst>0) ? (timezone-3600) :timezone);
347-
# endif
344+
*tzp= ((tm->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
348345
if (tzn!=NULL)
349346
*tzn=tzname[(tm->tm_isdst>0)];
350347
# endif
@@ -1084,13 +1081,7 @@ timestamp_pl_span(PG_FUNCTION_ARGS)
10841081
# if defined(HAVE_TM_ZONE)
10851082
tz=-(tm->tm_gmtoff);/* tm_gmtoff is Sun/DEC-ism */
10861083
# elif defined(HAVE_INT_TIMEZONE)
1087-
1088-
# ifdef__CYGWIN__
1089-
tz= ((tm->tm_isdst>0) ? (_timezone-3600) :_timezone);
1090-
# else
1091-
tz= ((tm->tm_isdst>0) ? (timezone-3600) :timezone);
1092-
# endif
1093-
1084+
tz= ((tm->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
10941085
# endif
10951086

10961087
#else/* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
@@ -1733,13 +1724,7 @@ timestamp_trunc(PG_FUNCTION_ARGS)
17331724
# if defined(HAVE_TM_ZONE)
17341725
tz=-(tm->tm_gmtoff);/* tm_gmtoff is Sun/DEC-ism */
17351726
# elif defined(HAVE_INT_TIMEZONE)
1736-
1737-
# ifdef__CYGWIN__
1738-
tz= ((tm->tm_isdst>0) ? (_timezone-3600) :_timezone);
1739-
# else
1740-
tz= ((tm->tm_isdst>0) ? (timezone-3600) :timezone);
1741-
# endif
1742-
1727+
tz= ((tm->tm_isdst>0) ? (TIMEZONE_GLOBAL-3600) :TIMEZONE_GLOBAL);
17431728
# endif
17441729

17451730
#else/* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */

‎src/include/utils/datetime.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: datetime.h,v 1.15 2000/06/0822:37:58 momjian Exp $
12+
* $Id: datetime.h,v 1.16 2001/01/18 07:22:42 thomas Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -193,6 +193,11 @@ do { \
193193
t -= rint(q * u); \
194194
} while(0)
195195

196+
#ifdef__CYGWIN__
197+
#defineTIMEZONE_GLOBAL _timezone
198+
#else
199+
#defineTIMEZONE_GLOBAL timezone
200+
#endif
196201

197202
/*
198203
* Date/time validation

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp