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

Format local dates instead of converting a second time #568

Merged
merged 2 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { __experimentalGetSettings, dateI18n, setSettings } from '@wordpress/date';
import { dateI18n } from '@wordpress/date';

/**
* Internal dependencies
*/
import { WC_BLOCKS_STORE } from '../../data';

/*
* Work around Gutenberg bug: https://github.com/WordPress/gutenberg/issues/22193
*
* @todo remove this when that's resolved, because it adds ~150k to the build.
*/
import 'moment-timezone/moment-timezone-utils';
setSettings( __experimentalGetSettings() );

/*
* Create an implicit "0" track when none formally exist.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { InspectorControls } from '@wordpress/block-editor';
import { CheckboxControl, PanelBody, ToggleControl } from '@wordpress/components';
import { dateI18n } from '@wordpress/date';
import { dateI18n, format } from '@wordpress/date';
import { createInterpolateElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function ScheduleInspectorControls(
}

/**
* Get all of the dates that the given sessions are assigned to.
* Get all of the dates (in site/venue timezone) that the given sessions are assigned to.
*
* @param {Array} sessions
*
Expand Down Expand Up @@ -124,7 +124,7 @@ function ChooseSpecificDays( { chooseSpecificDays, displayedDays, chosenDays, da
return (
<CheckboxControl
key={ day }
label={ dateI18n( dateFormat, day ) }
label={ format( dateFormat, day ) }
checked={ chosenDays.includes( day ) }
onChange={ ( isChecked ) => {
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { dateI18n } from '@wordpress/date';
import { dateI18n, format } from '@wordpress/date';
import { __, _x } from '@wordpress/i18n';
import { createContext, useContext } from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';
Expand Down Expand Up @@ -49,7 +49,7 @@ export function ScheduleGrid( { sessions } ) {
scheduleDays.push(
<ScheduleDay
key={ date }
date={ date }
localDate={ date }
sessions={ sessionsGroup }
/>
);
Expand All @@ -63,7 +63,7 @@ export function ScheduleGrid( { sessions } ) {
}

/**
* Create an array of sessions, indexed by their date.
* Create an array of sessions, indexed by their date (according to the site's timezone).
*
* @param {Array} sessions
*
Expand Down Expand Up @@ -94,17 +94,17 @@ function groupSessionsByDate( sessions ) {
* Render the schedule for a specific day.
*
* @param {Object} props
* @param {string} props.date In a format acceptable by `wp.date.dateI18n()`.
* @param {Array} props.sessions
* @param {string} props.localDate The day being displayed in Ymd format (in the site's timezone).
* @param {Array} props.sessions The sessions assigned to the displayed date.
*
* @return {Element}
*/
function ScheduleDay( { date, sessions } ) {
function ScheduleDay( { localDate, sessions } ) {
const { attributes, allTracks, renderEnvironment, settings } = useContext( ScheduleGridContext );
const { chooseSpecificTracks, chosenTrackIds } = attributes;

const displayedTracks = getDisplayedTracks( sessions, allTracks, chooseSpecificTracks, chosenTrackIds );
const formattedDate = dateI18n( DATE_SLUG_FORMAT, date );
const formattedDate = format( DATE_SLUG_FORMAT, localDate );
const formattedTrackIds = chooseSpecificTracks ? displayedTracks.map( ( track ) => track.id ).join( '-' ) : 'all';

/*
Expand Down Expand Up @@ -145,7 +145,7 @@ function ScheduleDay( { date, sessions } ) {
</style>

<h2 className="wordcamp-schedule__date">
{ dateI18n( settings.date_format, date ) }
{ format( settings.date_format, localDate ) }
</h2>

{ 'editor' === renderEnvironment && renderOverlappingSessionsWarning( overlappingSessions ) }
Expand Down