Subject: bug#78096: 31.0.50; calendar-iso-to-absolute and %W time string format are inconsistent

From: Stephen Berman <[email-masked]>
Date: Sun, 27 Apr 2025 23:05:06 +0200

On Sun, 27 Apr 2025 15:28:43 +0000 Ihor Radchenko <[email-masked]> wrote:

> Hi,
>
> This bug was originally reported in
> https://orgmode.org/list/[email-masked]
>
> Consider the following:
>
> (calendar-gregorian-from-absolute
>   ;; First day of the second week of 2025
>   (calendar-iso-to-absolute (list 2 1 2025))) ; => 2025-01-06
>
> Now, let's try to format the same date using `format-time-string'
>
> (format-time-string
>   "%Y-%m-%d W%W"
>   (encode-time (parse-time-string "2025-01-06 00:00")))
> ;; => 2025-01-06 W01
>
> As you can see, week numbering is off by 1 between %W and
> `calendar-iso-to-absolute', which is unexpected.
>
> I believe that it is a bug.

The doc string of `format-time-string' says:

%U is the week number starting on Sunday, %W starting on Monday,
 %V the week number according to ISO 8601.

(format-time-string
  "%Y-%m-%d W%V"
  (encode-time (parse-time-string "2025-01-06 00:00")))
=> "2025-01-06 W02"

Maybe just starting the week on Monday does not guarantee that the
result is an ISO commercial date?

Steve Berman