mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-13 13:17:43 +03:00
format-table: add TABLE_TIMESTAMP_UTC and _RELATIVE
This commit is contained in:
parent
d8bfdbe1fa
commit
c5bbb2b5be
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user