]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: add TABLE_TIMESTAMP_UTC and _RELATIVE
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Jul 2019 15:44:14 +0000 (00:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Jul 2019 15:44:14 +0000 (00:44 +0900)
src/shared/format-table.c
src/shared/format-table.h

index 90c80568ac43ec8d69c9a47b0ab9299cc8865ccf..11e4d567299f3fd54a708a869b6b2e8851863577 100644 (file)
@@ -230,6 +230,8 @@ static size_t table_data_size(TableDataType type, const void *data) {
                 return sizeof(bool);
 
         case TABLE_TIMESTAMP:
+        case TABLE_TIMESTAMP_UTC:
+        case TABLE_TIMESTAMP_RELATIVE:
         case TABLE_TIMESPAN:
         case TABLE_TIMESPAN_MSEC:
                 return sizeof(usec_t);
@@ -720,6 +722,8 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
                         break;
 
                 case TABLE_TIMESTAMP:
+                case TABLE_TIMESTAMP_UTC:
+                case TABLE_TIMESTAMP_RELATIVE:
                 case TABLE_TIMESPAN:
                 case TABLE_TIMESPAN_MSEC:
                         buffer.usec = va_arg(ap, usec_t);
@@ -884,6 +888,8 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
                         return 0;
 
                 case TABLE_TIMESTAMP:
+                case TABLE_TIMESTAMP_UTC:
+                case TABLE_TIMESTAMP_RELATIVE:
                         return CMP(a->timestamp, b->timestamp);
 
                 case TABLE_TIMESPAN:
@@ -988,14 +994,23 @@ static const char *table_data_format(TableData *d) {
         case TABLE_BOOLEAN:
                 return yes_no(d->boolean);
 
-        case TABLE_TIMESTAMP: {
+        case TABLE_TIMESTAMP:
+        case TABLE_TIMESTAMP_UTC:
+        case TABLE_TIMESTAMP_RELATIVE: {
                 _cleanup_free_ char *p;
+                char *ret;
 
                 p = new(char, FORMAT_TIMESTAMP_MAX);
                 if (!p)
                         return NULL;
 
-                if (!format_timestamp(p, FORMAT_TIMESTAMP_MAX, d->timestamp))
+                if (d->type == TABLE_TIMESTAMP)
+                        ret = format_timestamp(p, FORMAT_TIMESTAMP_MAX, d->timestamp);
+                else if (d->type == TABLE_TIMESTAMP_UTC)
+                        ret = format_timestamp_utc(p, FORMAT_TIMESTAMP_MAX, d->timestamp);
+                else
+                        ret = format_timestamp_relative(p, FORMAT_TIMESTAMP_MAX, d->timestamp);
+                if (!ret)
                         return "n/a";
 
                 d->formatted = TAKE_PTR(p);
@@ -1637,6 +1652,8 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
                 return json_variant_new_boolean(ret, d->boolean);
 
         case TABLE_TIMESTAMP:
+        case TABLE_TIMESTAMP_UTC:
+        case TABLE_TIMESTAMP_RELATIVE:
                 if (d->timestamp == USEC_INFINITY)
                         return json_variant_new_null(ret);
 
index cd77ea02f0ca14f4b31fd07196c968d50df7be2e..bbfeb10c11efc8cf6e3e77a9fee2ccdfba94ed49 100644 (file)
@@ -13,6 +13,8 @@ typedef enum TableDataType {
         TABLE_STRING,
         TABLE_BOOLEAN,
         TABLE_TIMESTAMP,
+        TABLE_TIMESTAMP_UTC,
+        TABLE_TIMESTAMP_RELATIVE,
         TABLE_TIMESPAN,
         TABLE_TIMESPAN_MSEC,
         TABLE_SIZE,