]> granicus.if.org Git - sysstat/commitdiff
Add epoch type to start and end times
authorNathanael P Wilson <Nathanael.P.Wilson@aexp.com>
Thu, 1 Sep 2022 23:21:45 +0000 (16:21 -0700)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 7 Jan 2023 13:45:43 +0000 (14:45 +0100)
sa.h
sa_common.c

diff --git a/sa.h b/sa.h
index 4c212839c0560f02ba646e945457a6b7f2d79b9d..a301b75b506131e2dd579f58734477fb4351e397 100644 (file)
--- 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 */
index 35251003cbab85a14c795f2407c8426d0e844894..4de72b5bf129f1f941e5ea28c0ed94eb20abc83a 100644 (file)
@@ -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;