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

Date: Optimize the usage of moment-timezone to save some kilobytes #12356

Merged
merged 1 commit into from Nov 28, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/packages-dependencies.php
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
Expand Up @@ -38,9 +38,6 @@
"classnames": "^2.2.5",
"lodash": "^4.17.10",
"memize": "^1.0.5",
"moment": "^2.22.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

Those dependencies are never used...

"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
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();