Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/date

Package Overview
Dependencies
Maintainers
16
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/date - npm Package Compare versions

Comparing version 3.14.0 to 3.15.1-next.5c9849e156.0

build-types/index.d.ts

101

build-module/index.js

@@ -9,2 +9,49 @@ /**

/** @typedef {import('moment').LocaleSpecification} MomentLocaleSpecification */
/**
* @typedef MeridiemConfig
* @property {string} am Lowercase AM.
* @property {string} AM Uppercase AM.
* @property {string} pm Lowercase PM.
* @property {string} PM Uppercase PM.
*/
/**
* @typedef FormatsConfig
* @property {string} time Time format.
* @property {string} date Date format.
* @property {string} datetime Datetime format.
* @property {string} datetimeAbbreviated Abbreviated datetime format.
*/
/**
* @typedef TimezoneConfig
* @property {string} offset Offset setting.
* @property {string} string The timezone as a string (e.g., `'America/Los_Angeles'`).
* @property {string} abbr Abbreviation for the timezone.
*/
/* eslint-disable jsdoc/valid-types */
/**
* @typedef L10nSettings
* @property {string} locale Moment locale.
* @property {MomentLocaleSpecification['months']} months Locale months.
* @property {MomentLocaleSpecification['monthsShort']} monthsShort Locale months short.
* @property {MomentLocaleSpecification['weekdays']} weekdays Locale weekdays.
* @property {MomentLocaleSpecification['weekdaysShort']} weekdaysShort Locale weekdays short.
* @property {MeridiemConfig} meridiem Meridiem config.
* @property {MomentLocaleSpecification['relativeTime']} relative Relative time config.
*/
/* eslint-enable jsdoc/valid-types */
/**
* @typedef DateSettings
* @property {L10nSettings} l10n Localization settings.
* @property {FormatsConfig} formats Date/time formats config.
* @property {TimezoneConfig} timezone Timezone settings.
*/
var WP_ZONE = 'WP'; // This regular expression tests positive for UTC offsets as described in ISO 8601.

@@ -16,2 +63,4 @@ // See: https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC

/** @type {DateSettings} */
var settings = {

@@ -62,3 +111,3 @@ l10n: {

*
* @param {Object} dateSettings Settings, including locale data.
* @param {DateSettings} dateSettings Settings, including locale data.
*/

@@ -86,6 +135,9 @@

LT: dateSettings.formats.time,
// @ts-ignore Forcing this to `null`
LTS: null,
// @ts-ignore Forcing this to `null`
L: null,
LL: dateSettings.formats.date,
LLL: dateSettings.formats.datetime,
// @ts-ignore Forcing this to `null`
LLLL: null

@@ -151,4 +203,2 @@ },

* directly.
*
* @type {Object}
*/

@@ -188,3 +238,3 @@

// DDD - 1
return '' + parseInt(momentDate.format('DDD'), 10) - 1;
return (parseInt(momentDate.format('DDD'), 10) - 1).toString();
},

@@ -204,3 +254,3 @@ // Week

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -234,3 +284,3 @@ t: function t(momentDate) {

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -242,3 +292,3 @@ B: function B(momentDate) {

hours = parseInt(timezoned.format('H'), 10);
return parseInt((seconds + minutes * MINUTE_IN_SECONDS + hours * HOUR_IN_SECONDS) / 86.4, 10);
return parseInt(((seconds + minutes * MINUTE_IN_SECONDS + hours * HOUR_IN_SECONDS) / 86.4).toString(), 10);
},

@@ -275,3 +325,3 @@ g: 'h',

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -282,3 +332,5 @@ Z: function Z(momentDate) {

var sign = offset[0] === '-' ? -1 : 1;
var parts = offset.substring(1).split(':');
var parts = offset.substring(1).split(':').map(function (n) {
return parseInt(n, 10);
});
return sign * (parts[0] * HOUR_IN_MINUTES + parts[1]) * MINUTE_IN_SECONDS;

@@ -297,3 +349,3 @@ },

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -321,8 +373,12 @@ *

if (char in formatMap) {
if (typeof formatMap[char] !== 'string') {
var formatter = formatMap[
/** @type {keyof formatMap} */
char];
if (typeof formatter !== 'string') {
// If the format is a function, call it.
newFormat.push('[' + formatMap[char](momentDate) + ']');
newFormat.push('[' + formatter(momentDate) + ']');
} else {
// Otherwise, add as a formatting string.
newFormat.push(formatMap[char]);
newFormat.push(formatter);
}

@@ -336,4 +392,3 @@ } else {

newFormat = newFormat.join('[]');
return momentDate.format(newFormat);
return momentDate.format(newFormat.join('[]'));
}

@@ -345,5 +400,5 @@ /**

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string, parsable
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* by moment.js.
* @param {string|number|null} timezone Timezone to output result in or a
* @param {string | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -369,3 +424,3 @@ * site.

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -389,5 +444,5 @@ *

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string, parsable by
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable by
* moment.js.
* @param {string|number|boolean|null} timezone Timezone to output result in or a
* @param {string | boolean | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -426,3 +481,3 @@ * site. Notice: `boolean` is effectively

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -470,5 +525,5 @@ *

*
* @param {Date|string|Moment|null} dateValue Date object or string, parsable
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* by moment.js.
* @param {string|number|null} timezone Timezone to output result in or a
* @param {string | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -475,0 +530,0 @@ * site.

@@ -29,2 +29,49 @@ "use strict";

/** @typedef {import('moment').Moment} Moment */
/** @typedef {import('moment').LocaleSpecification} MomentLocaleSpecification */
/**
* @typedef MeridiemConfig
* @property {string} am Lowercase AM.
* @property {string} AM Uppercase AM.
* @property {string} pm Lowercase PM.
* @property {string} PM Uppercase PM.
*/
/**
* @typedef FormatsConfig
* @property {string} time Time format.
* @property {string} date Date format.
* @property {string} datetime Datetime format.
* @property {string} datetimeAbbreviated Abbreviated datetime format.
*/
/**
* @typedef TimezoneConfig
* @property {string} offset Offset setting.
* @property {string} string The timezone as a string (e.g., `'America/Los_Angeles'`).
* @property {string} abbr Abbreviation for the timezone.
*/
/* eslint-disable jsdoc/valid-types */
/**
* @typedef L10nSettings
* @property {string} locale Moment locale.
* @property {MomentLocaleSpecification['months']} months Locale months.
* @property {MomentLocaleSpecification['monthsShort']} monthsShort Locale months short.
* @property {MomentLocaleSpecification['weekdays']} weekdays Locale weekdays.
* @property {MomentLocaleSpecification['weekdaysShort']} weekdaysShort Locale weekdays short.
* @property {MeridiemConfig} meridiem Meridiem config.
* @property {MomentLocaleSpecification['relativeTime']} relative Relative time config.
*/
/* eslint-enable jsdoc/valid-types */
/**
* @typedef DateSettings
* @property {L10nSettings} l10n Localization settings.
* @property {FormatsConfig} formats Date/time formats config.
* @property {TimezoneConfig} timezone Timezone settings.
*/
var WP_ZONE = 'WP'; // This regular expression tests positive for UTC offsets as described in ISO 8601.

@@ -36,2 +83,4 @@ // See: https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC

/** @type {DateSettings} */
var settings = {

@@ -82,3 +131,3 @@ l10n: {

*
* @param {Object} dateSettings Settings, including locale data.
* @param {DateSettings} dateSettings Settings, including locale data.
*/

@@ -107,6 +156,9 @@

LT: dateSettings.formats.time,
// @ts-ignore Forcing this to `null`
LTS: null,
// @ts-ignore Forcing this to `null`
L: null,
LL: dateSettings.formats.date,
LLL: dateSettings.formats.datetime,
// @ts-ignore Forcing this to `null`
LLLL: null

@@ -175,4 +227,2 @@ },

* directly.
*
* @type {Object}
*/

@@ -212,3 +262,3 @@

// DDD - 1
return '' + parseInt(momentDate.format('DDD'), 10) - 1;
return (parseInt(momentDate.format('DDD'), 10) - 1).toString();
},

@@ -228,3 +278,3 @@ // Week

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -258,3 +308,3 @@ t: function t(momentDate) {

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -266,3 +316,3 @@ B: function B(momentDate) {

hours = parseInt(timezoned.format('H'), 10);
return parseInt((seconds + minutes * MINUTE_IN_SECONDS + hours * HOUR_IN_SECONDS) / 86.4, 10);
return parseInt(((seconds + minutes * MINUTE_IN_SECONDS + hours * HOUR_IN_SECONDS) / 86.4).toString(), 10);
},

@@ -299,3 +349,3 @@ g: 'h',

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -306,3 +356,5 @@ Z: function Z(momentDate) {

var sign = offset[0] === '-' ? -1 : 1;
var parts = offset.substring(1).split(':');
var parts = offset.substring(1).split(':').map(function (n) {
return parseInt(n, 10);
});
return sign * (parts[0] * HOUR_IN_MINUTES + parts[1]) * MINUTE_IN_SECONDS;

@@ -321,3 +373,3 @@ },

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -345,8 +397,12 @@ *

if (char in formatMap) {
if (typeof formatMap[char] !== 'string') {
var formatter = formatMap[
/** @type {keyof formatMap} */
char];
if (typeof formatter !== 'string') {
// If the format is a function, call it.
newFormat.push('[' + formatMap[char](momentDate) + ']');
newFormat.push('[' + formatter(momentDate) + ']');
} else {
// Otherwise, add as a formatting string.
newFormat.push(formatMap[char]);
newFormat.push(formatter);
}

@@ -360,4 +416,3 @@ } else {

newFormat = newFormat.join('[]');
return momentDate.format(newFormat);
return momentDate.format(newFormat.join('[]'));
}

@@ -369,5 +424,5 @@ /**

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string, parsable
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* by moment.js.
* @param {string|number|null} timezone Timezone to output result in or a
* @param {string | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -394,3 +449,3 @@ * site.

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -415,5 +470,5 @@ *

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string, parsable by
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable by
* moment.js.
* @param {string|number|boolean|null} timezone Timezone to output result in or a
* @param {string | boolean | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -453,3 +508,3 @@ * site. Notice: `boolean` is effectively

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -502,5 +557,5 @@ *

*
* @param {Date|string|Moment|null} dateValue Date object or string, parsable
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* by moment.js.
* @param {string|number|null} timezone Timezone to output result in or a
* @param {string | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -507,0 +562,0 @@ * site.

@@ -5,2 +5,8 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## 3.15.0-next.0 (2021-03-26)
### New Feature
- Bundle type definitions.
## 3.14.0 (2021-03-17)

@@ -7,0 +13,0 @@

{
"name": "@wordpress/date",
"version": "3.14.0",
"version": "3.15.1-next.5c9849e156.0",
"description": "Date module for WordPress.",

@@ -24,4 +24,5 @@ "author": "The WordPress Contributors",

"react-native": "src/index",
"types": "build-types",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@babel/runtime": "^7.13.10",
"moment": "^2.22.1",

@@ -33,3 +34,3 @@ "moment-timezone": "^0.5.31"

},
"gitHead": "054f7d722fe561b2bede2d1e89e1add59a6b7093"
"gitHead": "595352e9f9c483d00f19d2b2f89ccca41f92e9a6"
}

@@ -31,4 +31,4 @@ # Date

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Date|string|Moment|null`: Date object or string, parsable by moment.js.
- _timezone_ `string|number|null`: Timezone to output result in or a UTC offset. Defaults to timezone from site.
- _dateValue_ `Moment | Date | string | undefined`: Date object or string, parsable by moment.js.
- _timezone_ `string | undefined`: Timezone to output result in or a UTC offset. Defaults to timezone from site.

@@ -54,4 +54,4 @@ _Returns_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Date|string|Moment|null`: Date object or string, parsable by moment.js.
- _timezone_ `string|number|boolean|null`: Timezone to output result in or a UTC offset. Defaults to timezone from site. Notice: `boolean` is effectively deprecated, but still supported for backward compatibility reasons.
- _dateValue_ `Moment | Date | string | undefined`: Date object or string, parsable by moment.js.
- _timezone_ `string | boolean | undefined`: Timezone to output result in or a UTC offset. Defaults to timezone from site. Notice: `boolean` is effectively deprecated, but still supported for backward compatibility reasons.

@@ -69,3 +69,3 @@ _Returns_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Date|string|Moment|null`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | undefined`: Date object or string, parsable by moment.js.

@@ -95,3 +95,3 @@ _Returns_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Date|string|Moment|null`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | undefined`: Date object or string, parsable by moment.js.

@@ -110,3 +110,3 @@ _Returns_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Date|string|Moment|null`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | undefined`: Date object or string, parsable by moment.js.

@@ -135,3 +135,3 @@ _Returns_

- _dateSettings_ `Object`: Settings, including locale data.
- _dateSettings_ `DateSettings`: Settings, including locale data.

@@ -138,0 +138,0 @@

@@ -9,3 +9,47 @@ /**

/** @typedef {import('moment').Moment} Moment */
/** @typedef {import('moment').LocaleSpecification} MomentLocaleSpecification */
/**
* @typedef MeridiemConfig
* @property {string} am Lowercase AM.
* @property {string} AM Uppercase AM.
* @property {string} pm Lowercase PM.
* @property {string} PM Uppercase PM.
*/
/**
* @typedef FormatsConfig
* @property {string} time Time format.
* @property {string} date Date format.
* @property {string} datetime Datetime format.
* @property {string} datetimeAbbreviated Abbreviated datetime format.
*/
/**
* @typedef TimezoneConfig
* @property {string} offset Offset setting.
* @property {string} string The timezone as a string (e.g., `'America/Los_Angeles'`).
* @property {string} abbr Abbreviation for the timezone.
*/
/* eslint-disable jsdoc/valid-types */
/**
* @typedef L10nSettings
* @property {string} locale Moment locale.
* @property {MomentLocaleSpecification['months']} months Locale months.
* @property {MomentLocaleSpecification['monthsShort']} monthsShort Locale months short.
* @property {MomentLocaleSpecification['weekdays']} weekdays Locale weekdays.
* @property {MomentLocaleSpecification['weekdaysShort']} weekdaysShort Locale weekdays short.
* @property {MeridiemConfig} meridiem Meridiem config.
* @property {MomentLocaleSpecification['relativeTime']} relative Relative time config.
*/
/* eslint-enable jsdoc/valid-types */
/**
* @typedef DateSettings
* @property {L10nSettings} l10n Localization settings.
* @property {FormatsConfig} formats Date/time formats config.
* @property {TimezoneConfig} timezone Timezone settings.
*/
const WP_ZONE = 'WP';

@@ -19,2 +63,3 @@

// well because it uses the `setSettings()` function to change these settings.
/** @type {DateSettings} */
let settings = {

@@ -91,3 +136,3 @@ l10n: {

*
* @param {Object} dateSettings Settings, including locale data.
* @param {DateSettings} dateSettings Settings, including locale data.
*/

@@ -118,6 +163,9 @@ export function setSettings( dateSettings ) {

LT: dateSettings.formats.time,
// @ts-ignore Forcing this to `null`
LTS: null,
// @ts-ignore Forcing this to `null`
L: null,
LL: dateSettings.formats.date,
LLL: dateSettings.formats.datetime,
// @ts-ignore Forcing this to `null`
LLLL: null,

@@ -184,4 +232,2 @@ },

* directly.
*
* @type {Object}
*/

@@ -220,3 +266,3 @@ const formatMap = {

// DDD - 1
return '' + parseInt( momentDate.format( 'DDD' ), 10 ) - 1;
return ( parseInt( momentDate.format( 'DDD' ), 10 ) - 1 ).toString();
},

@@ -237,3 +283,3 @@

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -267,3 +313,3 @@ t( momentDate ) {

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -276,6 +322,8 @@ B( momentDate ) {

return parseInt(
( seconds +
minutes * MINUTE_IN_SECONDS +
hours * HOUR_IN_SECONDS ) /
86.4,
(
( seconds +
minutes * MINUTE_IN_SECONDS +
hours * HOUR_IN_SECONDS ) /
86.4
).toString(),
10

@@ -312,3 +360,3 @@ );

*
* @return {string} Formatted date.
* @return {number} Formatted date.
*/

@@ -319,3 +367,6 @@ Z( momentDate ) {

const sign = offset[ 0 ] === '-' ? -1 : 1;
const parts = offset.substring( 1 ).split( ':' );
const parts = offset
.substring( 1 )
.split( ':' )
.map( ( n ) => parseInt( n, 10 ) );
return (

@@ -338,3 +389,3 @@ sign *

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -346,3 +397,3 @@ *

let i, char;
let newFormat = [];
const newFormat = [];
const momentDate = momentLib( dateValue );

@@ -359,8 +410,10 @@ for ( i = 0; i < dateFormat.length; i++ ) {

if ( char in formatMap ) {
if ( typeof formatMap[ char ] !== 'string' ) {
const formatter =
formatMap[ /** @type {keyof formatMap} */ ( char ) ];
if ( typeof formatter !== 'string' ) {
// If the format is a function, call it.
newFormat.push( '[' + formatMap[ char ]( momentDate ) + ']' );
newFormat.push( '[' + formatter( momentDate ) + ']' );
} else {
// Otherwise, add as a formatting string.
newFormat.push( formatMap[ char ] );
newFormat.push( formatter );
}

@@ -373,4 +426,3 @@ } else {

// unneeded separators with static text.
newFormat = newFormat.join( '[]' );
return momentDate.format( newFormat );
return momentDate.format( newFormat.join( '[]' ) );
}

@@ -383,5 +435,5 @@

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string, parsable
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* by moment.js.
* @param {string|number|null} timezone Timezone to output result in or a
* @param {string | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -405,3 +457,3 @@ * site.

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -424,5 +476,5 @@ *

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string, parsable by
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable by
* moment.js.
* @param {string|number|boolean|null} timezone Timezone to output result in or a
* @param {string | boolean | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -458,3 +510,3 @@ * site. Notice: `boolean` is effectively

* See php.net/date.
* @param {Date|string|Moment|null} dateValue Date object or string,
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* parsable by moment.js.

@@ -502,5 +554,5 @@ *

*
* @param {Date|string|Moment|null} dateValue Date object or string, parsable
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* by moment.js.
* @param {string|number|null} timezone Timezone to output result in or a
* @param {string | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from

@@ -507,0 +559,0 @@ * site.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc