X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Ftimestamp.c;h=4699a848e7be3e44ec89bedf89a120f82a87fa4f;hb=HEAD;hp=dfeec75ce9100e01eccb70460da828bbd63f7ca7;hpb=94a044f90357edefa6f4ae9f0b1d5885b0e34aee;p=debian%2Famanda diff --git a/common-src/timestamp.c b/common-src/timestamp.c index dfeec75..4699a84 100644 --- a/common-src/timestamp.c +++ b/common-src/timestamp.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1999 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -24,6 +25,7 @@ * file named AUTHORS, in the root directory of this distribution. */ +#include "amanda.h" #include "timestamp.h" #include "conffile.h" #include @@ -60,6 +62,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 +70,62 @@ 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; + tm.tm_year = 0; + tm.tm_mon = 0; + tm.tm_mday = 1; + tm.tm_hour = 0; + tm.tm_min = 0; + tm.tm_sec = 0; + + 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;