Fix array order inconsistencies#958
Merged
susnux merged 5 commits intonextcloud-libraries:fix-l10nfrom Nov 3, 2025
Sector6759:fix-array-order-inconsistencies
Merged
Fix array order inconsistencies#958susnux merged 5 commits intonextcloud-libraries:fix-l10nfrom Sector6759:fix-array-order-inconsistencies
susnux merged 5 commits intonextcloud-libraries:fix-l10nfrom
Sector6759:fix-array-order-inconsistencies
Conversation
susnux
approved these changes
Nov 3, 2025
Contributor
susnux
left a comment
There was a problem hiding this comment.
This makes a lot of sense!
Contributor
|
@Sector6759 sorry for the delay! |
Contributor
Author
|
Contributor
|
@Sector6759 thats fine you can also sign off with the name and email configured for your git commits. |
Signed-off-by: Sector6759 <[email protected]>
Signed-off-by: Sector6759 <[email protected]>
…allback array values Signed-off-by: Sector6759 <[email protected]>
…ents of "Server rendered" arrays Signed-off-by: Sector6759 <[email protected]>
…ime zones Signed-off-by: Sector6759 <[email protected]>
Contributor
Author
|
@susnux Done |
Contributor
|
Thank you |
Merged
Merged
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.
Introduction
Hey, I'm working on a project which relies on a consistent order of the elements in the array returned by the
getDayNamesMinfunction, no matter which time zone the runtime is set to. To be specific, my code relies on the returned array always having Sunday at index 0, Monday at 1 etc. To double check, I had a look on the actual implementation. Manual testing revealed changing the runtime's time zone does not affect the order of the elements in the returned array as long as the so called "Server rendered" array is set and the function does not "Fallback to Intl".The problem
The above array will have Sunday at index 0, matching the "Server rendered" array
globalThis.dayNamesMin, but only if the runtime's time zone is UTC or any time zone with a positive offset, e.g. +01:00. This is because theDate.prototype.toLocaleDateStringmethod formats the returned string according to the runtime's local time zone. January 4, 1970 is a Sunday but invoking theDateconstructor with an ISO string – including the"Z"suffix for UTC – like"1970-01-04T00:00:00.000Z"in a runtime with a negative time zone offset will result in the local date being January 3, 1970 which is a Saturday.If you want to check for yourself, just switch the time zone of your local machine to e.g. America/New_York and run
npm run test. You'll see multiple tests fail.The solution
Instead of using the ISO string as the constructor argument, pass separate
Numberarguments for the year, month and day. This way, the arguments are treated as being in local time, which in turn results in Sunday always being the first element in the array, no matter the runtime's time zone.Affected code
The issue affects all of the following functions
getDayNamesgetDayNamesShortgetDayNamesMingetMonthNamesgetMonthNamesShortTests
I duplicated the tests covering the affected functions and adjusted those tests to use two different time zones: one with a negative and one with a positive offset from UTC.
Implications
One could consider this a breaking change, due to the order of the returned arrays being different compared to the current state, but then again those functions never promised any specific order. Still, based on assumptions that developers might make, I myself would consider this breaking.
On a side note, I dont' even know if there's actually a scenario where the "Server rendered" arrays inside
globalThiswouldn't be present.Contributing guidelines
I know I didn't follow the guidelines regarding the "Signed-off-by" suffix to my commit message as I'm not willing to disclose my legal name, so feel free to close this PR and copy my changes to a new unrelated PR. My goal is to just get this fixed.