datefmt

format unix timestamps over stdin
git clone git://jb55.com/datefmt
Log | Files | Refs | README | LICENSE

commit aa3b7728ea1efa4effe3878ef1b8e88f51190875
parent e06c047c96ab8ba1924a291bd049dd4892c91330
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 30 Oct 2022 08:03:56 -0700

rename timeago to relative

timeago isn't that clear

Diffstat:
MREADME | 2+-
Mdatefmt.c | 20++++++++++----------
2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/README b/README @@ -8,7 +8,7 @@ format unix timestamps from stdin -p, --past only format timestamps in the past --version display version information and exit -m, --ms interpret timestamps as milliseconds instead of seconds - -t, --timeago custom format: show age of timestamp (1h, 2d, etc) + -r, --relative custom format: show age of timestamp (1h, 2d, etc) FORMAT a strftime format string, defaults to '%F %R' diff --git a/datefmt.c b/datefmt.c @@ -22,7 +22,7 @@ struct parser { int n_digits; int dir; int ms; - int timeago; + int relative; const char *format; char digits[15]; }; @@ -80,7 +80,7 @@ static int time_matches(struct parser *parser, int64_t ts) return 1; } -static void print_timeago(int64_t previous) +static void print_relative(int64_t previous) { time_t now = time(NULL); @@ -107,12 +107,12 @@ static void print_timeago(int64_t previous) } } -static void print_time(const char *format, char *charbuf, int64_t ts, int timeago) +static void print_time(const char *format, char *charbuf, int64_t ts, int relative) { static char timebuf[128]; - if (timeago) { - print_timeago(ts); + if (relative) { + print_relative(ts); printf("%s", charbuf); } else { strftime(timebuf, sizeof(timebuf), format, localtime((time_t*)&ts)); @@ -139,7 +139,7 @@ static enum state doaction(int c, enum state new_state, struct parser *parser) ts = strtoll(parser->digits, NULL, 10); /* found date */ if (time_matches(parser, ts)) { - print_time(parser->format, charbuf, ts, parser->timeago); + print_time(parser->format, charbuf, ts, parser->relative); } else { print_rest(parser, charbuf, &new_state); } @@ -214,7 +214,7 @@ static void parser_init(struct parser *parser) parser->before = -1; parser->dir = 0; parser->ms = 0; - parser->timeago = 0; + parser->relative = 0; parser->n_digits = 0; parser->format = fmt? fmt : "%F %R"; } @@ -228,7 +228,7 @@ static void usage() { printf(" -p, --past only format timestamps in the past \n"); printf(" --version display version information and exit \n"); printf(" -m, --ms interpret timestamps as milliseconds instead of seconds \n"); - printf(" -t, --timeago custom format: show age of timestamp (1h, 2d, etc) \n"); + printf(" -r, --relative custom format: show age of timestamp (1h, 2d, etc) \n"); printf("\n FORMAT\n a strftime format string, defaults to '%%F %%R'\n"); @@ -287,8 +287,8 @@ static void parse_arg(int *argc, char **argv, struct parser *parser) } else if (!strcmp("--ms", argv[0]) || !strcmp("-m", argv[0])) { parser->ms = 1; shift_arg(argc, argv); - } else if (!strcmp("--timeago", argv[0]) || !strcmp("-t", argv[0])) { - parser->timeago = 1; + } else if (!strcmp("--relative", argv[0]) || !strcmp("-r", argv[0])) { + parser->relative = 1; shift_arg(argc, argv); } else { parser->format = (const char*)argv[0];