Skip to content
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: Post schedule label showing wrong time if site and user timezones did not match #26212

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/editor/src/components/post-schedule/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { dateI18n, __experimentalGetSettings } from '@wordpress/date';
import { format, __experimentalGetSettings } from '@wordpress/date';
import { withSelect } from '@wordpress/data';

export function PostScheduleLabel( { date, isFloating } ) {
const settings = __experimentalGetSettings();

return date && ! isFloating
? dateI18n(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the intent of that function is not clear. Does it assume that the passed date is a given timezone? Should we remove that assumption? Should we clarify it in the description of the function.

Anyway, it seems like the current fix is good anyway but there might be something wrong with dateI18n

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by default the dateI18n assumes the time is in the user's timezone and formats it in the website time zone.
I think we may have other cases where we are using dateI18n for dates that are already on the website timezone. I will try to propose a follow-up PR that improves documentation for this function and maybe fixes additional issues.

? format(
`${ settings.formats.date } ${ settings.formats.time }`,
date
)
Expand Down