Date: Pad the ISO week number to two digits, matching PHP - #81299
Open
konnen916 wants to merge 1 commit into
Open
Date: Pad the ISO week number to two digits, matching PHP#81299konnen916 wants to merge 1 commit into
konnen916 wants to merge 1 commit into
Conversation
The `W` format character maps onto Moment's `W`, which is unpadded, while
PHP's `date( 'W' )` pads to two digits. So any week before the tenth of
the year came back a character short: `3` where PHP gives `03`.
Verified against PHP 8.4:
date PHP before after
2024-01-15 03 3 03
2024-01-01 01 1 01
2020-02-29 09 9 09
2024-03-05 10 10 10
2026-12-31 53 53 53
The existing test for `W` uses 18 June 2019, which falls in week 25. Two
digits either way, so it passed regardless of the padding. The added
cases use single digit weeks and fail without this change.
konnen916
force-pushed
the
fix/date-iso-week-padding
branch
from
August 8, 2026 15:35
9d84e39 to
8df95fa
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @konnen916. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Closes #81298
formatreturns an unpadded ISO week number where PHP pads it to two digits. This mapsWonto Moment's paddedWW.Why?
The
formatMapentry isW: 'W'. Moment'sWis the ISO week without padding, PHP'sdate( 'W' )pads to two digits, so weeks 1 to 9 come back a character short:Weeks 10 and up are already two characters and agree, which is why this has been quiet. It fails by returning a plausible string rather than raising anything, so a wrong value propagates instead of surfacing.
Verified against PHP 8.4.24:
033030110109909101010535353I checked the other format characters with custom handling in that map against PHP over the same dates, including a leap day and both ISO year boundaries.
z,t,L,o,N,wandSall already agree.Wwas the only divergence.How?
One character:
W: 'W'becomesW: 'WW'.Five test cases are added. The existing test for
Wuses 18 June 2019, week 25, which is two digits and therefore passes either way. The new cases use single digit weeks, and three of the five fail without the source change.Testing Instructions
wp.date.format( 'W', '2024-01-15' ).'3'. With this branch it returns'03', matchingdate( 'W' )in PHP.Or run the package tests:
115 pass. Reverting only the change to
packages/date/src/index.tsand rerunning drops three of the new cases to failing, which is the check that they are testing the right thing.Testing Instructions for Keyboard
Not applicable, this is a package-level change with no UI.
Screenshots or screencast
Not applicable.