diff options
author | Leah Neukirchen <leah@vuxu.org> | 2020-01-02 16:15:35 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2020-01-02 16:15:35 +0100 |
commit | 9e91eb6e8b2ec2041fc14f3c8cc740a0371277c3 (patch) | |
tree | 72419f53437541613d9a8ec467d4300203e8fec8 | |
parent | dbf118f6c9e873ff5ae333cf041a3b10b0eca531 (diff) | |
download | mblaze-9e91eb6e8b2ec2041fc14f3c8cc740a0371277c3.tar.gz mblaze-9e91eb6e8b2ec2041fc14f3c8cc740a0371277c3.tar.xz mblaze-9e91eb6e8b2ec2041fc14f3c8cc740a0371277c3.zip |
mscan: add dottime formatting
-rw-r--r-- | man/mscan.1 | 7 | ||||
-rw-r--r-- | mscan.c | 28 |
2 files changed, 34 insertions, 1 deletions
diff --git a/man/mscan.1 b/man/mscan.1 index 8fd930e..f2378a4 100644 --- a/man/mscan.1 +++ b/man/mscan.1 @@ -1,4 +1,4 @@ -.Dd September 25, 2018 +.Dd January 2, 2020 .Dt MSCAN 1 .Os .Sh NAME @@ -94,6 +94,11 @@ on the current message, otherwise a blank. .It Cm "%" Ns Oo Ar wd Oc Ns Cm "d" Adaptive date of the message. +When +.Ar wd +is greater or equal to 19, +the timestamp is shown in dottime format +.Pq Lk https://dotti.me/ . .It Cm "%" Ns Oo Ar wd Oc Ns Cm "D" ISO date of the message .Pq year, month, day . diff --git a/mscan.c b/mscan.c index c9a00a4..9fd1f4d 100644 --- a/mscan.c +++ b/mscan.c @@ -6,6 +6,7 @@ #include <sys/stat.h> #include <sys/types.h> +#include <ctype.h> #include <errno.h> #include <fcntl.h> #include <locale.h> @@ -138,6 +139,33 @@ fmt_date(struct message *msg, int w, int iso) strftime(date, sizeof date, "%Y-%m-%d %H:%M", tm); else strftime(date, sizeof date, "%Y-%m-%d", tm); + } else if (w >= 19) { + // https://dotti.me/ + + tm = gmtime(&t); + strftime(date, sizeof date, "%Y-%m-%dT%H\xc2\xb7%M", tm); + char *d = date + strlen(date); + + char *e = v + strlen(v); + while (e > v && (*e != '+' && *e != '-')) + e--; + + if (isdigit(e[1]) && isdigit(e[2]) && isdigit(e[3]) && isdigit(e[4])) { + *d++ = e[0]; + *d++ = e[1]; + *d++ = e[2]; + if (e[3] != '0' || e[4] != '0') { + *d++ = ':'; + *d++ = e[3]; + *d++ = e[4]; + } + *d = 0; + } else { + *d++ = '+'; + *d++ = '0'; + *d++ = '0'; + *d = 0; + } } else if (w < 10) { if (tm->tm_year != curyear) strftime(date, sizeof date, "%b%y", tm); |