datefmt

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

commit 531e2369b30db01593bd17840fe399802a757791
parent 63cfa62cfd599eb89b8b793658056ec659c3b6f7
Author: William Casarin <jb55@jb55.com>
Date:   Tue,  7 Dec 2021 11:05:32 -0800

env: allow changing default format with env

Diffstat:
MCHANGELOG.md | 4++++
Mdatefmt.c | 6++++--
Mdoc/datefmt.1 | 3++-
Mdoc/datefmt.scd | 3++-
4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog +## 0.2.2 + +- Added `DEFAULT_DATEFMT` env var to change default format string + ## 0.2.1 - Fix darwin/clang build diff --git a/datefmt.c b/datefmt.c @@ -5,7 +5,7 @@ #include <time.h> #include <string.h> -#define VERSION "0.2.1" +#define VERSION "0.2.2" enum state { BEGIN, @@ -166,6 +166,8 @@ static void process(struct parser *parser, int last) static void parser_init(struct parser *parser) { static unsigned char buf[READSIZE]; + const char *fmt = getenv("DEFAULT_DATEFMT"); + parser->buf = buf; parser->state = BEGIN; parser->len = 0; @@ -174,7 +176,7 @@ static void parser_init(struct parser *parser) parser->dir = 0; parser->ms = 0; parser->n_digits = 0; - parser->format = "%F %R"; + parser->format = fmt? fmt : "%F %R"; } static void usage() { diff --git a/doc/datefmt.1 b/doc/datefmt.1 @@ -55,7 +55,8 @@ display version and exit .RE .SH FORMAT .P -a strftime(3) format string.\& defaults to '%F %R' +a strftime(3) format string.\& defaults to '%F %R'.\& The default can be changed +with the \fBDEFAULT_DATEFMT\fR environment variable.\& .P .SH EXAMPLE .P diff --git a/doc/datefmt.scd b/doc/datefmt.scd @@ -36,7 +36,8 @@ to convert these timestamps into formatted dates. # FORMAT -a strftime(3) format string. defaults to '%F %R' +a strftime(3) format string. defaults to '%F %R'. The default can be changed +with the *DEFAULT_DATEFMT* environment variable. # EXAMPLE