git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* log.date 'iso-strict' does not comply with ISO 8601-1:2020-12
@ 2024-03-13 11:27 Osipov, Michael (IN IT IN)
  2024-03-13 17:50 ` [PATCH] date: make "iso-strict" conforming for the UTC timezone Beat Bolli
  0 siblings, 1 reply; 10+ messages in thread
From: Osipov, Michael (IN IT IN) @ 2024-03-13 11:27 UTC (permalink / raw
  To: git

Folks,

I am running git version 2.43.0 and consider the following config:
> $ git config --system --list
> core.eol=native
> log.date=iso-strict
> color.ui=auto

when a commit happens with a zero offset the following is displayed:
> osipovmi@deblndw011x:~/var/Projekte/tomcat-native ((ba1454e15...)|BISECTING)
> $ git log
> commit ba1454e15619a44fe66d86f59c766c0cc25323eb (HEAD)
> Author: Mark Thomas <markt@apache.org>
> Date:   2024-02-13T08:27:43+00:00
> 
>     Fix link
> 

This not right according to the standard in the original language 
version, namely in sections:
* 4.3.13 Zeitverschiebung (time shift) (roughly translated from German): 
Z denotes that there is no shift from UTC. It also says that you either 
have an offset or use "Z"
* 5.3.3 Uhrzeit in UTC (time in UTC) (roughly translated from German): 
...the formats from sections ... must be used followed by the UTC marker 
"Z" without space.

Throughout the definition neither +0000 for the basic format nor +00:00 
for the extended format are used to denote a zero offset from UTC.

The offending code snippet is here: 
https://github.com/git/git/blob/945115026aa63df4ab849ab14a04da31623abece/date.c#L344-L352

See also Java's Instant class [1] which is based on ISO 8601 as well is 
Java's SimpleDateFormat XXX [2] which will *always* print "Z" in case of 
a zero offset.

I'd expect Git to comply with strict since this is why it has been 
introduced years ago instead of modifying 'iso'.

Regards,

Michael

[1] https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html
[2] 
https://github.com/openjdk/jdk8u-dev/blob/fbb3392d744d1572239eeca082d7365a03897b8b/jdk/src/share/classes/java/text/SimpleDateFormat.java#L1291-L1306


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] date: make "iso-strict" conforming for the UTC timezone
  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 ` Beat Bolli
  2024-03-13 18:30   ` Junio C Hamano
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Beat Bolli @ 2024-03-13 17:50 UTC (permalink / raw
  To: michael.osipov; +Cc: git, Junio C Hamano, Beat Bolli

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.

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'
-- 
2.44.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] date: make "iso-strict" conforming for the UTC timezone
  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
  2024-03-13 19:29     ` Osipov, Michael (IN IT IN)
  2024-03-13 22:29     ` [PATCH v2] " Beat Bolli
  2024-03-13 19:27   ` [PATCH] " Osipov, Michael (IN IT IN)
  2024-03-13 20:09   ` Kristoffer Haugsbakk
  2 siblings, 2 replies; 10+ messages in thread
From: Junio C Hamano @ 2024-03-13 18:30 UTC (permalink / raw
  To: Beat Bolli; +Cc: michael.osipov, git, Beat Bolli

"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'


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] date: make "iso-strict" conforming for the UTC timezone
  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
@ 2024-03-13 19:27   ` Osipov, Michael (IN IT IN)
  2024-03-13 20:09   ` Kristoffer Haugsbakk
  2 siblings, 0 replies; 10+ messages in thread
From: Osipov, Michael (IN IT IN) @ 2024-03-13 19:27 UTC (permalink / raw
  To: Beat Bolli, michael.osipov; +Cc: git, Junio C Hamano, Beat Bolli

On 2024-03-13 18:50, Beat Bolli wrote:
> 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.

Thanks for this lightspeed fix!


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] date: make "iso-strict" conforming for the UTC timezone
  2024-03-13 18:30   ` Junio C Hamano
@ 2024-03-13 19:29     ` Osipov, Michael (IN IT IN)
  2024-03-13 22:29     ` [PATCH v2] " Beat Bolli
  1 sibling, 0 replies; 10+ messages in thread
From: Osipov, Michael (IN IT IN) @ 2024-03-13 19:29 UTC (permalink / raw
  To: Junio C Hamano, Beat Bolli; +Cc: michael.osipov, git, Beat Bolli

On 2024-03-13 19:30, Junio C Hamano wrote:
> "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?

 From my PoV, if they don't stick it is not you to blame. The standard 
also says that it is equiv ("Z") to both numeral offsets. At the end 
strict is strict.

Thanks,

Michael


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] date: make "iso-strict" conforming for the UTC timezone
  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
  2024-03-13 19:27   ` [PATCH] " Osipov, Michael (IN IT IN)
@ 2024-03-13 20:09   ` Kristoffer Haugsbakk
  2 siblings, 0 replies; 10+ messages in thread
From: Kristoffer Haugsbakk @ 2024-03-13 20:09 UTC (permalink / raw
  To: Beat Bolli; +Cc: git, Junio C Hamano, Beat Bolli, michael.osipov

On Wed, Mar 13, 2024, at 18:50, Beat Bolli wrote:
> 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>

I personally don’t really think `Link` trailers are necessary in this
project given the existence of `refs/notes/amlog`.

🔗 https://lore.kernel.org/git/ebe188e5-7289-4f7b-b845-d59a47cd06fe@app.fastmail.com/

-- 
Kristoffer Haugsbakk



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2] date: make "iso-strict" conforming for the UTC timezone
  2024-03-13 18:30   ` Junio C Hamano
  2024-03-13 19:29     ` Osipov, Michael (IN IT IN)
@ 2024-03-13 22:29     ` Beat Bolli
  2024-03-13 22:42       ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Beat Bolli @ 2024-03-13 22:29 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Beat Bolli, Michael Osipov

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.

This changes an established output format which might be depended on by
scripts. The original patch 466fb6742d7f (pretty: provide a strict ISO
8601 date format, 2014-08-29) mentioned XML parsers as its rationale,
which generally have good parsing support, so this change should be
fine.

Reported-by: Michael Osipov <michael.osipov@innomotics.com>
Signed-off-by: Beat Bolli <dev+git@drbeat.li>
---
Changes from v1:

- added a comment why the change is fine
- removed the Link: trailer

 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'
-- 
2.44.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] date: make "iso-strict" conforming for the UTC timezone
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2024-03-13 22:42 UTC (permalink / raw
  To: Beat Bolli; +Cc: git, Beat Bolli, Michael Osipov

"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.
>
> This changes an established output format which might be depended on by
> scripts. The original patch 466fb6742d7f (pretty: provide a strict ISO
> 8601 date format, 2014-08-29) mentioned XML parsers as its rationale,
> which generally have good parsing support, so this change should be
> fine.

"fine." -> "fine for that particular usecase."

Unlike in 2005, we no longer write our features only for our own
single use case that motivated it.  I do not think it is possible
to make this change without breaking some real script, and admitting
this is a breaking change and we are knowingly doing so is probably
better in the longer term.

Saying "this should be fine" in the log will give future developers
room to consider reverting it, and while they are free to make such
a decision based on the reality at their time in the future, we
should give them a data point from our point of view: we know it may
break somebody but we are still doing so knowingly as upside to
adhere to a published standard and help those users who adhere to
the same standard is more valuable then the unfortunate script that
bended themselves to match our earlier mistake.

Thanks.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3] date: make "iso-strict" conforming for the UTC timezone
  2024-03-13 22:42       ` Junio C Hamano
@ 2024-03-13 22:54         ` Beat Bolli
  2024-03-13 23:06           ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Beat Bolli @ 2024-03-13 22:54 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Beat Bolli, Michael Osipov

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.

Changing an established output format which might be depended on by
scripts is always problematic, but here we choose to adhere more closely
to the published standard.

Reported-by: Michael Osipov <michael.osipov@innomotics.com>
Signed-off-by: Beat Bolli <dev+git@drbeat.li>
---
Changes from v2:

- changed the rationale according to Junio's feedback

Changes from v1:

- added a comment why the change is fine
- removed the Link: trailer

 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'
-- 
2.44.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] date: make "iso-strict" conforming for the UTC timezone
  2024-03-13 22:54         ` [PATCH v3] " Beat Bolli
@ 2024-03-13 23:06           ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2024-03-13 23:06 UTC (permalink / raw
  To: Beat Bolli; +Cc: git, Beat Bolli, Michael Osipov

"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.
>
> Changing an established output format which might be depended on by
> scripts is always problematic, but here we choose to adhere more closely
> to the published standard.

Perfect.  Thanks for following it through.  Will replace (I've
queued v2 already but it is easy to replace).

>
> Reported-by: Michael Osipov <michael.osipov@innomotics.com>
> Signed-off-by: Beat Bolli <dev+git@drbeat.li>
> ---
> Changes from v2:
>
> - changed the rationale according to Junio's feedback
>
> Changes from v1:
>
> - added a comment why the change is fine
> - removed the Link: trailer
>
>  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'


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-03-13 23:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).