From 9e91eb6e8b2ec2041fc14f3c8cc740a0371277c3 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 2 Jan 2020 16:15:35 +0100 Subject: [PATCH] mscan: add dottime formatting --- man/mscan.1 | 7 ++++++- mscan.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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 #include +#include #include #include #include @@ -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);