mirror of git://git.sysmocom.de/ofono
Add utility to convert SCTS to local/remote time
This commit is contained in:
parent
b149dc166c
commit
41071737d0
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue