Review at  https://gerrit.osmocom.org/3128

04.08: find a portable way to obtain the timezone offset

Portable GMT offset calculation to display correct
time on GSM.

Change-Id: I673f17af2550c9708c4771e4ea4eafbbfafbb824
---
M openbsc/src/libmsc/gsm_04_08.c
1 file changed, 11 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/28/3128/1

diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index 89108e4..f1b2a4b 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -861,12 +861,20 @@
        else {
                /* Need to get GSM offset and convert into 15 min units */
                /* This probably breaks if gmtoff returns a value not evenly 
divisible by 15? */
-               local_time = localtime(&cur_t);
 #ifdef HAVE_TM_GMTOFF_IN_TM
+               local_time = localtime(&cur_t);
                tzunits = (local_time->tm_gmtoff/60)/15;
 #else
-#warning find a portable way to obtain the timezone offset
-               tzunits = 0;
+               /* #warning find a portable way to obtain the timezone offset
+                * this should be portable */
+               time_t utc;
+               double offsetFromUTC;
+               utc = mktime(gmt_time);
+               local_time = localtime(&cur_t);
+               offsetFromUTC = difftime(cur_t, utc);
+               if (local_time->tm_isdst)
+                       offsetFromUTC += 3600.0;
+               tzunits = ((int)offsetFromUTC) / 60 / 15;
 #endif
                if (tzunits < 0) {
                        tzunits = tzunits/-1;

-- 
To view, visit https://gerrit.osmocom.org/3128
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I673f17af2550c9708c4771e4ea4eafbbfafbb824
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: dexter <[email protected]>

Reply via email to