Merge pull request woocommerce/woocommerce-admin#1216 from woocommerce/fix/date-range-dow

DateRange: use DayOfWeek from moment locale
This commit is contained in:
Paul Sealock 2019-01-04 13:30:59 +13:00 committed by GitHub
commit 5a4f6185d6
6 changed files with 17 additions and 36 deletions

View File

@ -180,9 +180,6 @@ function wc_admin_print_script_settings() {
'embedBreadcrumbs' => wc_admin_get_embed_breadcrumbs(), 'embedBreadcrumbs' => wc_admin_get_embed_breadcrumbs(),
'siteLocale' => esc_attr( get_bloginfo( 'language' ) ), 'siteLocale' => esc_attr( get_bloginfo( 'language' ) ),
'currency' => wc_admin_currency_settings(), 'currency' => wc_admin_currency_settings(),
'date' => array(
'dow' => get_option( 'start_of_week', 0 ),
),
'orderStatuses' => format_order_statuses( wc_get_order_statuses() ), 'orderStatuses' => format_order_statuses( wc_get_order_statuses() ),
'stockStatuses' => wc_get_product_stock_status_options(), 'stockStatuses' => wc_get_product_stock_status_options(),
'siteTitle' => get_bloginfo( 'name' ), 'siteTitle' => get_bloginfo( 'name' ),

View File

@ -152,7 +152,6 @@ class DateRange extends Component {
noBorder noBorder
initialVisibleMonth={ this.setTnitialVisibleMonth( isDoubleCalendar, before ) } initialVisibleMonth={ this.setTnitialVisibleMonth( isDoubleCalendar, before ) }
phrases={ phrases } phrases={ phrases }
firstDayOfWeek={ Number( wcSettings.date.dow ) }
/> />
</div> </div>
</div> </div>

View File

@ -232,7 +232,7 @@ class Chart extends Component {
} = this.props; } = this.props;
let { yFormat } = this.props; let { yFormat } = this.props;
const legendDirection = mode === 'time-comparison' && isViewportWide ? 'row' : 'column'; const legendDirection = mode === 'time-comparison' && isViewportWide ? 'row' : 'column';
const chartDirection = ( mode === 'item-comparison' ) && isViewportWide ? 'row' : 'column'; const chartDirection = mode === 'item-comparison' && isViewportWide ? 'row' : 'column';
const chartHeight = this.getChartHeight(); const chartHeight = this.getChartHeight();
const legend = ( const legend = (
@ -267,7 +267,7 @@ class Chart extends Component {
} }
return ( return (
<div className="woocommerce-chart"> <div className="woocommerce-chart">
{ mode !== 'block' && { mode !== 'block' && (
<div className="woocommerce-chart__header"> <div className="woocommerce-chart__header">
<H className="woocommerce-chart__title">{ title }</H> <H className="woocommerce-chart__title">{ title }</H>
{ isViewportWide && legendDirection === 'row' && legend } { isViewportWide && legendDirection === 'row' && legend }
@ -301,7 +301,7 @@ class Chart extends Component {
/> />
</NavigableMenu> </NavigableMenu>
</div> </div>
} ) }
<Section component={ false }> <Section component={ false }>
<div <div
className={ classNames( className={ classNames(
@ -343,7 +343,9 @@ class Chart extends Component {
/> />
) } ) }
</div> </div>
{ ( ! isViewportWide || mode === 'block' ) && <div className="woocommerce-chart__footer">{ legend }</div> } { ( ! isViewportWide || mode === 'block' ) && (
<div className="woocommerce-chart__footer">{ legend }</div>
) }
</Section> </Section>
</div> </div>
); );

View File

@ -57,7 +57,7 @@
padding: 0; padding: 0;
width: 100%; width: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
.components-spinner { .components-spinner {
margin: 0; margin: 0;

View File

@ -490,15 +490,14 @@ export function getDateFormatsForInterval( interval, ticks = 0 ) {
} }
/** /**
* Gutenberg's moment instance is loaded with i18n values. If the locale isn't english * Gutenberg's moment instance is loaded with i18n values, which are
* we can use that data and enhance it with additional translations * PHP date formats, ie 'LLL: "F j, Y g:i a"'. Override those with translations
* of moment style js formats.
*/ */
export function loadLocaleData() { export function loadLocaleData() {
const { date, l10n } = wcSettings; const { userLocale, weekdaysShort } = wcSettings.l10n;
const { userLocale, weekdaysShort } = l10n; // Don't update if the wp locale hasn't been set yet, like in unit tests, for instance.
if ( 'en' !== moment.locale() ) {
// Keep the default Momentjs English settings for any English
if ( ! userLocale.match( /en_/ ) ) {
moment.updateLocale( userLocale, { moment.updateLocale( userLocale, {
longDateFormat: { longDateFormat: {
L: __( 'MM/DD/YYYY', 'wc-admin' ), L: __( 'MM/DD/YYYY', 'wc-admin' ),
@ -507,17 +506,6 @@ export function loadLocaleData() {
LLLL: __( 'dddd, D MMMM YYYY LT', 'wc-admin' ), LLLL: __( 'dddd, D MMMM YYYY LT', 'wc-admin' ),
LT: __( 'HH:mm', 'wc-admin' ), LT: __( 'HH:mm', 'wc-admin' ),
}, },
calendar: {
lastDay: __( '[Yesterday at] LT', 'wc-admin' ),
lastWeek: __( '[Last] dddd [at] LT', 'wc-admin' ),
nextDay: __( '[Tomorrow at] LT', 'wc-admin' ),
nextWeek: __( 'dddd [at] LT', 'wc-admin' ),
sameDay: __( '[Today at] LT', 'wc-admin' ),
sameElse: __( 'L', 'wc-admin' ),
},
week: {
dow: Number( date.dow ),
},
weekdaysMin: weekdaysShort, weekdaysMin: weekdaysShort,
} ); } );
} }

View File

@ -455,28 +455,23 @@ describe( 'getRangeLabel', () => {
describe( 'loadLocaleData', () => { describe( 'loadLocaleData', () => {
beforeEach( () => { beforeEach( () => {
// Reset to default settings // Reset to default settings
wcSettings.date.dow = 0;
wcSettings.l10n = { wcSettings.l10n = {
userLocale: 'en_US', userLocale: 'en_US',
weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ], weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
}; };
} ); } );
it( 'should leave default momentjs data unchanged for english languages', () => { it( 'should load locale data on user locale', () => {
loadLocaleData();
expect( moment.locale() ).toBe( 'en' );
} );
it( "should load locale data on user locale other than 'en-*'", () => {
wcSettings.date.dow = 5;
wcSettings.l10n = { wcSettings.l10n = {
userLocale: 'fr_FR', userLocale: 'fr_FR',
weekdaysShort: [ 'dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam' ], weekdaysShort: [ 'dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam' ],
}; };
// initialize locale. Gutenberg normaly does this, but not in test environment.
moment.locale( 'fr_FR', {} );
loadLocaleData(); loadLocaleData();
expect( moment.localeData().weekdaysMin() ).toEqual( wcSettings.l10n.weekdaysShort ); expect( moment.localeData().weekdaysMin() ).toEqual( wcSettings.l10n.weekdaysShort );
expect( moment.localeData().firstDayOfWeek() ).toBe( wcSettings.date.dow );
} ); } );
} ); } );