-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Scheduled Post time has mismatched between time shown and hint #25256
Comments
I think the problem comes from the fact that the date given to the frontend by the site is already offset, but the frontend formatting functions works assuming that this is not the case. In order to print "September 20, 2020 5:00pm", Something else to note: the difference between EDT and PDT is 3 hours; that is the offset that the library is applying to the date, and not necessarily the actual PDT offset of UTC-7—if it were a matter of the time being picked in another timezone, it would look like.
In my system, the offset is applied based on my timezone (GMT-3) vs the timezone of the site—for instance, GMT-5 would render displayed dates like with an offset of -2 hours: This is because of how moment works and how the There currently isn't an option for Any thoughts? |
Another thought that comes to mind: the real base of the problem is that the site is providing the frontend with an already formatted time, which makes it harder to manipulate, as the new variable of 'timezone' is introduced. It would perhaps be best if the system reported all times as UTC. If we take a look at the tests on |
This turned out to be a deeper issue that it seems, in my opinion. When handling dates on the frontend, the multiple possible sources of truth must be kept in mind in order to avoid inconsistencies with the “actual” dates. The WordPress entity’s “date” and “date_gmt” attributes should be considered the source of truth when handling WordPress entities. The happy path.The user’s Browser timezone is UTC-3. The user sets the site’s time to UTC-3 as well. The user creates a post; the following timestamps are set in the corresponding attributes. date is the site’s local time, date_gmt its UTC(GMT/Zulu Time) equivalent.
Gutenberg’s dateI18n function is called, in order to display the post’s formatted date on the editor—the > dateI18n('F j, Y g:i a', '2020-09-23T17:18:00')
< September 23, 2020 17:18 pm This scenario is well tested, and it works correctly! The not so happy pathThe user’s Browser timezone is still UTC-3, but they’ve set the site’s time to UTC-5. At 5:18pm UTC-5, the user creates a post; the following timestamps are set:
The formatting function is called to display the post’s formatted date: > dateI18n('F j, Y g:i a', '2020-09-23T17:18:00')
< September 23, 2020 3:18 pm Here we can see that 3:18pm is neither UTC-5 nor -3 for the actual UTC time of Same would happen if we used A combination of Possible Solutions
> dateI18n( 'F j, Y g:i a', '2020-09-23T22:18:00Z' )
< September 23, 2020 5:18 pm I think this would be ideally done in the backend.
const dateGMT = "2020-09-23T22:18:00";
const actualGMTDate = moment( dateGMT ).utc( true );
> dateI18n( actualGMTDate );
< September 23, 2020 5:18 pm
...or similarly doing the same when we save the data to the store.
ie. changing the API to export function gmdateI18n( dateFormat, dateValue = new Date() ) {
/**
* The only change in the next line, where the`true` parameter
* is added to the `utc()` function.
*/
const dateMoment = momentLib( dateValue ).utc( true );
dateMoment.locale( settings.l10n.locale );
return format( dateFormat, dateMoment );
} This breaks the tests, so I'm hesistant on this being the best solution. The entire library is tested using timestamps that include the Conclusion/QuestionsAdding the This issue is affecting every usage of the
Please let me know your thoughts. I'm particularly interested on the perspective of the non-Gutenberg side of this issue, as I haven't filled the knowledge gap there. cc. @mkaz |
Good work digging in and figuring out the scenarios. I think I'm with you on the first solution — adding the This would be a good one to bring up in the Core JS Meeting, usually there is time in the meeting to bring up items, but might be good to add ahead to the meeting's rolling agenda to give people a chance to prep. |
I brought this up on the meeting, and as suggested, I'd like to bring this to the attention of @aduth and @davilera—I don't have permissions to add you as reviewers, hence the ping :) |
Is this a duplicate of #25003? |
Yes, it’s the same problem. |
This seems to be fixed by now. Not sure which commit though. Probably it's fixed by migrating from moment to date-fns. @mkaz Can you confirm? Thanks! |
Yep, fixed in #25782 |
Describe the bug
When displaying the time in the calendar, a hint was added in #23400 so the user would know what timezone the post was being schedule in.
The issue is it now appears that the time being selected is the user's time and not the server time.
To reproduce
Steps to reproduce the behavior:
Expected behavior
The time shown should match the hint of what time zone it is being set to.
Screenshots
Related trac ticket: https://core.trac.wordpress.org/ticket/50624
The text was updated successfully, but these errors were encountered: