Skip to content

Commit 9ab58bb

Browse files
author
Michael Meskes
committed
Also removed the function not just the call, sorry.
1 parent 439cf8e commit 9ab58bb

File tree

1 file changed

+1
-154
lines changed

1 file changed

+1
-154
lines changed

src/interfaces/ecpg/pgtypeslib/dt_common.c

+1-154
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.39 2007/05/21 07:04:00 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.40 2007/05/21 07:07:48 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -1090,159 +1090,6 @@ GetCurrentDateTime(struct tm * tm)
10901090
abstime2tm(time(NULL), &tz, tm, NULL);
10911091
}
10921092

1093-
/* DetermineLocalTimeZone()
1094-
*
1095-
* Given a struct tm in which tm_year, tm_mon, tm_mday, tm_hour, tm_min, and
1096-
* tm_sec fields are set, attempt to determine the applicable local zone
1097-
* (ie, regular or daylight-savings time) at that time. Set the struct tm's
1098-
* tm_isdst field accordingly, and return the actual timezone offset.
1099-
*
1100-
* This subroutine exists to centralize uses of mktime() and defend against
1101-
* mktime() bugs/restrictions on various platforms. This should be
1102-
* the *only* call of mktime() in the backend.
1103-
*/
1104-
static int
1105-
DetermineLocalTimeZone(struct tm * tm)
1106-
{
1107-
int tz;
1108-
1109-
if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
1110-
{
1111-
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
1112-
1113-
/*
1114-
* Some buggy mktime() implementations may change the year/month/day
1115-
* when given a time right at a DST boundary. To prevent corruption
1116-
* of the caller's data, give mktime() a copy...
1117-
*/
1118-
struct tm tt,
1119-
*tmp = &tt;
1120-
1121-
*tmp = *tm;
1122-
/* change to Unix conventions for year/month */
1123-
tmp->tm_year -= 1900;
1124-
tmp->tm_mon -= 1;
1125-
1126-
/* indicate timezone unknown */
1127-
tmp->tm_isdst = -1;
1128-
1129-
if (mktime(tmp) != (time_t) -1 && tmp->tm_isdst >= 0)
1130-
{
1131-
/* mktime() succeeded, trust its result */
1132-
tm->tm_isdst = tmp->tm_isdst;
1133-
1134-
#if defined(HAVE_TM_ZONE)
1135-
/* tm_gmtoff is Sun/DEC-ism */
1136-
tz = -tmp->tm_gmtoff;
1137-
#elif defined(HAVE_INT_TIMEZONE)
1138-
tz = (tmp->tm_isdst > 0) ? TIMEZONE_GLOBAL - SECS_PER_HOUR : TIMEZONE_GLOBAL;
1139-
#endif /* HAVE_INT_TIMEZONE */
1140-
}
1141-
else
1142-
{
1143-
/*
1144-
* We have a buggy (not to say deliberately brain damaged)
1145-
* mktime(). Work around it by using localtime() instead.
1146-
*
1147-
* First, generate the time_t value corresponding to the given
1148-
* y/m/d/h/m/s taken as GMT time. This will not overflow (at
1149-
* least not for time_t taken as signed) because of the range
1150-
* check we did above.
1151-
*/
1152-
long day,
1153-
mysec,
1154-
locsec,
1155-
delta1,
1156-
delta2;
1157-
time_t mytime;
1158-
1159-
day = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) -
1160-
date2j(1970, 1, 1));
1161-
mysec = tm->tm_sec + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
1162-
mytime = (time_t) mysec;
1163-
1164-
/*
1165-
* Use localtime to convert that time_t to broken-down time, and
1166-
* reassemble to get a representation of local time.
1167-
*/
1168-
tmp = localtime(&mytime);
1169-
if (!tmp)
1170-
{
1171-
tm->tm_isdst = 0;
1172-
return 0;
1173-
}
1174-
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
1175-
date2j(1970, 1, 1));
1176-
locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
1177-
1178-
/*
1179-
* The local time offset corresponding to that GMT time is now
1180-
* computable as mysec - locsec.
1181-
*/
1182-
delta1 = mysec - locsec;
1183-
1184-
/*
1185-
* However, if that GMT time and the local time we are actually
1186-
* interested in are on opposite sides of a daylight-savings-time
1187-
* transition, then this is not the time offset we want. So,
1188-
* adjust the time_t to be what we think the GMT time
1189-
* corresponding to our target local time is, and repeat the
1190-
* localtime() call and delta calculation. We may have to do it
1191-
* twice before we have a trustworthy delta.
1192-
*
1193-
* Note: think not to put a loop here, since if we've been given
1194-
* an "impossible" local time (in the gap during a spring-forward
1195-
* transition) we'd never get out of the loop. Twice is enough to
1196-
* give the behavior we want, which is that "impossible" times are
1197-
* taken as standard time, while at a fall-back boundary ambiguous
1198-
* times are also taken as standard.
1199-
*/
1200-
mysec += delta1;
1201-
mytime = (time_t) mysec;
1202-
tmp = localtime(&mytime);
1203-
if (!tmp)
1204-
{
1205-
tm->tm_isdst = 0;
1206-
return 0;
1207-
}
1208-
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
1209-
date2j(1970, 1, 1));
1210-
locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
1211-
delta2 = mysec - locsec;
1212-
if (delta2 != delta1)
1213-
{
1214-
mysec += (delta2 - delta1);
1215-
mytime = (time_t) mysec;
1216-
tmp = localtime(&mytime);
1217-
if (!tmp)
1218-
{
1219-
tm->tm_isdst = 0;
1220-
return 0;
1221-
}
1222-
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
1223-
date2j(1970, 1, 1));
1224-
locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
1225-
delta2 = mysec - locsec;
1226-
}
1227-
tm->tm_isdst = tmp->tm_isdst;
1228-
tz = (int) delta2;
1229-
}
1230-
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
1231-
/* Assume UTC if no system timezone info available */
1232-
tm->tm_isdst = 0;
1233-
tz = 0;
1234-
#endif
1235-
}
1236-
else
1237-
{
1238-
/* Given date is out of range, so assume UTC */
1239-
tm->tm_isdst = 0;
1240-
tz = 0;
1241-
}
1242-
1243-
return tz;
1244-
}
1245-
12461093
static void
12471094
dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
12481095
{

0 commit comments

Comments
 (0)