summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/smsutil.c37
-rw-r--r--src/smsutil.h2
-rw-r--r--unit/test-sms.c16
3 files changed, 55 insertions, 0 deletions
diff --git a/src/smsutil.c b/src/smsutil.c
index 6bbb57d1..d44e73d2 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -1484,3 +1484,40 @@ gboolean sms_udh_iter_next(struct sms_udh_iter *iter)
return TRUE;
}
+
+/* Returns both forms of time. The time_t value returns the time in local
+ * timezone. The struct tm is filled out with the remote time information
+ */
+time_t sms_scts_to_time(struct sms_scts *scts, struct tm *remote)
+{
+ struct tm t;
+ time_t ret;
+
+ t.tm_sec = scts->second;
+ t.tm_min = scts->minute;
+ t.tm_hour = scts->hour;
+ t.tm_mday = scts->day;
+ t.tm_mon = scts->month - 1;
+ t.tm_isdst = -1;
+
+ if (scts->year > 80)
+ t.tm_year = scts->year;
+ else
+ t.tm_year = scts->year + 100;
+
+ ret = mktime(&t);
+
+ /* Adjust local time by the local timezone information */
+ ret += t.tm_gmtoff;
+
+ /* Set the proper timezone on the remote side */
+ t.tm_gmtoff = scts->timezone * 15 * 60;
+
+ /* Now adjust by the remote timezone information */
+ ret -= t.tm_gmtoff;
+
+ if (remote)
+ memcpy(remote, &t, sizeof(struct tm));
+
+ return ret;
+}
diff --git a/src/smsutil.h b/src/smsutil.h
index 940a185b..566701c2 100644
--- a/src/smsutil.h
+++ b/src/smsutil.h
@@ -295,4 +295,6 @@ guint8 sms_udh_iter_get_ie_length(struct sms_udh_iter *iter);
void sms_udh_iter_get_ie_data(struct sms_udh_iter *iter, guint8 *data);
gboolean sms_udh_iter_has_next(struct sms_udh_iter *iter);
gboolean sms_udh_iter_next(struct sms_udh_iter *iter);
+
+time_t sms_scts_to_time(struct sms_scts *scts, struct tm *remote);
#endif
diff --git a/unit/test-sms.c b/unit/test-sms.c
index d644cda0..6057076e 100644
--- a/unit/test-sms.c
+++ b/unit/test-sms.c
@@ -38,6 +38,10 @@ static const char *simple_submit = "0011000B916407281553F80000AA"
static void print_scts(struct sms_scts *scts, const char *prefix)
{
+ time_t ts;
+ struct tm remote;
+ char buf[128];
+
g_print("%s: (YY-MM-DD) %02d-%02d-%02d\n", prefix,
(int)scts->year, (int)scts->month, (int)scts->day);
@@ -47,6 +51,18 @@ static void print_scts(struct sms_scts *scts, const char *prefix)
g_print("%s: Timezone %d hours %d minutes\n", prefix,
(int)scts->timezone / 4,
(int)((abs(scts->timezone) % 4) * 15));
+
+ ts = sms_scts_to_time(scts, &remote);
+
+ strftime(buf, 127, "%a, %d %b %Y %H:%M:%S %z", localtime(&ts));
+ buf[127] = '\0';
+
+ g_print("local time: %s\n", buf);
+
+ strftime(buf, 127, "%a, %d %b %Y %H:%M:%S %z", &remote);
+ buf[127] = '\0';
+
+ g_print("remote time: %s\n", buf);
}
static void print_vpf(enum sms_validity_period_format vpf,