summaryrefslogtreecommitdiff
path: root/time
diff options
context:
space:
mode:
authorBranko Čibej <brane@apache.org>2001-07-01 21:47:53 +0000
committerBranko Čibej <brane@apache.org>2001-07-01 21:47:53 +0000
commit71db5c856eb79f5321436683cb318fb7c656e693 (patch)
treed7ed63a2be50db6e0bd7d7d85725cf50f0a62ecb /time
parentdc24ef72dab81d192053275ae592fed29a7c1d2b (diff)
downloadapr-71db5c856eb79f5321436683cb318fb7c656e693.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: https://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
}