diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/smsutil.c | 37 | ||||
-rw-r--r-- | src/smsutil.h | 2 |
2 files changed, 39 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 |