X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Ftimestamp.c;h=30963555d25f80171edd43a99c1bd1446737bb76;hb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;hp=dfeec75ce9100e01eccb70460da828bbd63f7ca7;hpb=94a044f90357edefa6f4ae9f0b1d5885b0e34aee;p=debian%2Famanda diff --git a/common-src/timestamp.c b/common-src/timestamp.c index dfeec75..3096355 100644 --- a/common-src/timestamp.c +++ b/common-src/timestamp.c @@ -24,6 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ +#include "amanda.h" #include "timestamp.h" #include "conffile.h" #include @@ -60,6 +61,7 @@ char * get_timestamp_from_time(time_t when) { } char * get_proper_stamp_from_time(time_t when) { + /* note that this is reimplemented in perl in perl/Amanda/Util.swg */ if (getconf_boolean(CNF_USETIMESTAMPS)) { return get_timestamp_from_time(when); } else { @@ -67,6 +69,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;