From: Nathanael P Wilson Date: Thu, 1 Sep 2022 23:21:45 +0000 (-0700) Subject: Add epoch type to start and end times X-Git-Tag: v12.7.2~14^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45c2383dac3b0738c9f0409c7d2fc2b1e7192cce;p=sysstat Add epoch type to start and end times --- diff --git a/sa.h b/sa.h index 4c21283..a301b75 100644 --- a/sa.h +++ b/sa.h @@ -1358,6 +1358,8 @@ struct tstamp { int tm_min; int tm_hour; int use; + int use_epoch; + time_t epoch; }; /* Structure for items in list */ diff --git a/sa_common.c b/sa_common.c index 3525100..4de72b5 100644 --- a/sa_common.c +++ b/sa_common.c @@ -643,6 +643,35 @@ int decode_timestamp(char timestamp[], struct tstamp *tse) return 0; } +/* + *************************************************************************** + * Use time stamp to fill tstamp structure. + * + * IN: + * @timestamp Timestamp to decode (format: seconds since Januray 1st 1970 00:00:00 UTC). + * + * OUT: + * @tse Structure containing the decoded timestamp. + * + * RETURNS: + * 0 + *************************************************************************** + */ +int decode_epoch(char timestamp[], struct tstamp *tse) +{ + time_t epoch_time = atol(timestamp); + tse->epoch = epoch_time; + tse->use_epoch = TRUE; + + struct tm *given_time = localtime(&epoch_time); + tse->tm_sec = given_time->tm_sec; + tse->tm_min = given_time->tm_min; + tse->tm_hour = given_time->tm_hour; + tse->use = TRUE; + + return 0; +} + /* *************************************************************************** * Compare two timestamps. @@ -699,7 +728,7 @@ int datecmp(struct tm *rectime, struct tstamp *tse, int cross_day) int parse_timestamp(char *argv[], int *opt, struct tstamp *tse, const char *def_timestamp) { - char timestamp[9]; + char timestamp[11]; if (argv[++(*opt)]) { switch (strlen(argv[*opt])) { @@ -714,6 +743,12 @@ int parse_timestamp(char *argv[], int *opt, struct tstamp *tse, strncpy(timestamp, argv[(*opt)++], 8); break; + case 10: + strncpy(timestamp, argv[(*opt)++], 10); + timestamp[10] = '\0'; + return decode_epoch(timestamp, tse); + break; + default: strncpy(timestamp, def_timestamp, 8); break;