summaryrefslogtreecommitdiff
path: root/time
diff options
context:
space:
mode:
authorbrane <brane@13f79535-47bb-0310-9956-ffa450edef68>2001-07-01 21:47:53 +0000
committerbrane <brane@13f79535-47bb-0310-9956-ffa450edef68>2001-07-01 21:47:53 +0000
commit3f63d1bc24b82ad6c76f080eb87d53b1c218fb30 (patch)
treed7ed63a2be50db6e0bd7d7d85725cf50f0a62ecb /time
parentdef946778e9463f1fbffdb65dbb1b4cf4343b72b (diff)
downloadlibapr-3f63d1bc24b82ad6c76f080eb87d53b1c218fb30.tar.gz
Adjust the calculated GMT offset on get_offset() for daylight savings time.
This only affects platforms that do not have a tm_gmtoff field in struct tm (e.g., Solaris 2.6, HP-UX 10.20, ...). git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61843 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'time')
-rw-r--r--time/unix/time.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/time/unix/time.c b/time/unix/time.c
index a39ca75a8..35a9161f6 100644
--- a/time/unix/time.c
+++ b/time/unix/time.c
@@ -77,18 +77,28 @@ static apr_int32_t get_offset(struct tm *tm)
#elif defined(HAVE___OFFSET)
return tm->__tm_gmtoff;
#else
- /* we don't have an offset field to use, so calculate it */
+ /* We don't have an offset field to use, so calculate it.
+ mktime() is the inverse of localtime(); so, presumably,
+ passing in a struct tm made by gmtime() let's us calculate
+ the true GMT offset. However, there's a catch: if daylight
+ savings is in effect, gmtime()will set the tm_isdst field
+ and confuse mktime() into returning a time that's offset
+ by one hour. In that case, we must adjust the calculated GMT
+ offset. */
{
time_t t1 = time(0), t2 = 0;
struct tm t;
+ int was_dst;
#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
gmtime_r(&t1, &t);
#else
t = *gmtime(&t1);
#endif
+ was_dst = (t.tm_isdst > 0);
+ t.tm_isdst = -1;
t2 = mktime(&t);
- return (apr_int32_t) difftime(t1, t2);
+ return (apr_int32_t) difftime(t1, t2) + (was_dst ? 3600 : 0);
}
#endif
}