]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: add new cell type TABLE_TIMESPAN_DAY
authorLennart Poettering <lennart@poettering.net>
Mon, 23 Jan 2023 12:12:43 +0000 (13:12 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 24 Jan 2023 14:32:42 +0000 (15:32 +0100)
This is just like TABLE_TIMESPAN_MSEC, but shows time spans in accuracy
of days.

src/shared/format-table.c
src/shared/format-table.h

index fbac0f749880502d9aec124c328e1158acb59d70..ee45d4fd9e237596e8e53c2bca9beafa8ce25313 100644 (file)
@@ -300,6 +300,7 @@ static size_t table_data_size(TableDataType type, const void *data) {
         case TABLE_TIMESTAMP_DATE:
         case TABLE_TIMESPAN:
         case TABLE_TIMESPAN_MSEC:
+        case TABLE_TIMESPAN_DAY:
                 return sizeof(usec_t);
 
         case TABLE_SIZE:
@@ -898,6 +899,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
                 case TABLE_TIMESTAMP_DATE:
                 case TABLE_TIMESPAN:
                 case TABLE_TIMESPAN_MSEC:
+                case TABLE_TIMESPAN_DAY:
                         buffer.usec = va_arg(ap, usec_t);
                         data = &buffer.usec;
                         break;
@@ -1307,6 +1309,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
 
                 case TABLE_TIMESPAN:
                 case TABLE_TIMESPAN_MSEC:
+                case TABLE_TIMESPAN_DAY:
                         return CMP(a->timespan, b->timespan);
 
                 case TABLE_SIZE:
@@ -1558,7 +1561,8 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
         }
 
         case TABLE_TIMESPAN:
-        case TABLE_TIMESPAN_MSEC: {
+        case TABLE_TIMESPAN_MSEC:
+        case TABLE_TIMESPAN_DAY: {
                 _cleanup_free_ char *p = NULL;
 
                 p = new(char, FORMAT_TIMESPAN_MAX);
@@ -1566,7 +1570,8 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
                         return NULL;
 
                 if (!format_timespan(p, FORMAT_TIMESPAN_MAX, d->timespan,
-                                     d->type == TABLE_TIMESPAN ? 0 : USEC_PER_MSEC))
+                                     d->type == TABLE_TIMESPAN ? 0 :
+                                     d->type == TABLE_TIMESPAN_MSEC ? USEC_PER_MSEC : USEC_PER_DAY))
                         return "-";
 
                 d->formatted = TAKE_PTR(p);
@@ -2592,6 +2597,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
 
         case TABLE_TIMESPAN:
         case TABLE_TIMESPAN_MSEC:
+        case TABLE_TIMESPAN_DAY:
                 if (d->timespan == USEC_INFINITY)
                         return json_variant_new_null(ret);
 
index 0817846be22dffe68cf8cafb008a7b27c0554ed3..97255f5aef24eb42b54d6af20d8cad091e2d57af 100644 (file)
@@ -26,6 +26,7 @@ typedef enum TableDataType {
         TABLE_TIMESTAMP_DATE,
         TABLE_TIMESPAN,
         TABLE_TIMESPAN_MSEC,
+        TABLE_TIMESPAN_DAY,
         TABLE_SIZE,
         TABLE_BPS,
         TABLE_INT,