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

Commit43b6f1e

Browse files
author
Thomas G. Lockhart
committed
Clean up support for USE_POSIX_TIME, ! HAVE_INT_TIMEZONE machines.
Remove references to modf() which is buggy on some platforms (Sparc/Linux).
1 parent07f0647 commit43b6f1e

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.6 1997/05/16 07:19:50 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.7 1997/05/30 15:02:48 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -392,9 +392,11 @@ date2tm(DateADT dateVal, int *tzp, struct tm *tm, double *fsec, char **tzn)
392392
tx=localtime(&utime);
393393

394394
#ifdefDATEDEBUG
395+
#ifdefHAVE_INT_TIMEZONE
395396
printf("date2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
396397
tx->tm_year,tx->tm_mon,tx->tm_mday,tx->tm_hour,tx->tm_min,sec,
397398
tzname[0],tzname[1],tx->tm_isdst);
399+
#endif
398400
#endif
399401
tm->tm_year=tx->tm_year+1900;
400402
tm->tm_mon=tx->tm_mon+1;
@@ -411,6 +413,9 @@ printf( "date2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
411413
if (tzn!=NULL)*tzn=tzname[(tm->tm_isdst>0)];
412414

413415
#else/* !HAVE_INT_TIMEZONE */
416+
tm->tm_gmtoff=tx->tm_gmtoff;
417+
tm->tm_zone=tx->tm_zone;
418+
414419
*tzp= (tm->tm_isdst? (tm->tm_gmtoff-3600):tm->tm_gmtoff);/* tm_gmtoff is Sun/DEC-ism */
415420
if (tzn!=NULL)*tzn=tm->tm_zone;
416421
#endif

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

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.22 1997/05/23 05:24:47 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.23 1997/05/30 15:02:51 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -44,6 +44,12 @@ char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
4444
char*days[]= {"Sunday","Monday","Tuesday","Wednesday",
4545
"Thursday","Friday","Saturday",NULL};
4646

47+
/* TMODULO()
48+
* Macro to replace modf(), which is broken on some platforms.
49+
*/
50+
#defineTMODULO(t,q,u) {q = ((t < 0)? ceil(t / u): floor(t / u)); \
51+
if (q != 0) t -= rint(q * u);}
52+
4753

4854
/*****************************************************************************
4955
* USER I/O ROUTINES *
@@ -1556,6 +1562,9 @@ int j2day( int date)
15561562
* Returns:
15571563
* 0 on success
15581564
* -1 on out of range
1565+
*
1566+
* For dates within the system-supported time_t range, convert to the
1567+
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
15591568
*/
15601569
int
15611570
datetime2tm(DateTimedt,int*tzp,structtm*tm,double*fsec,char**tzn)
@@ -1568,7 +1577,9 @@ datetime2tm( DateTime dt, int *tzp, struct tm *tm, double *fsec, char **tzn)
15681577

15691578

15701579
date0=date2j(2000,1,1);
1571-
time= (modf(dt/86400,&date)*86400);
1580+
1581+
time=dt;
1582+
TMODULO(time,date,86400e0);
15721583

15731584
if (time<0) {
15741585
time+=86400;
@@ -1594,24 +1605,30 @@ printf( "datetime2tm- date is %d.%02d.%02d\n", tm->tm_year, tm->tm_mon, tm->tm_m
15941605
printf("datetime2tm- time is %02d:%02d:%02.0f\n",tm->tm_hour,tm->tm_min,sec);
15951606
#endif
15961607

1597-
*fsec=modf(JROUND(sec),&sec);
1598-
tm->tm_sec=sec;
1608+
*fsec=JROUND(sec);
1609+
TMODULO(*fsec,tm->tm_sec,1);
15991610

16001611
#ifdefDATEDEBUG
16011612
printf("datetime2tm- time is %02d:%02d:%02d %.7f\n",tm->tm_hour,tm->tm_min,tm->tm_sec,*fsec);
16021613
#endif
16031614

16041615
if (tzp!=NULL) {
1605-
/* XXX HACK to get time behavior compatible with Postgres v6.0 - tgl 97/04/07 */
16061616
if (IS_VALID_UTIME(tm->tm_year,tm->tm_mon,tm->tm_mday)) {
16071617
utime= (dt+ (date0-date2j(1970,1,1))*86400);
16081618

16091619
#ifdefUSE_POSIX_TIME
16101620
tx=localtime(&utime);
16111621
#ifdefDATEDEBUG
1622+
#ifdefHAVE_INT_TIMEZONE
16121623
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
16131624
tx->tm_year,tx->tm_mon,tx->tm_mday,tx->tm_hour,tx->tm_min,sec,
16141625
tzname[0],tzname[1],tx->tm_isdst);
1626+
#else
1627+
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s dst=%d\n",
1628+
tx->tm_year,tx->tm_mon,tx->tm_mday,tx->tm_hour,tx->tm_min,sec,
1629+
tx->tm_zone,tx->tm_isdst);
1630+
#endif
1631+
#else
16151632
#endif
16161633
tm->tm_year=tx->tm_year+1900;
16171634
tm->tm_mon=tx->tm_mon+1;
@@ -1626,6 +1643,9 @@ printf( "datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
16261643
if (tzn!=NULL)*tzn=tzname[(tm->tm_isdst>0)];
16271644

16281645
#else/* !HAVE_INT_TIMEZONE */
1646+
tm->tm_gmtoff=tx->tm_gmtoff;
1647+
tm->tm_zone=tx->tm_zone;
1648+
16291649
*tzp= (tm->tm_isdst? (tm->tm_gmtoff-3600):tm->tm_gmtoff);/* tm_gmtoff is Sun/DEC-ism */
16301650
if (tzn!=NULL)*tzn=tm->tm_zone;
16311651
#endif
@@ -1634,6 +1654,7 @@ printf( "datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
16341654
*tzp=CTimeZone;/* V7 conventions; don't know timezone? */
16351655
if (tzn!=NULL)*tzn=CTZName;
16361656
#endif
1657+
16371658
}else {
16381659
*tzp=0;
16391660
tm->tm_isdst=0;
@@ -1653,10 +1674,12 @@ printf( "datetime2tm- time is %02d:%02d:%02d %.7f\n", tm->tm_hour, tm->tm_min, t
16531674
#endif
16541675

16551676
#ifdefDATEDEBUG
1677+
#ifdefUSE_POSIX_TIME
16561678
#ifdefHAVE_INT_TIMEZONE
16571679
printf("datetime2tm- timezone is %s; offset is %d (%d); daylight is %d\n",
16581680
tzname[tm->tm_isdst!=0], ((tzp!=NULL)?*tzp:0),CTimeZone,CDayLight);
16591681
#endif
1682+
#endif
16601683
#endif
16611684

16621685
return0;
@@ -1690,6 +1713,9 @@ printf( "tm2datetime- time is %f %02d:%02d:%02d %f\n", time, tm->tm_hour, tm->tm
16901713
}/* tm2datetime() */
16911714

16921715

1716+
/* timespan2tm()
1717+
* Convert a timespan data type to a tm structure.
1718+
*/
16931719
int
16941720
timespan2tm(TimeSpanspan,structtm*tm,float8*fsec)
16951721
{
@@ -1710,19 +1736,10 @@ timespan2tm(TimeSpan span, struct tm *tm, float8 *fsec)
17101736
time=span.time;
17111737
#endif
17121738

1713-
funit=modf( (time /86400),&iunit);
1714-
tm->tm_mday=iunit;
1715-
if (tm->tm_mday!=0)time-=rint(tm->tm_mday*86400);
1716-
1717-
funit=modf( (time /3600),&iunit);
1718-
tm->tm_hour=iunit;
1719-
if (tm->tm_hour!=0)time-=rint(tm->tm_hour*3600e0);
1720-
funit=modf( (time /60),&iunit);
1721-
tm->tm_min=iunit;
1722-
if (tm->tm_min!=0)time-=rint(tm->tm_min*60e0);
1723-
funit=modf(time,&iunit);
1724-
tm->tm_sec=iunit;
1725-
if (tm->tm_sec!=0)time-=tm->tm_sec;
1739+
TMODULO(time,tm->tm_mday,86400e0);
1740+
TMODULO(time,tm->tm_hour,3600e0);
1741+
TMODULO(time,tm->tm_min,60e0);
1742+
TMODULO(time,tm->tm_sec,1);
17261743
*fsec=time;
17271744

17281745
#ifdefDATEDEBUG
@@ -1901,6 +1918,11 @@ printf( "ParseDateTime- set field[%d] to %s type %d\n", (nf-1), field[nf-1], fty
19011918
*Also supports input in compact time:
19021919
*"970207 152327"
19031920
*"97038 152327"
1921+
*
1922+
* Use the system-provided functions to get the current time zone
1923+
* if not specified in the input string.
1924+
* If the date is outside the time_t system-supported time range,
1925+
* then assume GMT time zone. - tgl 97/05/27
19041926
*/
19051927
int
19061928
DecodeDateTime(char*field[],intftype[],intnf,
@@ -2090,7 +2112,6 @@ printf( " %02d:%02d:%02d\n", tm->tm_hour, tm->tm_min, tm->tm_sec);
20902112
return(((fmask&DTK_TIME_M)==DTK_TIME_M)?1:-1);
20912113

20922114
/* timezone not specified? then find local timezone if possible */
2093-
/* XXX HACK to get correct behavior relative to Postgres v6.0 - tgl 97/04/07 */
20942115
if ((*dtype==DTK_DATE)&& ((fmask&DTK_DATE_M)==DTK_DATE_M)
20952116
&& (tzp!=NULL)&& (! (fmask&DTK_M(TZ)))) {
20962117

@@ -2105,9 +2126,11 @@ printf( " %02d:%02d:%02d\n", tm->tm_hour, tm->tm_min, tm->tm_sec);
21052126

21062127
#ifdefHAVE_INT_TIMEZONE
21072128
*tzp= ((tm->tm_isdst>0)? (timezone-3600):timezone);
2129+
21082130
#else/* !HAVE_INT_TIMEZONE */
2109-
*tzp=tm->tm_gmtoff;
2131+
*tzp=-(tm->tm_gmtoff);/* tm_gmtoff is Sun/DEC-ism */
21102132
#endif
2133+
21112134
#else/* !USE_POSIX_TIME */
21122135
*tzp=CTimeZone;
21132136
#endif
@@ -2803,7 +2826,7 @@ printf( "DecodeDateDelta- (%08x/%08x) field[%d] %s value is %d\n",
28032826
};
28042827

28052828
if (*fsec!=0) {
2806-
*fsec=modf(*fsec,&sec);
2829+
TMODULO(*fsec,sec,1);
28072830
tm->tm_sec+=sec;
28082831
};
28092832

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp