X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=common-src%2Ftimestamp.c;h=bc24018b482557b766732ce1925d3bbb3066816d;hb=fd48f3e498442f0cbff5f3606c7c403d0566150e;hp=0c2e6c1513447411551d31e009edaa490858b78e;hpb=96f35b20267e8b1a1c846d476f27fcd330e0b018;p=debian%2Famanda diff --git a/common-src/timestamp.c b/common-src/timestamp.c index 0c2e6c1..bc24018 100644 --- a/common-src/timestamp.c +++ b/common-src/timestamp.c @@ -68,6 +68,56 @@ char * get_proper_stamp_from_time(time_t when) { } } +time_t get_time_from_timestamp(char *timestamp) +{ + struct tm tm; + char t[5]; + time_t tt; + + if (strlen(timestamp) >= 4) { + memcpy(t, timestamp, 4); + t[4]='\0'; + tm.tm_year = atoi(t) - 1900; + } + + if (strlen(timestamp) >= 6) { + memcpy(t, timestamp+4, 2); + t[2]='\0'; + tm.tm_mon = atoi(t) - 1; + } + + if (strlen(timestamp) >= 8) { + memcpy(t, timestamp+6, 2); + t[2]='\0'; + tm.tm_mday = atoi(t); + } + + if (strlen(timestamp) >= 10) { + memcpy(t, timestamp+8, 2); + t[2]='\0'; + tm.tm_hour = atoi(t); + } + + if (strlen(timestamp) >= 12) { + memcpy(t, timestamp+10, 2); + t[2]='\0'; + tm.tm_min = atoi(t); + } + + if (strlen(timestamp) >= 14) { + memcpy(t, timestamp+12, 2); + t[2]='\0'; + tm.tm_sec = atoi(t); + } + tm.tm_wday = 0; + tm.tm_yday = 0; + tm.tm_isdst = -1; + + tt = mktime(&tm); + + return(tt); +} + time_state_t get_timestamp_state(char * timestamp) { if (timestamp == NULL || *timestamp == '\0') { return TIME_STATE_REPLACE;