1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-21 02:50:18 +03:00

format-table: add new cell type TABLE_TIMESPAN_DAY

This is just like TABLE_TIMESPAN_MSEC, but shows time spans in accuracy
of days.
This commit is contained in:
Lennart Poettering 2023-01-23 13:12:43 +01:00
parent 856ad0fdb6
commit 3d46a8292f
2 changed files with 9 additions and 2 deletions

View 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);

View 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,