-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Stats information fails to load when date cannot be parsed when returned from API #22910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Stats information fails to load when date cannot be parsed when returned from API #22910
Conversation
|
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr22910-478d749 | |
| Version | 25.1 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 478d749 | |
| App Center Build | WPiOS - One-Offs #10214 |
|
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr22910-478d749 | |
| Version | 25.1 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 478d749 | |
| App Center Build | jetpack-installable-builds #9263 |
|
Update after #23366 is merged |
RFC339NoTimeDateFormatter creates yyyy-MM-dd date from string while taking into account DST (Daylight Savings Time)
46dd232 to
478d749
Compare
|
This is a fix for a low-priority corner case. I only found this bug to be reproducible for Paraguay/Asuncion time zones during daylight savings date. 🤔 Therefore, I'm conflicted about whether it merits significant date formatter updates, although I tried to be careful and cover corner cases with tests. |
|
Dropping a note here as well, as it was discussed internally: it might be worth switching to native date here to eliminate any potential issues with timezones, time, and |
|
I'm closing this PR based on the previous discussion. This is an extremely rare corner case that only happens when parsing a specific date in a timezone on which DST starts at midnight. Other more generic solutions are preferred. |


Fixes #22859
We need to pass
yyyy-MM-dddate toAPIwhen fetchingstats/visitsand other similar endpoints. However, in some cases, date conversions to date string fails.The bug is related to TimeZone and DTS. For example, Paraguay has a DTS change at midnight 2023-10-01 which is ambiguous to
DateFormatterandnilis returned.Date formatter we use:
Result for "America/Asuncion" time zone:
Result for "Europe/Vilnius" time zone:
In documentation Apple suggests to set the timezone to UTC:
However, this is not a straightforward solution, since in Stats we're working with dates that are in a different time zone.
Solution
Created
RFC339NoTimeDateFormatterthat sets:but also recalculates the data to the current time zone after conversion. Therefore, the dates remain unchanged but conversions also succeed. I added
RFC339NoTimeDateFormatterTestsas an example.To test:
The easiest way to reproduce and confirm that the issue is fixed is to follow the steps from #22859
SiteStatsTableHeaderViewview so we can go back further back in datesVideo before the fix
Date.bug.mov
Video after the fix
Date.fix.mov
Regression Notes
There shouldn't be any. WPKit-PR: wordpress-mobile/WordPressKit-iOS#771 adds unit tests to make sure that a new date formatter behaves in exact same way but additionally doesn't fail during DST changes.
Unit tests, manual tests
PR submission checklist:
RELEASE-NOTES.txtif necessary.Testing checklist: