Repository navigation
Fix the flaky daysElapsedCountsSpansAcrossBoundaries test - #26459
Merged
Merged
Conversation
daysElapsedSinceDate found midnight in the process time zone but counted days in the receiving calendar. When a test changed NSTimeZone.default, Calendar.current followed it and the two zones disagreed across a clock change, making the 30-day case return 29 at 23:xx Pacific. Use the receiving calendar for both steps, and accept an optional now so the behaviour can be tested deterministically.
Collaborator
Generated by 🚫 Danger |
crazytonyli
marked this pull request as ready for review
November 26, 2026 08:52
jkmassel
enabled auto-merge
November 26, 2026 18:27
jkmassel
approved these changes
Nov 26, 2026
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.
Description
CalendarHelpersTests.daysElapsedCountsSpansAcrossBoundaries, added in #25826, has been failing fordaysAgo → 30on CI since November. It only fails between 23:00 and 23:59 Pacific, and only whenNSDateHelperTestruns before it.NSDateHelperTest.init()setsNSTimeZone.defaultto GMT for the whole test process.Calendar.currentfollows that default, butTimeZone.autoupdatingCurrentdoes not.daysElapsedSinceDatefound midnight withnormalizedDate(), which usesautoupdatingCurrent(Pacific on CI), and then counted days with the receiving calendar (GMT). The 1 November clock change puts the two zones an hour out of step, so 30 days counts as 29.This PR makes
daysElapsedSinceDateuse the receiving calendar for both steps. The app is not affected: it never setsNSTimeZone.default, so both zones are the same for the one caller inNotificationsViewController.The new
nowparameter is there for the new test. Without a fixed clock, the old failure depends on the wall clock and the process time zone, so no test could catch it reliably.This PR leaves
NSDateHelperTestchanging the process time zone, and leaves the othernormalizedDate()callers that mix zones the same way. Those can be follow-ups.What I ran
Claude Code ran
-only-testing:WordPressSharedTests/CalendarHelpersTests -only-testing:WordPressSharedTests/NSDateHelperTeston an iOS 26.2 simulator:It also reproduced the failure with
TZ=America/Anchorageat 23:xx local time. A copy of the test that first setsNSTimeZone.defaultto GMT, asNSDateHelperTestdoes, failed 20 of 20 runs before this change and 0 of 20 after.Testing instructions
To reproduce the failure on trunk before 1 December: between 07:00 and 07:59 UTC, run
TZ=America/Los_Angeles swift test --filter WordPressSharedTestsa few times. It fails whenNSDateHelperTestruns first, which happened in about 2 of 3 local runs. At other hours, use a US time zone where the local time is 23:xx, such asAmerica/Chicagofrom 05:00 UTC.