2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
4 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of U.M. not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. U.M. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
17 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Authors: the Amanda Development Team. Its members are listed in a
25 * file named AUTHORS, in the root directory of this distribution.
29 #include "timestamp.h"
34 * Construct a datestamp (YYYYMMDD) from a time_t.
36 char * get_datestamp_from_time(time_t when) {
39 if(when == (time_t)0) {
40 when = time((time_t *)NULL);
43 tm = localtime(&when);
44 return g_strdup_printf("%04d%02d%02d",
45 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
49 * Construct a timestamp (YYYYMMDDHHMMSS) from a time_t.
51 char * get_timestamp_from_time(time_t when) {
54 if(when == (time_t)0) {
55 when = time((time_t *)NULL);
58 tm = localtime(&when);
59 return g_strdup_printf("%04d%02d%02d%02d%02d%02d",
60 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
61 tm->tm_hour, tm->tm_min, tm->tm_sec);
64 char * get_proper_stamp_from_time(time_t when) {
65 /* note that this is reimplemented in perl in perl/Amanda/Util.swg */
66 if (getconf_boolean(CNF_USETIMESTAMPS)) {
67 return get_timestamp_from_time(when);
69 return get_datestamp_from_time(when);
73 time_t get_time_from_timestamp(char *timestamp)
85 if (strlen(timestamp) >= 4) {
86 memcpy(t, timestamp, 4);
88 tm.tm_year = atoi(t) - 1900;
91 if (strlen(timestamp) >= 6) {
92 memcpy(t, timestamp+4, 2);
94 tm.tm_mon = atoi(t) - 1;
97 if (strlen(timestamp) >= 8) {
98 memcpy(t, timestamp+6, 2);
100 tm.tm_mday = atoi(t);
103 if (strlen(timestamp) >= 10) {
104 memcpy(t, timestamp+8, 2);
106 tm.tm_hour = atoi(t);
109 if (strlen(timestamp) >= 12) {
110 memcpy(t, timestamp+10, 2);
115 if (strlen(timestamp) >= 14) {
116 memcpy(t, timestamp+12, 2);
129 time_state_t get_timestamp_state(char * timestamp) {
130 if (timestamp == NULL || *timestamp == '\0') {
131 return TIME_STATE_REPLACE;
132 } else if (strcmp(timestamp, "X") == 0) {
133 return TIME_STATE_UNDEF;
135 return TIME_STATE_SET;
139 char * get_undef_timestamp(void) {