diff options
Diffstat (limited to 'src/smsutil.c')
-rw-r--r-- | src/smsutil.c | 37 |
1 files changed, 37 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; +} |