git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Beat Bolli" <bb@drbeat.li>
Cc: michael.osipov@innomotics.com,  git@vger.kernel.org,
	 Beat Bolli <dev+git@drbeat.li>
Subject: Re: [PATCH] date: make "iso-strict" conforming for the UTC timezone
Date: Wed, 13 Mar 2024 11:30:42 -0700	[thread overview]
Message-ID: <xmqqwmq6asrx.fsf@gitster.g> (raw)
In-Reply-To: <20240313175000.2148-1-dev+git@drbeat.li> (Beat Bolli's message of "Wed, 13 Mar 2024 18:50:00 +0100")

"Beat Bolli" <bb@drbeat.li> writes:

> ISO 8601-1:2020-12 specifies that a zero timezone offset must be denoted
> with a "Z" suffix instead of the numeric "+00:00". Add the correponding
> special case to show_date() and a new test.

Hmph, would this break existing scripts that expects the current
behaviour, and if it does, is it safe for us to blame the script
authors for not following the standard?

Assuming that we do not need to worry about them, the patch itself
looks perfectly reasonable to me.

Thanks.

> Reported-by: Michael Osipov <michael.osipov@innomotics.com>
> Link: https://lore.kernel.org/git/410d458c-ae5b-40cc-9c8e-97b016c74a76@siemens.com/
> Signed-off-by: Beat Bolli <dev+git@drbeat.li>
> ---
>  date.c          | 14 +++++++++-----
>  t/t0006-date.sh |  1 +
>  2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/date.c b/date.c
> index 619ada5b2044..44cf2221d81f 100644
> --- a/date.c
> +++ b/date.c
> @@ -342,14 +342,18 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
>  				tm->tm_hour, tm->tm_min, tm->tm_sec,
>  				tz);
>  	else if (mode->type == DATE_ISO8601_STRICT) {
> -		char sign = (tz >= 0) ? '+' : '-';
> -		tz = abs(tz);
> -		strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
> +		strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d:%02d:%02d",
>  				tm->tm_year + 1900,
>  				tm->tm_mon + 1,
>  				tm->tm_mday,
> -				tm->tm_hour, tm->tm_min, tm->tm_sec,
> -				sign, tz / 100, tz % 100);
> +				tm->tm_hour, tm->tm_min, tm->tm_sec);
> +		if (tz == 0) {
> +			strbuf_addch(&timebuf, 'Z');
> +		} else {
> +			strbuf_addch(&timebuf, tz >= 0 ? '+' : '-');
> +			tz = abs(tz);
> +			strbuf_addf(&timebuf, "%02d:%02d", tz / 100, tz % 100);
> +		}
>  	} else if (mode->type == DATE_RFC2822)
>  		strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
>  			weekday_names[tm->tm_wday], tm->tm_mday,
> diff --git a/t/t0006-date.sh b/t/t0006-date.sh
> index e18b1602864e..1d228a981ee9 100755
> --- a/t/t0006-date.sh
> +++ b/t/t0006-date.sh
> @@ -46,6 +46,7 @@ check_show () {
>  TIME='1466000000 +0200'
>  check_show iso8601 "$TIME" '2016-06-15 16:13:20 +0200'
>  check_show iso8601-strict "$TIME" '2016-06-15T16:13:20+02:00'
> +check_show iso8601-strict "$(echo "$TIME" | sed 's/+0200$/+0000/')" '2016-06-15T14:13:20Z'
>  check_show rfc2822 "$TIME" 'Wed, 15 Jun 2016 16:13:20 +0200'
>  check_show short "$TIME" '2016-06-15'
>  check_show default "$TIME" 'Wed Jun 15 16:13:20 2016 +0200'

  reply	other threads:[~2024-03-13 18:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 11:27 log.date 'iso-strict' does not comply with ISO 8601-1:2020-12 Osipov, Michael (IN IT IN)
2024-03-13 17:50 ` [PATCH] date: make "iso-strict" conforming for the UTC timezone Beat Bolli
2024-03-13 18:30   ` Junio C Hamano [this message]
2024-03-13 19:29     ` Osipov, Michael (IN IT IN)
2024-03-13 22:29     ` [PATCH v2] " Beat Bolli
2024-03-13 22:42       ` Junio C Hamano
2024-03-13 22:54         ` [PATCH v3] " Beat Bolli
2024-03-13 23:06           ` Junio C Hamano
2024-03-13 19:27   ` [PATCH] " Osipov, Michael (IN IT IN)
2024-03-13 20:09   ` Kristoffer Haugsbakk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqwmq6asrx.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=bb@drbeat.li \
    --cc=dev+git@drbeat.li \
    --cc=git@vger.kernel.org \
    --cc=michael.osipov@innomotics.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).