: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @return {number} Formatted date.
const timezoned = external_moment_default()(momentDate).utcOffset(60);
const seconds = parseInt(timezoned.format('s'), 10),
minutes = parseInt(timezoned.format('m'), 10),
hours = parseInt(timezoned.format('H'), 10);
return parseInt(((seconds + minutes * MINUTE_IN_SECONDS + hours * HOUR_IN_SECONDS) / 86.4).toString(), 10);
* Gets whether the timezone is in DST currently.
* @param {Moment} momentDate Moment instance.
* @return {string} Formatted date.
return momentDate.isDST() ? '1' : '0';
* Gets the timezone offset in seconds.
* @param {Moment} momentDate Moment instance.
* @return {number} Formatted date.
// Timezone offset in seconds.
const offset = momentDate.format('Z');
const sign = offset[0] === '-' ? -1 : 1;
const parts = offset.substring(1).split(':').map(n => parseInt(n, 10));
return sign * (parts[0] * HOUR_IN_MINUTES + parts[1]) * MINUTE_IN_SECONDS;
c: 'YYYY-MM-DDTHH:mm:ssZ',
* Formats the date as RFC2822.
* @param {Moment} momentDate Moment instance.
* @return {string} Formatted date.
return momentDate.locale('en').format('ddd, DD MMM YYYY HH:mm:ss ZZ');
* Formats a date. Does not alter the date's timezone.
* @param {string} dateFormat PHP-style formatting string.
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* @return {string} Formatted date.
function format(dateFormat, dateValue = new Date()) {
const momentDate = external_moment_default()(dateValue);
for (i = 0; i < dateFormat.length; i++) {
// Add next character, then move on.
newFormat.push('[' + dateFormat[i] + ']');
const formatter = formatMap[( /** @type {keyof formatMap} */char)];
if (typeof formatter !== 'string') {
// If the format is a function, call it.
newFormat.push('[' + formatter(momentDate) + ']');
// Otherwise, add as a formatting string.
newFormat.push(formatter);
newFormat.push('[' + char + ']');
// Join with [] between to separate characters, and replace
// unneeded separators with static text.
return momentDate.format(newFormat.join('[]'));
* Formats a date (like `date()` in PHP).
* @param {string} dateFormat PHP-style formatting string.
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* @param {string | number | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
* @return {string} Formatted date in English.
function date(dateFormat, dateValue = new Date(), timezone) {
const dateMoment = buildMoment(dateValue, timezone);
return format(dateFormat, dateMoment);
* Formats a date (like `date()` in PHP), in the UTC timezone.
* @param {string} dateFormat PHP-style formatting string.
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* @return {string} Formatted date in English.
function gmdate(dateFormat, dateValue = new Date()) {
const dateMoment = external_moment_default()(dateValue).utc();
return format(dateFormat, dateMoment);
* Formats a date (like `wp_date()` in PHP), translating it into site's locale.
* Backward Compatibility Notice: if `timezone` is set to `true`, the function
* behaves like `gmdateI18n`.
* @param {string} dateFormat PHP-style formatting string.
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable by
* @param {string | number | boolean | undefined} timezone 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.
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
* @return {string} Formatted date.
function dateI18n(dateFormat, dateValue = new Date(), timezone) {
return gmdateI18n(dateFormat, dateValue);
if (false === timezone) {
const dateMoment = buildMoment(dateValue, timezone);
dateMoment.locale(settings.l10n.locale);
return format(dateFormat, dateMoment);
* Formats a date (like `wp_date()` in PHP), translating it into site's locale
* and using the UTC timezone.
* @param {string} dateFormat PHP-style formatting string.
* @param {Moment | Date | string | undefined} dateValue Date object or string,
* @return {string} Formatted date.
function gmdateI18n(dateFormat, dateValue = new Date()) {
const dateMoment = external_moment_default()(dateValue).utc();
dateMoment.locale(settings.l10n.locale);
return format(dateFormat, dateMoment);
* Check whether a date is considered in the future according to the WordPress settings.
* @param {string} dateValue Date String or Date object in the Defined WP Timezone.
* @return {boolean} Is in the future.
function isInTheFuture(dateValue) {
const now = external_moment_default().tz(WP_ZONE);
const momentObject = external_moment_default().tz(dateValue, WP_ZONE);
return momentObject.isAfter(now);
* Create and return a JavaScript Date Object from a date string in the WP timezone.
* @param {string?} dateString Date formatted in the WP timezone.
function getDate(dateString) {
return external_moment_default().tz(WP_ZONE).toDate();
return external_moment_default().tz(dateString, WP_ZONE).toDate();
* Returns a human-readable time difference between two dates, like human_time_diff() in PHP.
* @param {Moment | Date | string} from From date, in the WP timezone.
* @param {Moment | Date | string | undefined} to To date, formatted in the WP timezone.
* @return {string} Human-readable time difference.
function humanTimeDiff(from, to) {
const fromMoment = external_moment_default().tz(from, WP_ZONE);
const toMoment = to ? external_moment_default().tz(to, WP_ZONE) : external_moment_default().tz(WP_ZONE);
return fromMoment.from(toMoment);
* Creates a moment instance using the given timezone or, if none is provided, using global settings.
* @param {Moment | Date | string | undefined} dateValue Date object or string, parsable
* @param {string | number | undefined} timezone Timezone to output result in or a
* UTC offset. Defaults to timezone from
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
* @return {Moment} a moment instance.
function buildMoment(dateValue, timezone = '') {
const dateMoment = external_moment_default()(dateValue);
if (timezone && !isUTCOffset(timezone)) {
// The ! isUTCOffset() check guarantees that timezone is a string.
return dateMoment.tz( /** @type {string} */timezone);
if (timezone && isUTCOffset(timezone)) {
return dateMoment.utcOffset(timezone);
if (settings.timezone.string) {
return dateMoment.tz(settings.timezone.string);
return dateMoment.utcOffset(+settings.timezone.offset);
* Returns whether a certain UTC offset is valid or not.
* @param {number|string} offset a UTC offset.
* @return {boolean} whether a certain UTC offset is valid or not.
function isUTCOffset(offset) {
if ('number' === typeof offset) {
return VALID_UTC_OFFSET.test(offset);
(window.wp = window.wp || {}).date = __webpack_exports__;