Skip to content

Commit

Permalink
Date: Optimize the usage of moment-timezone to save some kilobytes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Nov 28, 2018
1 parent 6e3bb74 commit 4512195
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
1 change: 0 additions & 1 deletion lib/packages-dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'wp-block-library' => array(
'editor',
'lodash',
'moment',
'wp-api-fetch',
'wp-autop',
'wp-blob',
Expand Down
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
"classnames": "^2.2.5",
"lodash": "^4.17.10",
"memize": "^1.0.5",
"moment": "^2.22.1",
"querystring": "^0.2.0",
"querystringify": "^1.0.0",
"url": "^0.11.0"
},
"devDependencies": {
Expand Down
16 changes: 9 additions & 7 deletions packages/date/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
* External dependencies
*/
import momentLib from 'moment';
import 'moment-timezone';
import 'moment-timezone/moment-timezone';
import 'moment-timezone/moment-timezone-utils';

const WP_ZONE = 'WP';

// Changes made here will likely need to be made in `lib/client-assets.php` as
// well because it uses the `setSettings()` function to change these settings.
let settings = {
Expand Down Expand Up @@ -92,8 +94,8 @@ export function __experimentalGetSettings() {
function setupWPTimezone() {
// Create WP timezone based off dateSettings.
momentLib.tz.add( momentLib.tz.pack( {
name: 'WP',
abbrs: [ 'WP' ],
name: WP_ZONE,
abbrs: [ WP_ZONE ],
untils: [ null ],
offsets: [ -settings.timezone.offset * 60 || 0 ],
} ) );
Expand Down Expand Up @@ -371,8 +373,8 @@ export function dateI18n( dateFormat, dateValue = new Date(), gmt = false ) {
* @return {boolean} Is in the future.
*/
export function isInTheFuture( dateValue ) {
const now = momentLib.tz( 'WP' );
const momentObject = momentLib.tz( dateValue, 'WP' );
const now = momentLib.tz( WP_ZONE );
const momentObject = momentLib.tz( dateValue, WP_ZONE );

return momentObject.isAfter( now );
}
Expand All @@ -386,10 +388,10 @@ export function isInTheFuture( dateValue ) {
*/
export function getDate( dateString ) {
if ( ! dateString ) {
return momentLib.tz( 'WP' ).toDate();
return momentLib.tz( WP_ZONE ).toDate();
}

return momentLib.tz( dateString, 'WP' ).toDate();
return momentLib.tz( dateString, WP_ZONE ).toDate();
}

setupWPTimezone();

0 comments on commit 4512195

Please sign in to comment.