Skip to content
Snippets Groups Projects
Commit 88148e0d authored by rswindell's avatar rswindell
Browse files

Fix: xpDateTime_to_time() would convert an xpDateTime_t which was in UTC

to the local timezone equivalent (not adjusting for offset). Now using timegm()
(aka mkgmtime()) to fix this scenario. Times in zones other than the local time
zone or UTC are explicitly not supported by this function now (returns
INVALID_TIME in that scenario).
parent c43eef30
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* * * *
* Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html * * Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* * * *
* This library is free software; you can redistribute it and/or * * This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
...@@ -123,6 +123,7 @@ xpTimeZone_t DLLCALL xpTimeZone_local(void) ...@@ -123,6 +123,7 @@ xpTimeZone_t DLLCALL xpTimeZone_local(void)
#endif #endif
} }
/* TODO: Supports local timezone and UTC only, currently */
time_t DLLCALL xpDateTime_to_time(xpDateTime_t xpDateTime) time_t DLLCALL xpDateTime_to_time(xpDateTime_t xpDateTime)
{ {
struct tm tm; struct tm tm;
...@@ -140,7 +141,11 @@ time_t DLLCALL xpDateTime_to_time(xpDateTime_t xpDateTime) ...@@ -140,7 +141,11 @@ time_t DLLCALL xpDateTime_to_time(xpDateTime_t xpDateTime)
tm.tm_min = xpDateTime.time.minute; tm.tm_min = xpDateTime.time.minute;
tm.tm_sec = (int)xpDateTime.time.second; tm.tm_sec = (int)xpDateTime.time.second;
return sane_mktime(&tm); if(xpDateTime.zone == xpTimeZone_UTC)
return sane_timegm(&tm);
if(xpDateTime.zone == xpTimeZone_LOCAL || xpDateTime.zone == xpTimeZone_local())
return sane_mktime(&tm);
return INVALID_TIME;
} }
xpDateTime_t DLLCALL time_to_xpDateTime(time_t ti, xpTimeZone_t zone) xpDateTime_t DLLCALL time_to_xpDateTime(time_t ti, xpTimeZone_t zone)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment