From unknown Sun Jun 22 00:11:43 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74841: [PATCH] srfi-19: Fix ~V converter in date->string. Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 12 Dec 2024 21:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74841 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: 74841@debbugs.gnu.org Cc: Tomas Volf <~@wolfsden.cz> X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17340374462682 (code B ref -1); Thu, 12 Dec 2024 21:05:02 +0000 Received: (at submit) by debbugs.gnu.org; 12 Dec 2024 21:04:06 +0000 Received: from localhost ([127.0.0.1]:40585 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLqLn-0000gn-TU for submit@debbugs.gnu.org; Thu, 12 Dec 2024 16:04:05 -0500 Received: from lists.gnu.org ([209.51.188.17]:35496) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <~@wolfsden.cz>) id 1tLqLj-0000ga-Fo for submit@debbugs.gnu.org; Thu, 12 Dec 2024 16:03:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1tLqLi-00048o-2e for bug-guile@gnu.org; Thu, 12 Dec 2024 16:03:54 -0500 Received: from wolfsden.cz ([37.205.8.62]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1tLqLf-0005R6-OA for bug-guile@gnu.org; Thu, 12 Dec 2024 16:03:53 -0500 Received: by wolfsden.cz (Postfix, from userid 104) id C658235B32C; Thu, 12 Dec 2024 21:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1734037428; bh=uuodW7FBdAEGpBSqznpZU8i1BVZtibZR0LZPPlZv57M=; h=From:To:Cc:Subject:Date; b=jMTkzrZI/Q1IJ1l+CD0vK/jWPAX9Zi6kHADR98f+a/bHuq86W4MFPhV3oOPD3wTKU 2MouY2Y0N2AAAUQeVpzl3a25rqRX/ZXioC1sEZqZYnTxIv5waBDDrjN8RD5IrdHXo7 NI/PCNxt+0wiVhZEQetiH1IJ67D8eUe9v5Fqt3TKpxatQRJ77OhZS7B8dE8d063iIx Mod5R/tFkY3oQpxDtFRqB7y0dRhFHwLSWkT4AdnHDRdocHyLLqvuWUPf4SNb+aX4E1 5EAfAhbYr5dTagsZZhWKb+Lz1CNsf4FpffrABAh16dUMAcgTHnG76KG4dNOPa8MyPF hx/W7QK3n/IdRP4FFTzWMryO91W52aB8z8B5Jgyqee2WJfme056BpoRMa7Dstk99gN NysDoSETCjfWcDh88ucE2l+qy1xwqj61mcN0XcPpL2fSJm0MWgdjeDH0xP87oYN34P 3TgyucOJaRX56i/Ai3v6KkiboiyHr6i1kLR9yAvf2N2e9OXgsKQcVUEDnj/dMevDj2 Xjjb80+7Uy+W1yjoIYvJvDa0p0/kkbYiSJF3tXurWSGj8XWGDLLPB0sFt762pMYkQK 4pcckTucCLhhY/bzF13LMf7Pg9vNSbZ4YwlMBdmc8sGtSY1bH1NpXq0WR+9Dipfpvv C1lQSRMT3juallmzIj4Ybp1Y= X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on wolfsden X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (unknown [128.0.188.242]) by wolfsden.cz (Postfix) with ESMTPSA id 3E08B35C29B; Thu, 12 Dec 2024 21:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1734037428; bh=uuodW7FBdAEGpBSqznpZU8i1BVZtibZR0LZPPlZv57M=; h=From:To:Cc:Subject:Date; b=jMTkzrZI/Q1IJ1l+CD0vK/jWPAX9Zi6kHADR98f+a/bHuq86W4MFPhV3oOPD3wTKU 2MouY2Y0N2AAAUQeVpzl3a25rqRX/ZXioC1sEZqZYnTxIv5waBDDrjN8RD5IrdHXo7 NI/PCNxt+0wiVhZEQetiH1IJ67D8eUe9v5Fqt3TKpxatQRJ77OhZS7B8dE8d063iIx Mod5R/tFkY3oQpxDtFRqB7y0dRhFHwLSWkT4AdnHDRdocHyLLqvuWUPf4SNb+aX4E1 5EAfAhbYr5dTagsZZhWKb+Lz1CNsf4FpffrABAh16dUMAcgTHnG76KG4dNOPa8MyPF hx/W7QK3n/IdRP4FFTzWMryO91W52aB8z8B5Jgyqee2WJfme056BpoRMa7Dstk99gN NysDoSETCjfWcDh88ucE2l+qy1xwqj61mcN0XcPpL2fSJm0MWgdjeDH0xP87oYN34P 3TgyucOJaRX56i/Ai3v6KkiboiyHr6i1kLR9yAvf2N2e9OXgsKQcVUEDnj/dMevDj2 Xjjb80+7Uy+W1yjoIYvJvDa0p0/kkbYiSJF3tXurWSGj8XWGDLLPB0sFt762pMYkQK 4pcckTucCLhhY/bzF13LMf7Pg9vNSbZ4YwlMBdmc8sGtSY1bH1NpXq0WR+9Dipfpvv C1lQSRMT3juallmzIj4Ybp1Y= From: Tomas Volf <~@wolfsden.cz> Date: Thu, 12 Dec 2024 22:03:21 +0100 Message-ID: <20241212210322.32016-2-~@wolfsden.cz> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=37.205.8.62; envelope-from=~@wolfsden.cz; helo=wolfsden.cz X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) The ~V is supposed to print ISO week number, not a week number. This commit fixes that. * module/srfi/srfi-19.scm (date-week-number-iso): New procedure taken from the reference implementation. (directives)<#\V>: Use it. * test-suite/tests/srfi-19.test ("date->string ~V"): Add tests taken from the reference test suite. --- module/srfi/srfi-19.scm | 21 ++++++++++++- test-suite/tests/srfi-19.test | 57 ++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm index d809ac1ec..77be57a0e 100644 --- a/module/srfi/srfi-19.scm +++ b/module/srfi/srfi-19.scm @@ -753,6 +753,25 @@ (days-before-first-week date day-of-week-starting-week)) 7)) +(define (date-week-number-iso date) + ;; The week with the year's first Thursday is week 01. + (let* ((first-day-of-the-week (week-day 1 1 (date-year date))) + (offset (if (> first-day-of-the-week 4) 0 1)) + ;; -2: decrement one day to compensate 1-origin of date-year-day, + ;; and decrement one more day for Sunday belongs to the previous week. + (w (+ (floor-quotient (+ (date-year-day date) first-day-of-the-week -2) + 7) + offset))) + (cond ((zero? w) + ;; date belongs to the last week of the previous year + (date-week-number-iso (make-date 0 0 0 0 31 12 + (- (date-year date) 1) 0))) + ((and (= w 53) + (<= (week-day 1 1 (+ (date-year date) 1)) 4)) + ;; date belongs to the first week of the next year + 1) + (else w)))) + (define (current-date . tz-offset) (let ((time (current-time time-utc))) (time-utc->date @@ -1043,7 +1062,7 @@ (display (padding (date-week-number date 0) #\0 2) port)))) (cons #\V (lambda (date pad-with port) - (display (padding (date-week-number date 1) + (display (padding (date-week-number-iso date) #\0 2) port))) (cons #\w (lambda (date pad-with port) (display (date-week-day date) port))) diff --git a/test-suite/tests/srfi-19.test b/test-suite/tests/srfi-19.test index 55eb82320..5e3e1f445 100644 --- a/test-suite/tests/srfi-19.test +++ b/test-suite/tests/srfi-19.test @@ -412,7 +412,62 @@ incomplete numerical tower implementation.)" (with-test-prefix "date-week-number" (pass-if (= 0 (date-week-number (make-date 0 0 0 0 1 1 1984 0) 0))) (pass-if (= 0 (date-week-number (make-date 0 0 0 0 7 1 1984 0) 0))) - (pass-if (= 1 (date-week-number (make-date 0 0 0 0 8 1 1984 0) 0))))) + (pass-if (= 1 (date-week-number (make-date 0 0 0 0 8 1 1984 0) 0)))) + + (let ((convert (λ (lst) + (date->string + (make-date 0 0 0 0 + (caddr lst) (cadr lst) (car lst) + 0) + "~V")))) + (with-test-prefix "date->string ~V" + (pass-if-equal "Thursday, week 53" "53" + (convert '(2020 12 31))) + (pass-if-equal "Friday, week 53 (previous year)" "53" + (convert '(2021 1 1))) + (pass-if-equal "Sunday, week 53 (previous year)" "53" + (convert '(2021 1 3))) + (pass-if-equal "Monday, week 1" "01" + (convert '(2021 1 4))) + + (pass-if-equal "Sunday, week 52" "52" + (convert '(2019 12 29))) + (pass-if-equal "Monday, week 1 (next year)" "01" + (convert '(2019 12 30))) + (pass-if-equal "Tuesday, week 1 (next year)" "01" + (convert '(2019 12 31))) + (pass-if-equal "Wednesday, week 1" "01" + (convert '(2020 1 1))) + + (pass-if-equal "Saturday, week 52" "52" + (convert '(2016 12 31))) + (pass-if-equal "Sunday, week 52 (previous year)" "52" + (convert '(2017 1 1))) + (pass-if-equal "Monday, week 1" "01" + (convert '(2017 1 2))) + (pass-if-equal "Sunday, week 1" "01" + (convert '(2017 1 8))) + (pass-if-equal "Monday, week 2" "02" + (convert '(2017 1 9))) + + (pass-if-equal "Sunday, week 52" "52" + (convert '(2014 12 28))) + (pass-if-equal "Monday, week 1 (next year)" "01" + (convert '(2014 12 29))) + (pass-if-equal "Tuesday, week 1 (next year)" "01" + (convert '(2014 12 30))) + (pass-if-equal "Wednesday, week 1 (next year)" "01" + (convert '(2014 12 31))) + (pass-if-equal "Thursday, week 1" "01" + (convert '(2015 1 1))) + (pass-if-equal "Friday, week 1" "01" + (convert '(2015 1 2))) + (pass-if-equal "Saturday, week 1" "01" + (convert '(2015 1 3))) + (pass-if-equal "Sunday, week 1" "01" + (convert '(2015 1 4))) + (pass-if-equal "Monday, week 2" "02" + (convert '(2015 1 5)))))) ;; Local Variables: -- 2.46.0 From unknown Sun Jun 22 00:11:43 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74841: [PATCH] srfi-19: Fix ~V converter in date->string. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 22 Dec 2024 21:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74841 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: Tomas Volf <~@wolfsden.cz> Cc: 74841@debbugs.gnu.org Received: via spool by 74841-submit@debbugs.gnu.org id=B74841.173490371111896 (code B ref 74841); Sun, 22 Dec 2024 21:42:02 +0000 Received: (at 74841) by debbugs.gnu.org; 22 Dec 2024 21:41:51 +0000 Received: from localhost ([127.0.0.1]:52228 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPThv-00035n-9e for submit@debbugs.gnu.org; Sun, 22 Dec 2024 16:41:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37782) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPTht-00035a-DR for 74841@debbugs.gnu.org; Sun, 22 Dec 2024 16:41:50 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPThn-0001Ku-Iq; Sun, 22 Dec 2024 16:41:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=2ccBUc2a9f0X+UTaINEXndiQ5I+bIpNfy6HgZwZsfdU=; b=NGNOK/KmSs+VsXClHqPS ddrV2348D/dBcQv0Sz4r6HMb0yRz6tbGD7fHMPh7Uv016/vqVYgBDmY+CdhmIe2HfZOgpaEN88g0F AsXwOINB3hpgXLlr36qbdh0030U5Z1ZnrfpuFYRGposJyMidk00iK/diAsoxLS428hA6iuTCR3VZa z4d1UCI5ySjJdXTJlp8nQx8kq91PaBJlUneOtYVBOFK2SegI+55MH+4OYU8dVwqrywegeVgNlSiEK pUf3lrMLSsDqI5sBWacqkSmc26DLFift8u2cDiGAJY3Z0YCbQ/Eynfzj2UKW6TVhlma0iB0axK9fB jy7YOvBw5OvG7A==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <20241212210322.32016-2-~@wolfsden.cz> (Tomas Volf's message of "Thu, 12 Dec 2024 22:03:21 +0100") References: <20241212210322.32016-2-~@wolfsden.cz> Date: Sun, 22 Dec 2024 22:41:41 +0100 Message-ID: <87bjx3fl9m.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, Tomas Volf <~@wolfsden.cz> skribis: > The ~V is supposed to print ISO week number, not a week number. This > commit fixes that. > > * module/srfi/srfi-19.scm (date-week-number-iso): New procedure taken > from the reference implementation. > (directives)<#\V>: Use it. > * test-suite/tests/srfi-19.test ("date->string ~V"): Add tests taken > from the reference test suite. The manual just reads this: ~U week of year, Sunday first day of week, =E2=80=9800=E2=80=99 to =E2=80=9852=E2=80=99 ~V week of year, Monday first day of week, =E2=80=9801=E2=80=99 to =E2=80=9853=E2=80=99 Should it be fixed or clarified? > +(define (date-week-number-iso date) Please add a docstring. > + (let ((convert (=CE=BB (lst) > + (date->string > + (make-date 0 0 0 0 > + (caddr lst) (cadr lst) (car lst) Please use =E2=80=98match-lambda=E2=80=99. > + (with-test-prefix "date->string ~V" > + (pass-if-equal "Thursday, week 53" "53" If these are from the SRFI-19 spec, could you add a comment to say so? Thanks, Ludo=E2=80=99. From unknown Sun Jun 22 00:11:43 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74841: [PATCH v2] srfi-19: Fix ~V converter in date->string. References: <20241212210322.32016-2-~@wolfsden.cz> In-Reply-To: <20241212210322.32016-2-~@wolfsden.cz> Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 24 Jan 2025 16:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74841 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: 74841@debbugs.gnu.org Cc: Tomas Volf <~@wolfsden.cz> Received: via spool by 74841-submit@debbugs.gnu.org id=B74841.1737735823880 (code B ref 74841); Fri, 24 Jan 2025 16:24:02 +0000 Received: (at 74841) by debbugs.gnu.org; 24 Jan 2025 16:23:43 +0000 Received: from localhost ([127.0.0.1]:46678 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tbMT9-0000E8-0d for submit@debbugs.gnu.org; Fri, 24 Jan 2025 11:23:43 -0500 Received: from wolfsden.cz ([37.205.8.62]:37818) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <~@wolfsden.cz>) id 1tbMT6-0000Dv-8j for 74841@debbugs.gnu.org; Fri, 24 Jan 2025 11:23:41 -0500 Received: by wolfsden.cz (Postfix, from userid 104) id D1D4733DB0D; Fri, 24 Jan 2025 16:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1737735817; bh=3FpVS9i2RBZKGigpQd74LD5w0A70apJomN+uBEjT6aI=; h=From:To:Cc:Subject:Date; b=ABu1vSY7N3DaCGP+HEUzARQAzsdMvdeZZR3OF+dxCFfMeeKATmVuegtAtQoviZarz u8uK4W7G7OQyx4wpCz82xpbuzF9FUDUouDhUHGyTAS2stJR7i//JcYkYFzhsL9FkZX uqsWXIFGjck1itS5T1VyLdawBpk1tRWTDFpsRv9jBvUh4a08oMMju2cMPZ8t81d4cv VWBngatLQpbTPzS+vZf2vLaRNVjZewJrgcMgOccmHi2Iwc924CDrprbFbKnEUZMUqG 9XfYtarIiQS2o7AlTK9drRiPPDsP1KkY1/0x5X5YKOPtlTw20wZ9wQ7J1G0uClm1xs eH5nbybbcwlEgxs4BkfPPI/yBCAdpyxp+VybVHUNpNmZ3M7blYkusIMuvRWBMgRZMB B+oFZP2tXzDcL/cSzYPrmQrFPcIlPiTn1GsprCOWYCVPvfWOMbRLvhc315j2CCfJnZ yg93nbkjEqaFLgLlvi5TKp0m/vV+D3r/S8OwfLZb5QYE/bjqJ2x5SvR4IzVjturolW W7jX+1Wq8yDkwarxIziP6DFWSW8KY4z1kq+XS2ngYM6efZ0uZuUjz8mX3sdB0tGkQ4 LoNlkZPwEgYoO/dD5wKDHy+Tq7xbCiZ5VZGhEqsjjJqUuguxL1pbla5nEFwTj8djpI yPWdyw66YvhLlPhpRWTV6+es= X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on wolfsden X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=unavailable autolearn_force=no version=3.4.6 Received: from localhost (unknown [128.0.188.242]) by wolfsden.cz (Postfix) with ESMTPSA id 755D333DA06; Fri, 24 Jan 2025 16:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1737735816; bh=3FpVS9i2RBZKGigpQd74LD5w0A70apJomN+uBEjT6aI=; h=From:To:Cc:Subject:Date; b=pjo0Kq248YV+EtbuwC0lYcxcN/aBQ+CqQjlFejmPesYDffqKctys8rYyLFHCmqDvm KoilKbi1oO+XLGNSWQsaD1kJ4AuGqFb6ZZXQCfLrrADbtuzUWfsq560Gqmk7N0FZrC 98BKFiQnvhB+4oP56zlgRLCytc79wN/BWFz4GpVZsAhzuGGYxYvUPHXIZ03U81f4T4 44XXYRW4fmoDOaaWT7amhGmdtCFMIn4zzPeQp7b1f3IVYGjyA9nIg4he669bdzv1g4 7pLgLYfaMk+0VgbjfmXrsf2SHZzYCfR/udiC7DOGpUzJwcR8jJE2auZiaEh7HNzGwF nQIYJrtKV7YVuyxw19ZHrXQwQSQWi5n8UGtUdQmGXapfraln9FF1q9LCo2JjE2CgKS ryNWTjb3gmquv/WLpYpsAU6IVgxgz5BV7xgupsrnXFGYmMHGd2zICz8Jsv+mDGOWyx fcutBpebLnadWShwYwiQXugjjaPHdEqJZIWwgmEUDuFF+PdgXF9a+0L3WrPr0tBhcq Lnj9UP0tBd6+oDB+wvGRjDupudpW8CiiM0zoOsYdda+Ei7flFjlWl5pBjbjWCEg5ha /Dm0t+xw0akfORxGBdTfEBUfWegD8gCdbWxKkBPiR+M41rThsazXQ/V8Uh61ZJWnir LHnMUYd3QEekzrPTRvEcsGHQ= From: Tomas Volf <~@wolfsden.cz> Date: Fri, 24 Jan 2025 17:23:17 +0100 Message-ID: <20250124162317.11065-1-~@wolfsden.cz> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) The ~V is supposed to print ISO week number, not a week number. This commit fixes that. * module/srfi/srfi-19.scm (date-week-number-iso): New procedure taken from the reference implementation. (directives)<#\V>: Use it. * test-suite/tests/srfi-19.test ("date->string ~V"): Add tests taken from the reference test suite. * doc/ref/srfi-modules.texi (SRFI-19 Date to string): Mention ISO-8601 in description for ~V. --- doc/ref/srfi-modules.texi | 4 +-- module/srfi/srfi-19.scm | 24 +++++++++++++- test-suite/tests/srfi-19.test | 60 +++++++++++++++++++++++++++++++++-- 3 files changed, 83 insertions(+), 5 deletions(-) diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi index f072e6c3f..0b663902e 100644 --- a/doc/ref/srfi-modules.texi +++ b/doc/ref/srfi-modules.texi @@ -2864,8 +2864,8 @@ with locale decimal point, eg.@: @samp{5.2} @item @nicode{~T} @tab time, 24 hour clock, @samp{~H:~M:~S} @item @nicode{~U} @tab week of year, Sunday first day of week, @samp{00} to @samp{52} -@item @nicode{~V} @tab week of year, Monday first day of week, -@samp{01} to @samp{53} +@item @nicode{~V} @tab ISO 8601 week number of the year, +Monday first day of week, @samp{01} to @samp{53} @item @nicode{~w} @tab day of week, 0 for Sunday, @samp{0} to @samp{6} @item @nicode{~W} @tab week of year, Monday first day of week, @samp{00} to @samp{52} diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm index d809ac1ec..7ab0ad6dd 100644 --- a/module/srfi/srfi-19.scm +++ b/module/srfi/srfi-19.scm @@ -753,6 +753,28 @@ (days-before-first-week date day-of-week-starting-week)) 7)) +;;; Taken from the reference implementation. Modified to fit Guile's +;;; code style. +(define (date-week-number-iso date) + "Return a ISO-8601 week number for the @var{date}." + ;; The week with the year's first Thursday is week 01. + (let* ((first-day-of-the-week (week-day 1 1 (date-year date))) + (offset (if (> first-day-of-the-week 4) 0 1)) + ;; -2: decrement one day to compensate 1-origin of date-year-day, + ;; and decrement one more day for Sunday belongs to the previous week. + (w (+ (floor-quotient (+ (date-year-day date) first-day-of-the-week -2) + 7) + offset))) + (cond ((zero? w) + ;; date belongs to the last week of the previous year + (date-week-number-iso (make-date 0 0 0 0 31 12 + (- (date-year date) 1) 0))) + ((and (= w 53) + (<= (week-day 1 1 (+ (date-year date) 1)) 4)) + ;; date belongs to the first week of the next year + 1) + (else w)))) + (define (current-date . tz-offset) (let ((time (current-time time-utc))) (time-utc->date @@ -1043,7 +1065,7 @@ (display (padding (date-week-number date 0) #\0 2) port)))) (cons #\V (lambda (date pad-with port) - (display (padding (date-week-number date 1) + (display (padding (date-week-number-iso date) #\0 2) port))) (cons #\w (lambda (date pad-with port) (display (date-week-day date) port))) diff --git a/test-suite/tests/srfi-19.test b/test-suite/tests/srfi-19.test index 55eb82320..3cacff669 100644 --- a/test-suite/tests/srfi-19.test +++ b/test-suite/tests/srfi-19.test @@ -26,7 +26,8 @@ #:use-module (test-suite lib) #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) - #:use-module (ice-9 format)) + #:use-module (ice-9 format) + #:use-module (ice-9 match)) ;; Make sure we use the default locale. (when (defined? 'setlocale) @@ -412,7 +413,62 @@ incomplete numerical tower implementation.)" (with-test-prefix "date-week-number" (pass-if (= 0 (date-week-number (make-date 0 0 0 0 1 1 1984 0) 0))) (pass-if (= 0 (date-week-number (make-date 0 0 0 0 7 1 1984 0) 0))) - (pass-if (= 1 (date-week-number (make-date 0 0 0 0 8 1 1984 0) 0))))) + (pass-if (= 1 (date-week-number (make-date 0 0 0 0 8 1 1984 0) 0)))) + + (let ((convert (match-lambda + ((y m d) + (date->string (make-date 0 0 0 0 d m y 0) + "~V"))))) + ;; The test cases are taken from the test suite for the reference + ;; implementation. + (with-test-prefix "date->string ~V" + (pass-if-equal "Thursday, week 53" "53" + (convert '(2020 12 31))) + (pass-if-equal "Friday, week 53 (previous year)" "53" + (convert '(2021 1 1))) + (pass-if-equal "Sunday, week 53 (previous year)" "53" + (convert '(2021 1 3))) + (pass-if-equal "Monday, week 1" "01" + (convert '(2021 1 4))) + + (pass-if-equal "Sunday, week 52" "52" + (convert '(2019 12 29))) + (pass-if-equal "Monday, week 1 (next year)" "01" + (convert '(2019 12 30))) + (pass-if-equal "Tuesday, week 1 (next year)" "01" + (convert '(2019 12 31))) + (pass-if-equal "Wednesday, week 1" "01" + (convert '(2020 1 1))) + + (pass-if-equal "Saturday, week 52" "52" + (convert '(2016 12 31))) + (pass-if-equal "Sunday, week 52 (previous year)" "52" + (convert '(2017 1 1))) + (pass-if-equal "Monday, week 1" "01" + (convert '(2017 1 2))) + (pass-if-equal "Sunday, week 1" "01" + (convert '(2017 1 8))) + (pass-if-equal "Monday, week 2" "02" + (convert '(2017 1 9))) + + (pass-if-equal "Sunday, week 52" "52" + (convert '(2014 12 28))) + (pass-if-equal "Monday, week 1 (next year)" "01" + (convert '(2014 12 29))) + (pass-if-equal "Tuesday, week 1 (next year)" "01" + (convert '(2014 12 30))) + (pass-if-equal "Wednesday, week 1 (next year)" "01" + (convert '(2014 12 31))) + (pass-if-equal "Thursday, week 1" "01" + (convert '(2015 1 1))) + (pass-if-equal "Friday, week 1" "01" + (convert '(2015 1 2))) + (pass-if-equal "Saturday, week 1" "01" + (convert '(2015 1 3))) + (pass-if-equal "Sunday, week 1" "01" + (convert '(2015 1 4))) + (pass-if-equal "Monday, week 2" "02" + (convert '(2015 1 5)))))) ;; Local Variables: -- 2.47.1 From unknown Sun Jun 22 00:11:43 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74841: [PATCH] srfi-19: Fix ~V converter in date->string. Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 24 Jan 2025 16:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74841 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 74841@debbugs.gnu.org Received: via spool by 74841-submit@debbugs.gnu.org id=B74841.1737735837922 (code B ref 74841); Fri, 24 Jan 2025 16:24:02 +0000 Received: (at 74841) by debbugs.gnu.org; 24 Jan 2025 16:23:57 +0000 Received: from localhost ([127.0.0.1]:46683 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tbMTM-0000Eo-Ke for submit@debbugs.gnu.org; Fri, 24 Jan 2025 11:23:56 -0500 Received: from wolfsden.cz ([37.205.8.62]:53930) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <~@wolfsden.cz>) id 1tbMTK-0000Ea-Ht for 74841@debbugs.gnu.org; Fri, 24 Jan 2025 11:23:55 -0500 Received: by wolfsden.cz (Postfix, from userid 104) id 8F30433CA28; Fri, 24 Jan 2025 16:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1737735833; bh=EH6jKFqAiG/D35qs2rI5xOo3k8E+cG8aFts8DMoSO94=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=NBpTFmdeFo8qyC6F02S7zPUGDA9Hv3I9SQL5NURY/W2sscBvZudmaxzHvnz9nzUvR kowBJbOLOX+GA0zzt3U72AGZiR14D7KwjikYJXLmYpIvyFbxiOoi8Mz6mZaQIfjYzP 6OhRIl0dOt8KEWGm0kyq7HdVYdEhw1jYUN6SHAxijm3BC2yYLxVjD1kiPihTPXx8Vq A+f6v49K/eHj153zZAYPxR49QtsRkKJcc94t9n2oG8dFzQsJIGTzzLvDh7KLBaMBXl sEsEvFiPQhiTUFkY52jCfX48/FlniCVgH5yQRq0wwB9AQKKx6D3FJ7wPiNNc42bZmd 9n++icYNqbuSgk1cikgz1wI5pp2ksPQfkEgeF1YY6jML81wqbL9e9hWTZw5SXAcNDY nntA376MfXa768/6XLNWQYDP8tsTwya/6K73t8tGNWxtmtN6zteAt9zL7HHYadqnQZ Yl4flBe303/ij5jDk2GpbHmIxR01Ye3S+kFHJpAp9KeV+O2O5MhYB/MqfI0tNJ3ae3 u92LF4zYMqoSMq2dLRKWdihpAIeKfMWXL2Y1KaSwQySKJ0P6O4IMtCHjSaA0Ov4sUS kmfZzrl5M1w39lAqGaM7cJgGy2nYgcDTIuZZf1gyrWry3IwiLO+5Ba3NcSdNa4YZ+i CaDAuF2xejPnE8JNJeTTOZnQ= X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on wolfsden X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=unavailable autolearn_force=no version=3.4.6 Received: from localhost (unknown [128.0.188.242]) by wolfsden.cz (Postfix) with ESMTPSA id DB6C433CD30; Fri, 24 Jan 2025 16:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1737735831; bh=EH6jKFqAiG/D35qs2rI5xOo3k8E+cG8aFts8DMoSO94=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=ifhWD/rVP0VN3anZOB7s4Q27Ps180r0HIQDYTYLaTIMUejXrW5A8A4k2AIkaF0FhW P6O5shDtM0fdu4IFbzE12fwqHkdf4O+vEiLni+iTfdHkVa8IyE+FWDK2tSz49JLZgQ OI/qYy8kxJibl9MckBbFySzVSlnps4DmmNPbN3q1fJbv15p/gg7QrEktWdugDDq559 Jk6ftCxFitgoaioFc0TZ116RaLOjvLRLJ7086NEmaCJpuSJ6/YhOwF8vn3xwpBVjU+ BnWKbwibpMoDQs1sNlj+vi9hpZrAIHWq8Fz0tMvjG+XYfUBb91SfeFCSWk/nhfi4DO YqlStK4K/gc9LWo/mH/Y3vHAwYHnO1asynRtooGsUr7TyqM3uDYh/k16aXzLKIGFJX Ad7RZ4uInSURGn1ii0U5n9q7ijJAdu98DGX4MGunR1gYR/SihuoeeQNFWiMg6MSKG5 jL5f5WJe5yrXNQrvawa6QtqvmQ4zlvPIs6fqWP2jw5kztN7r2fkXrR5MVKKSS0hqqd UFhuVCZ8rBsA8FRqTm+Rl+qUtTs5VMMuC5jpjUC05a1mdFyRlO3cAgaCUEhJFw9qH2 8ls53YhBO50r7vHwnXq8KwIxeWP2ghaWEe6IiJ0n8VXMBw5Z9GbhJOC2kZOSWLw+Dt DhcmkGV1wG1nD4LwzlVytfd8= From: Tomas Volf <~@wolfsden.cz> In-Reply-To: <87bjx3fl9m.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Sun, 22 Dec 2024 22:41:41 +0100") References: <20241212210322.32016-2-~@wolfsden.cz> <87bjx3fl9m.fsf@gnu.org> Date: Fri, 24 Jan 2025 17:23:51 +0100 Message-ID: <87v7u4i3jc.fsf@wolfsden.cz> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: > Hi, > > Tomas Volf <~@wolfsden.cz> skribis: > >> The ~V is supposed to print ISO week number, not a week number. This >> commit fixes that. >> >> * module/srfi/srfi-19.scm (date-week-number-iso): New procedure taken >> from the reference implementation. >> (directives)<#\V>: Use it. >> * test-suite/tests/srfi-19.test ("date->string ~V"): Add tests taken >> from the reference test suite. > > The manual just reads this: > > ~U week of year, Sunday first day of week, =E2=80=9800=E2=80=99 = to > =E2=80=9852=E2=80=99 > ~V week of year, Monday first day of week, =E2=80=9801=E2=80=99 = to > =E2=80=9853=E2=80=99 > > Should it be fixed or clarified? Definitely, updated to reference the ISO-8601. > >> +(define (date-week-number-iso date) > > Please add a docstring. Done. > >> + (let ((convert (=CE=BB (lst) >> + (date->string >> + (make-date 0 0 0 0 >> + (caddr lst) (cadr lst) (car lst) > > Please use =E2=80=98match-lambda=E2=80=99. Yeah that is much nicer. > >> + (with-test-prefix "date->string ~V" >> + (pass-if-equal "Thursday, week 53" "53" > > If these are from the SRFI-19 spec, could you add a comment to say so? Good point, done. > > Thanks, > Ludo=E2=80=99. =2D- There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJCBAEBCgAsFiEEt4NJs4wUfTYpiGikL7/ufbZ/wakFAmeTvpcOHH5Ad29sZnNk ZW4uY3oACgkQL7/ufbZ/wamH+BAAiEGp/4RUciXN0pTaswTR+MS70Bulc4601Ck7 RcntRbg/9D+L2M5OTkFOAbnQXBcQ8AuLj6+b9a5pyO+4W9N8REIPH4vr0EyYoyyd 6yHNOwOWeW0/U1lpPGLH6Ftav7S190ATwOgJXdWeOVL6TzpzUmyAPEopc2/J6uVw CD2uzHZJ1x3tEAxFQxhxRmCq0P0kV6M54TuD76wBTA+2sq27XdH3Au35YUcQEM13 7ALguLc4AS+79mG21JsBaEvbjsdqzrHU4CPjB8xtU3M30/JZ/Cr6VFYHlkaETi7n /vYy3wKec+o8/6Qa1YzYOCnoiVXz25gBJymcyvAsQLQMQu6l+ua0xhM9QyFWS/NR ZnSjScJoC7qEkxCGpdZAmRX8HuPfM0KDQjH6M4JYvwW+NVIND2LKKwqvUhMV06z8 18jwkn8d8O5Xc8GPr9iLDZrjzFmto/No2gLma+5FnnP9iu6QfJJme+W4u5OO0hGy f4k7xIhSlJIyCFRUlYeKX/23CFSoEMA9aIm3Czn0NA6TJBbrI9TAHranVMSYHevW +wC4MRq4IWJhYb1DKu0OIzPAkaDBteD5uQd2ZWhh2IJQeuAQEVbGY9DCjClZu4rC XBZ4tCslfST21MXLU/CfacbmNAlmLehZCXmWqTtQGomDvovV+5JnsFKJjSTHSnaz Xc48alo= =n5y1 -----END PGP SIGNATURE----- --=-=-=-- From unknown Sun Jun 22 00:11:43 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Tomas Volf <~@wolfsden.cz> Subject: bug#74841: closed (Re: bug#74841: [PATCH v2] srfi-19: Fix ~V converter in date->string.) Message-ID: References: <874j0dpzqh.fsf@gnu.org> <20241212210322.32016-2-~@wolfsden.cz> X-Gnu-PR-Message: they-closed 74841 X-Gnu-PR-Package: guile X-Gnu-PR-Keywords: patch Reply-To: 74841@debbugs.gnu.org Date: Fri, 28 Feb 2025 20:44:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1740775443-3129-1" This is a multi-part message in MIME format... ------------=_1740775443-3129-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #74841: [PATCH] srfi-19: Fix ~V converter in date->string. which was filed against the guile package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 74841@debbugs.gnu.org. --=20 74841: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D74841 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1740775443-3129-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 74841-done) by debbugs.gnu.org; 28 Feb 2025 20:43:19 +0000 Received: from localhost ([127.0.0.1]:53616 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1to7CY-0000kX-Se for submit@debbugs.gnu.org; Fri, 28 Feb 2025 15:43:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51282) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1to7CT-0000j6-31 for 74841-done@debbugs.gnu.org; Fri, 28 Feb 2025 15:43:16 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1to7CL-0004y9-UW; Fri, 28 Feb 2025 15:43:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=gf+GIboQzFYtpweHcqbHZS9fpSVOBijLE4pDudtaKPQ=; b=bNpiJb+W/br7pIH+wUI6 HAavjM4IwYXM64mCkD4RC/BT5WC/liXqWTaCWfDPO8VZVrMcoDpafClbhbYjjy3YzcUyA7baANvst huMkjebSJLOoIZRVTfoAPa35+E9Q9YE2022ouXPQCnNk2lXTINCEKp4if3rIQ0GpEOf5ZdTOcvanE yla+3MIDvIB2KYIiwN9D46De5iFTFpX5nJsN83t/p0smYuUQlpneh/7LdW11vJdMCHR/0lAwqMxBz E1k+RhJb8SKM9Ocuj0o0vpvFaNhKJyE/wfllg6ms9OObOTPJpu0bJWRFF96/nVuhN/1cwGTOVAnEJ xMHYWwpDTcNgvA==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Tomas Volf <~@wolfsden.cz> Subject: Re: bug#74841: [PATCH v2] srfi-19: Fix ~V converter in date->string. In-Reply-To: <20250124162317.11065-1-~@wolfsden.cz> (Tomas Volf's message of "Fri, 24 Jan 2025 17:23:17 +0100") References: <20241212210322.32016-2-~@wolfsden.cz> <20250124162317.11065-1-~@wolfsden.cz> Date: Fri, 28 Feb 2025 21:43:02 +0100 Message-ID: <874j0dpzqh.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 74841-done Cc: 74841-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Tomas Volf <~@wolfsden.cz> skribis: > The ~V is supposed to print ISO week number, not a week number. This > commit fixes that. > > * module/srfi/srfi-19.scm (date-week-number-iso): New procedure taken > from the reference implementation. > (directives)<#\V>: Use it. > * test-suite/tests/srfi-19.test ("date->string ~V"): Add tests taken > from the reference test suite. > * doc/ref/srfi-modules.texi (SRFI-19 Date to string): Mention ISO-8601 > in description for ~V. Applied, thanks! ------------=_1740775443-3129-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 12 Dec 2024 21:04:06 +0000 Received: from localhost ([127.0.0.1]:40585 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLqLn-0000gn-TU for submit@debbugs.gnu.org; Thu, 12 Dec 2024 16:04:05 -0500 Received: from lists.gnu.org ([209.51.188.17]:35496) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <~@wolfsden.cz>) id 1tLqLj-0000ga-Fo for submit@debbugs.gnu.org; Thu, 12 Dec 2024 16:03:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1tLqLi-00048o-2e for bug-guile@gnu.org; Thu, 12 Dec 2024 16:03:54 -0500 Received: from wolfsden.cz ([37.205.8.62]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1tLqLf-0005R6-OA for bug-guile@gnu.org; Thu, 12 Dec 2024 16:03:53 -0500 Received: by wolfsden.cz (Postfix, from userid 104) id C658235B32C; Thu, 12 Dec 2024 21:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1734037428; bh=uuodW7FBdAEGpBSqznpZU8i1BVZtibZR0LZPPlZv57M=; h=From:To:Cc:Subject:Date; b=jMTkzrZI/Q1IJ1l+CD0vK/jWPAX9Zi6kHADR98f+a/bHuq86W4MFPhV3oOPD3wTKU 2MouY2Y0N2AAAUQeVpzl3a25rqRX/ZXioC1sEZqZYnTxIv5waBDDrjN8RD5IrdHXo7 NI/PCNxt+0wiVhZEQetiH1IJ67D8eUe9v5Fqt3TKpxatQRJ77OhZS7B8dE8d063iIx Mod5R/tFkY3oQpxDtFRqB7y0dRhFHwLSWkT4AdnHDRdocHyLLqvuWUPf4SNb+aX4E1 5EAfAhbYr5dTagsZZhWKb+Lz1CNsf4FpffrABAh16dUMAcgTHnG76KG4dNOPa8MyPF hx/W7QK3n/IdRP4FFTzWMryO91W52aB8z8B5Jgyqee2WJfme056BpoRMa7Dstk99gN NysDoSETCjfWcDh88ucE2l+qy1xwqj61mcN0XcPpL2fSJm0MWgdjeDH0xP87oYN34P 3TgyucOJaRX56i/Ai3v6KkiboiyHr6i1kLR9yAvf2N2e9OXgsKQcVUEDnj/dMevDj2 Xjjb80+7Uy+W1yjoIYvJvDa0p0/kkbYiSJF3tXurWSGj8XWGDLLPB0sFt762pMYkQK 4pcckTucCLhhY/bzF13LMf7Pg9vNSbZ4YwlMBdmc8sGtSY1bH1NpXq0WR+9Dipfpvv C1lQSRMT3juallmzIj4Ybp1Y= X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on wolfsden X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (unknown [128.0.188.242]) by wolfsden.cz (Postfix) with ESMTPSA id 3E08B35C29B; Thu, 12 Dec 2024 21:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1734037428; bh=uuodW7FBdAEGpBSqznpZU8i1BVZtibZR0LZPPlZv57M=; h=From:To:Cc:Subject:Date; b=jMTkzrZI/Q1IJ1l+CD0vK/jWPAX9Zi6kHADR98f+a/bHuq86W4MFPhV3oOPD3wTKU 2MouY2Y0N2AAAUQeVpzl3a25rqRX/ZXioC1sEZqZYnTxIv5waBDDrjN8RD5IrdHXo7 NI/PCNxt+0wiVhZEQetiH1IJ67D8eUe9v5Fqt3TKpxatQRJ77OhZS7B8dE8d063iIx Mod5R/tFkY3oQpxDtFRqB7y0dRhFHwLSWkT4AdnHDRdocHyLLqvuWUPf4SNb+aX4E1 5EAfAhbYr5dTagsZZhWKb+Lz1CNsf4FpffrABAh16dUMAcgTHnG76KG4dNOPa8MyPF hx/W7QK3n/IdRP4FFTzWMryO91W52aB8z8B5Jgyqee2WJfme056BpoRMa7Dstk99gN NysDoSETCjfWcDh88ucE2l+qy1xwqj61mcN0XcPpL2fSJm0MWgdjeDH0xP87oYN34P 3TgyucOJaRX56i/Ai3v6KkiboiyHr6i1kLR9yAvf2N2e9OXgsKQcVUEDnj/dMevDj2 Xjjb80+7Uy+W1yjoIYvJvDa0p0/kkbYiSJF3tXurWSGj8XWGDLLPB0sFt762pMYkQK 4pcckTucCLhhY/bzF13LMf7Pg9vNSbZ4YwlMBdmc8sGtSY1bH1NpXq0WR+9Dipfpvv C1lQSRMT3juallmzIj4Ybp1Y= From: Tomas Volf <~@wolfsden.cz> To: bug-guile@gnu.org Subject: [PATCH] srfi-19: Fix ~V converter in date->string. Date: Thu, 12 Dec 2024 22:03:21 +0100 Message-ID: <20241212210322.32016-2-~@wolfsden.cz> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=37.205.8.62; envelope-from=~@wolfsden.cz; helo=wolfsden.cz X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Tomas Volf <~@wolfsden.cz> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) The ~V is supposed to print ISO week number, not a week number. This commit fixes that. * module/srfi/srfi-19.scm (date-week-number-iso): New procedure taken from the reference implementation. (directives)<#\V>: Use it. * test-suite/tests/srfi-19.test ("date->string ~V"): Add tests taken from the reference test suite. --- module/srfi/srfi-19.scm | 21 ++++++++++++- test-suite/tests/srfi-19.test | 57 ++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm index d809ac1ec..77be57a0e 100644 --- a/module/srfi/srfi-19.scm +++ b/module/srfi/srfi-19.scm @@ -753,6 +753,25 @@ (days-before-first-week date day-of-week-starting-week)) 7)) +(define (date-week-number-iso date) + ;; The week with the year's first Thursday is week 01. + (let* ((first-day-of-the-week (week-day 1 1 (date-year date))) + (offset (if (> first-day-of-the-week 4) 0 1)) + ;; -2: decrement one day to compensate 1-origin of date-year-day, + ;; and decrement one more day for Sunday belongs to the previous week. + (w (+ (floor-quotient (+ (date-year-day date) first-day-of-the-week -2) + 7) + offset))) + (cond ((zero? w) + ;; date belongs to the last week of the previous year + (date-week-number-iso (make-date 0 0 0 0 31 12 + (- (date-year date) 1) 0))) + ((and (= w 53) + (<= (week-day 1 1 (+ (date-year date) 1)) 4)) + ;; date belongs to the first week of the next year + 1) + (else w)))) + (define (current-date . tz-offset) (let ((time (current-time time-utc))) (time-utc->date @@ -1043,7 +1062,7 @@ (display (padding (date-week-number date 0) #\0 2) port)))) (cons #\V (lambda (date pad-with port) - (display (padding (date-week-number date 1) + (display (padding (date-week-number-iso date) #\0 2) port))) (cons #\w (lambda (date pad-with port) (display (date-week-day date) port))) diff --git a/test-suite/tests/srfi-19.test b/test-suite/tests/srfi-19.test index 55eb82320..5e3e1f445 100644 --- a/test-suite/tests/srfi-19.test +++ b/test-suite/tests/srfi-19.test @@ -412,7 +412,62 @@ incomplete numerical tower implementation.)" (with-test-prefix "date-week-number" (pass-if (= 0 (date-week-number (make-date 0 0 0 0 1 1 1984 0) 0))) (pass-if (= 0 (date-week-number (make-date 0 0 0 0 7 1 1984 0) 0))) - (pass-if (= 1 (date-week-number (make-date 0 0 0 0 8 1 1984 0) 0))))) + (pass-if (= 1 (date-week-number (make-date 0 0 0 0 8 1 1984 0) 0)))) + + (let ((convert (λ (lst) + (date->string + (make-date 0 0 0 0 + (caddr lst) (cadr lst) (car lst) + 0) + "~V")))) + (with-test-prefix "date->string ~V" + (pass-if-equal "Thursday, week 53" "53" + (convert '(2020 12 31))) + (pass-if-equal "Friday, week 53 (previous year)" "53" + (convert '(2021 1 1))) + (pass-if-equal "Sunday, week 53 (previous year)" "53" + (convert '(2021 1 3))) + (pass-if-equal "Monday, week 1" "01" + (convert '(2021 1 4))) + + (pass-if-equal "Sunday, week 52" "52" + (convert '(2019 12 29))) + (pass-if-equal "Monday, week 1 (next year)" "01" + (convert '(2019 12 30))) + (pass-if-equal "Tuesday, week 1 (next year)" "01" + (convert '(2019 12 31))) + (pass-if-equal "Wednesday, week 1" "01" + (convert '(2020 1 1))) + + (pass-if-equal "Saturday, week 52" "52" + (convert '(2016 12 31))) + (pass-if-equal "Sunday, week 52 (previous year)" "52" + (convert '(2017 1 1))) + (pass-if-equal "Monday, week 1" "01" + (convert '(2017 1 2))) + (pass-if-equal "Sunday, week 1" "01" + (convert '(2017 1 8))) + (pass-if-equal "Monday, week 2" "02" + (convert '(2017 1 9))) + + (pass-if-equal "Sunday, week 52" "52" + (convert '(2014 12 28))) + (pass-if-equal "Monday, week 1 (next year)" "01" + (convert '(2014 12 29))) + (pass-if-equal "Tuesday, week 1 (next year)" "01" + (convert '(2014 12 30))) + (pass-if-equal "Wednesday, week 1 (next year)" "01" + (convert '(2014 12 31))) + (pass-if-equal "Thursday, week 1" "01" + (convert '(2015 1 1))) + (pass-if-equal "Friday, week 1" "01" + (convert '(2015 1 2))) + (pass-if-equal "Saturday, week 1" "01" + (convert '(2015 1 3))) + (pass-if-equal "Sunday, week 1" "01" + (convert '(2015 1 4))) + (pass-if-equal "Monday, week 2" "02" + (convert '(2015 1 5)))))) ;; Local Variables: -- 2.46.0 ------------=_1740775443-3129-1--