[MERGED] openbsc[master]: 04.08: find a portable way to obtain the timezone offset

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon Jul 10 17:19:50 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: 04.08: find a portable way to obtain the timezone offset
......................................................................


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, 10 insertions(+), 3 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index 89108e4..f926223 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -861,12 +861,19 @@
 	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;
+		/* find timezone offset */
+		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: merged
Gerrit-Change-Id: I673f17af2550c9708c4771e4ea4eafbbfafbb824
Gerrit-PatchSet: 8
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list