From c5bbb2b5be079852d92d16ebc0d0840929ed82e1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 16 Jul 2019 00:44:14 +0900 Subject: [PATCH] format-table: add TABLE_TIMESTAMP_UTC and _RELATIVE --- src/shared/format-table.c | 21 +++++++++++++++++++-- src/shared/format-table.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 90c8056..11e4d56 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -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); diff --git a/src/shared/format-table.h b/src/shared/format-table.h index cd77ea0..bbfeb10 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -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, -- 2.7.4