From 208b5822011b66b1bb7c645c9c9b989c34bcdf30 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Fri, 28 Jan 2000 17:40:42 +0000 Subject: [PATCH] There were so far only 42 different conversion specifications in strftime(3), add another one. :) %z yields the local timezone's offset in hours and minutes, as used in RFC822 headers. There's a precedence for this in Lunux' libc, and Internet software (like Perl scripts) start using it. OKed by (wrt. the code freeze): jkh --- lib/libc/stdtime/strftime.3 | 6 ++++++ lib/libc/stdtime/strftime.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/libc/stdtime/strftime.3 b/lib/libc/stdtime/strftime.3 index c4d2d8c07e23..9b2184348c8f 100644 --- a/lib/libc/stdtime/strftime.3 +++ b/lib/libc/stdtime/strftime.3 @@ -202,6 +202,11 @@ is replaced by the year with century as a decimal number. is replaced by the year without century as a decimal number (00-99). .It Cm \&%Z is replaced by the time zone name. +.It Cm \&%z +is replaced by the time zone offset from UTC; a leading plus sign stands for +east of UTC, a minus sign for west of UTC, hours and minutes follow +with two digits each and no delimiter between them (common form for +RFC 822 date headers). .It Cm %+ is replaced by national representation of the date and time (the format is similar to that produced by @@ -241,6 +246,7 @@ with a lot of extensions including .Ql %t , .Ql %u , .Ql \&%V , +.Ql %z , .Ql %+ . The peculiar week number and year in the replacements of diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index 9aa891f6e168..6404d9c4f26f 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -397,6 +397,22 @@ label: pt, ptlim); } else pt = _add("?", pt, ptlim); continue; + case 'z': + { + long absoff; + if (t->tm_gmtoff >= 0) { + absoff = t->tm_gmtoff; + pt = _add("+", pt, ptlim); + } else { + absoff = -t->tm_gmtoff; + pt = _add("-", pt, ptlim); + } + pt = _conv(absoff / 3600, "%02d", + pt, ptlim); + pt = _conv((absoff % 3600) / 60, "%02d", + pt, ptlim); + }; + continue; case '+': pt = _fmt(Locale->date_fmt, t, pt, ptlim); continue;