commit: 5e49368e64f10e226c7f192d471bd14565f0f84b
parent 184fd9cf78e696a540ed35edc4d9c3dcc739c9c9
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 20 Dec 2025 17:40:18 +0100
cmd/date: add support for %::z
Diffstat:
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/cmd/date.1.in b/cmd/date.1.in
@@ -106,11 +106,19 @@ as you can verify with the following command:
Set the displayed datetime in
.Xr strftime 3
format,
-with additionally
-%N for nanoseconds and %:z for colon-separated timezone (±ZZ:ZZ).
-.br
+with additionally:
+.Bl -tag -width _::z -compact
+.It %N
+for nanoseconds,
+.It %:z
+for hour:minutes timezone offset (±ZZ:ZZ)
+.It %::z
+for hour:minutes:seconds timezone offset (±ZZ:ZZ:ZZ)
+.El
+.Pp
Otherwise defaults to
.Ql %c
+when unspecified.
.El
.Sh DATETIME FORMAT
include(libutils/datetime_parse.mdoc)
@@ -149,7 +157,7 @@ and
.Fl j
options are inspired by FreeBSD and NetBSD.
.Pp
-The %N and %:z formats are extensions inspired from GNU coreutils.
+The %N, %:z, %::z formats are extensions inspired from GNU coreutils.
.Pp
The
.Fl I
diff --git a/cmd/date.c b/cmd/date.c
@@ -84,6 +84,19 @@ date_strftime(char *restrict buf,
printed += got;
fmt_bufused += 3;
}
+ else if(fmt_buf[0] == '%' && fmt_buf[1] == ':' && fmt_buf[2] == ':' && fmt_buf[3] == 'z')
+ {
+ unsigned tzhr = absu(tm->tm_gmtoff % 3600 / 60);
+ unsigned tzsec = absu(tm->tm_gmtoff % 3600 % 60);
+
+ size_t got = snprintf(buf, buflen, "%+.2ld:%.2u:%.2u", tm->tm_gmtoff / 3600, tzhr, tzsec);
+ if(got == 0) return got;
+
+ buf += got;
+ buflen -= got;
+ printed += got;
+ fmt_bufused += 4;
+ }
else if(fmt_buf[0] == '%' && fmt_buf[1] == 'N')
{
size_t got = snprintf(buf, buflen, "%09ld", nsec);