@wordpress/date 5.32.0 → 5.32.1-next.b8c8708f3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +222 -385
- package/build/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build-module/index.js +168 -336
- package/build-module/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/package.json +11 -4
package/build/index.js
CHANGED
|
@@ -1,145 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
format: true,
|
|
12
|
-
date: true,
|
|
13
|
-
gmdate: true,
|
|
14
|
-
dateI18n: true,
|
|
15
|
-
gmdateI18n: true,
|
|
16
|
-
isInTheFuture: true,
|
|
17
|
-
getDate: true,
|
|
18
|
-
humanTimeDiff: true
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
11
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
__experimentalGetSettings: () => __experimentalGetSettings,
|
|
33
|
+
date: () => date,
|
|
34
|
+
dateI18n: () => dateI18n,
|
|
35
|
+
format: () => format,
|
|
36
|
+
getDate: () => getDate,
|
|
37
|
+
getSettings: () => getSettings,
|
|
38
|
+
gmdate: () => gmdate,
|
|
39
|
+
gmdateI18n: () => gmdateI18n,
|
|
40
|
+
humanTimeDiff: () => humanTimeDiff,
|
|
41
|
+
isInTheFuture: () => isInTheFuture,
|
|
42
|
+
setSettings: () => setSettings
|
|
46
43
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Internal dependencies
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
const WP_ZONE = 'WP';
|
|
60
|
-
|
|
61
|
-
// This regular expression tests positive for UTC offsets as described in ISO 8601.
|
|
62
|
-
// See: https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
|
+
var import_moment = __toESM(require("moment"));
|
|
46
|
+
var import_moment_timezone = require("moment-timezone/moment-timezone");
|
|
47
|
+
var import_moment_timezone_utils = require("moment-timezone/moment-timezone-utils");
|
|
48
|
+
var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
49
|
+
__reExport(index_exports, require("./types"), module.exports);
|
|
50
|
+
const WP_ZONE = "WP";
|
|
63
51
|
const VALID_UTC_OFFSET = /^[+-][0-1][0-9](:?[0-9][0-9])?$/;
|
|
64
|
-
|
|
65
|
-
// Changes made here will likely need to be synced with Core in the file
|
|
66
|
-
// src/wp-includes/script-loader.php in `wp_default_packages_inline_scripts()`.
|
|
67
52
|
let settings = {
|
|
68
53
|
l10n: {
|
|
69
|
-
locale:
|
|
70
|
-
months: [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
54
|
+
locale: "en",
|
|
55
|
+
months: [
|
|
56
|
+
"January",
|
|
57
|
+
"February",
|
|
58
|
+
"March",
|
|
59
|
+
"April",
|
|
60
|
+
"May",
|
|
61
|
+
"June",
|
|
62
|
+
"July",
|
|
63
|
+
"August",
|
|
64
|
+
"September",
|
|
65
|
+
"October",
|
|
66
|
+
"November",
|
|
67
|
+
"December"
|
|
68
|
+
],
|
|
69
|
+
monthsShort: [
|
|
70
|
+
"Jan",
|
|
71
|
+
"Feb",
|
|
72
|
+
"Mar",
|
|
73
|
+
"Apr",
|
|
74
|
+
"May",
|
|
75
|
+
"Jun",
|
|
76
|
+
"Jul",
|
|
77
|
+
"Aug",
|
|
78
|
+
"Sep",
|
|
79
|
+
"Oct",
|
|
80
|
+
"Nov",
|
|
81
|
+
"Dec"
|
|
82
|
+
],
|
|
83
|
+
weekdays: [
|
|
84
|
+
"Sunday",
|
|
85
|
+
"Monday",
|
|
86
|
+
"Tuesday",
|
|
87
|
+
"Wednesday",
|
|
88
|
+
"Thursday",
|
|
89
|
+
"Friday",
|
|
90
|
+
"Saturday"
|
|
91
|
+
],
|
|
92
|
+
weekdaysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
93
|
+
meridiem: { am: "am", pm: "pm", AM: "AM", PM: "PM" },
|
|
80
94
|
relative: {
|
|
81
|
-
future:
|
|
82
|
-
past:
|
|
83
|
-
s:
|
|
84
|
-
ss:
|
|
85
|
-
m:
|
|
86
|
-
mm:
|
|
87
|
-
h:
|
|
88
|
-
hh:
|
|
89
|
-
d:
|
|
90
|
-
dd:
|
|
91
|
-
M:
|
|
92
|
-
MM:
|
|
93
|
-
y:
|
|
94
|
-
yy:
|
|
95
|
+
future: "%s from now",
|
|
96
|
+
past: "%s ago",
|
|
97
|
+
s: "a few seconds",
|
|
98
|
+
ss: "%d seconds",
|
|
99
|
+
m: "a minute",
|
|
100
|
+
mm: "%d minutes",
|
|
101
|
+
h: "an hour",
|
|
102
|
+
hh: "%d hours",
|
|
103
|
+
d: "a day",
|
|
104
|
+
dd: "%d days",
|
|
105
|
+
M: "a month",
|
|
106
|
+
MM: "%d months",
|
|
107
|
+
y: "a year",
|
|
108
|
+
yy: "%d years"
|
|
95
109
|
},
|
|
96
110
|
startOfWeek: 0
|
|
97
111
|
},
|
|
98
112
|
formats: {
|
|
99
|
-
time:
|
|
100
|
-
date:
|
|
101
|
-
datetime:
|
|
102
|
-
datetimeAbbreviated:
|
|
113
|
+
time: "g: i a",
|
|
114
|
+
date: "F j, Y",
|
|
115
|
+
datetime: "F j, Y g: i a",
|
|
116
|
+
datetimeAbbreviated: "M j, Y g: i a"
|
|
103
117
|
},
|
|
104
|
-
timezone: {
|
|
105
|
-
offset: '0',
|
|
106
|
-
offsetFormatted: '0',
|
|
107
|
-
string: '',
|
|
108
|
-
abbr: ''
|
|
109
|
-
}
|
|
118
|
+
timezone: { offset: "0", offsetFormatted: "0", string: "", abbr: "" }
|
|
110
119
|
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Adds a locale to moment, using the format supplied by `wp_localize_script()`.
|
|
114
|
-
*
|
|
115
|
-
* @param dateSettings Settings, including locale data.
|
|
116
|
-
*/
|
|
117
120
|
function setSettings(dateSettings) {
|
|
118
121
|
settings = dateSettings;
|
|
119
122
|
setupWPTimezone();
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// Is that locale misconfigured, e.g. because we are on a site running
|
|
124
|
-
// WordPress < 6.0?
|
|
125
|
-
if (_moment.default.localeData(dateSettings.l10n.locale).longDateFormat('LTS') === null) {
|
|
126
|
-
// Delete the misconfigured locale.
|
|
127
|
-
// @ts-ignore Type definitions are incorrect - null is permitted.
|
|
128
|
-
_moment.default.defineLocale(dateSettings.l10n.locale, null);
|
|
123
|
+
if (import_moment.default.locales().includes(dateSettings.l10n.locale)) {
|
|
124
|
+
if (import_moment.default.localeData(dateSettings.l10n.locale).longDateFormat("LTS") === null) {
|
|
125
|
+
import_moment.default.defineLocale(dateSettings.l10n.locale, null);
|
|
129
126
|
} else {
|
|
130
|
-
// We have a properly configured locale, so no need to create one.
|
|
131
127
|
return;
|
|
132
128
|
}
|
|
133
129
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const currentLocale = _moment.default.locale();
|
|
137
|
-
|
|
138
|
-
// Create locale.
|
|
139
|
-
_moment.default.defineLocale(dateSettings.l10n.locale, {
|
|
130
|
+
const currentLocale = import_moment.default.locale();
|
|
131
|
+
import_moment.default.defineLocale(dateSettings.l10n.locale, {
|
|
140
132
|
// Inherit anything missing from English. We don't load
|
|
141
133
|
// moment-with-locales.js so English is all there is.
|
|
142
|
-
parentLocale:
|
|
134
|
+
parentLocale: "en",
|
|
143
135
|
months: dateSettings.l10n.months,
|
|
144
136
|
monthsShort: dateSettings.l10n.monthsShort,
|
|
145
137
|
weekdays: dateSettings.l10n.weekdays,
|
|
@@ -152,100 +144,60 @@ function setSettings(dateSettings) {
|
|
|
152
144
|
},
|
|
153
145
|
longDateFormat: {
|
|
154
146
|
LT: dateSettings.formats.time,
|
|
155
|
-
LTS:
|
|
156
|
-
L:
|
|
147
|
+
LTS: import_moment.default.localeData("en").longDateFormat("LTS"),
|
|
148
|
+
L: import_moment.default.localeData("en").longDateFormat("L"),
|
|
157
149
|
LL: dateSettings.formats.date,
|
|
158
150
|
LLL: dateSettings.formats.datetime,
|
|
159
|
-
LLLL:
|
|
151
|
+
LLLL: import_moment.default.localeData("en").longDateFormat("LLLL")
|
|
160
152
|
},
|
|
161
153
|
// From human_time_diff?
|
|
162
154
|
// Set to `(number, withoutSuffix, key, isFuture) => {}` instead.
|
|
163
155
|
relativeTime: dateSettings.l10n.relative
|
|
164
156
|
});
|
|
165
|
-
|
|
166
|
-
// Restore the locale to what it was.
|
|
167
|
-
_moment.default.locale(currentLocale);
|
|
157
|
+
import_moment.default.locale(currentLocale);
|
|
168
158
|
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Returns the currently defined date settings.
|
|
172
|
-
*
|
|
173
|
-
* @return {DateSettings} Settings, including locale data.
|
|
174
|
-
*/
|
|
175
159
|
function getSettings() {
|
|
176
160
|
return settings;
|
|
177
161
|
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Returns the currently defined date settings.
|
|
181
|
-
*
|
|
182
|
-
* @deprecated
|
|
183
|
-
* @return {DateSettings} Settings, including locale data.
|
|
184
|
-
*/
|
|
185
162
|
function __experimentalGetSettings() {
|
|
186
|
-
(0,
|
|
187
|
-
since:
|
|
188
|
-
alternative:
|
|
163
|
+
(0, import_deprecated.default)("wp.date.__experimentalGetSettings", {
|
|
164
|
+
since: "6.1",
|
|
165
|
+
alternative: "wp.date.getSettings"
|
|
189
166
|
});
|
|
190
167
|
return getSettings();
|
|
191
168
|
}
|
|
192
169
|
function setupWPTimezone() {
|
|
193
|
-
|
|
194
|
-
const currentTimezone = _moment.default.tz.zone(settings.timezone.string);
|
|
195
|
-
|
|
196
|
-
// Check to see if we have a valid TZ data, if so, use it for the custom WP_ZONE timezone, otherwise just use the offset.
|
|
170
|
+
const currentTimezone = import_moment.default.tz.zone(settings.timezone.string);
|
|
197
171
|
if (currentTimezone) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}));
|
|
172
|
+
import_moment.default.tz.add(
|
|
173
|
+
import_moment.default.tz.pack({
|
|
174
|
+
name: WP_ZONE,
|
|
175
|
+
abbrs: currentTimezone.abbrs,
|
|
176
|
+
untils: currentTimezone.untils,
|
|
177
|
+
offsets: currentTimezone.offsets
|
|
178
|
+
})
|
|
179
|
+
);
|
|
207
180
|
} else {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
181
|
+
import_moment.default.tz.add(
|
|
182
|
+
import_moment.default.tz.pack({
|
|
183
|
+
name: WP_ZONE,
|
|
184
|
+
abbrs: [WP_ZONE],
|
|
185
|
+
untils: [null],
|
|
186
|
+
offsets: [-settings.timezone.offset * 60 || 0]
|
|
187
|
+
})
|
|
188
|
+
);
|
|
215
189
|
}
|
|
216
190
|
}
|
|
217
|
-
|
|
218
|
-
// Date constants.
|
|
219
|
-
/**
|
|
220
|
-
* Number of seconds in one minute.
|
|
221
|
-
*/
|
|
222
191
|
const MINUTE_IN_SECONDS = 60;
|
|
223
|
-
/**
|
|
224
|
-
* Number of minutes in one hour.
|
|
225
|
-
*/
|
|
226
192
|
const HOUR_IN_MINUTES = 60;
|
|
227
|
-
/**
|
|
228
|
-
* Number of seconds in one hour.
|
|
229
|
-
*/
|
|
230
193
|
const HOUR_IN_SECONDS = 60 * MINUTE_IN_SECONDS;
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Map of PHP formats to Moment.js formats.
|
|
234
|
-
*
|
|
235
|
-
* These are used internally by {@link format}, and are either
|
|
236
|
-
* a string representing the corresponding Moment.js format code, or a
|
|
237
|
-
* function which returns the formatted string.
|
|
238
|
-
*
|
|
239
|
-
* This should only be used through {@link format}, not
|
|
240
|
-
* directly.
|
|
241
|
-
*/
|
|
242
194
|
const formatMap = {
|
|
243
195
|
// Day.
|
|
244
|
-
d:
|
|
245
|
-
D:
|
|
246
|
-
j:
|
|
247
|
-
l:
|
|
248
|
-
N:
|
|
196
|
+
d: "DD",
|
|
197
|
+
D: "ddd",
|
|
198
|
+
j: "D",
|
|
199
|
+
l: "dddd",
|
|
200
|
+
N: "E",
|
|
249
201
|
/**
|
|
250
202
|
* Gets the ordinal suffix.
|
|
251
203
|
*
|
|
@@ -254,12 +206,11 @@ const formatMap = {
|
|
|
254
206
|
* @return Formatted date.
|
|
255
207
|
*/
|
|
256
208
|
S(momentDate) {
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
return withOrdinal.replace(num, '');
|
|
209
|
+
const num = momentDate.format("D");
|
|
210
|
+
const withOrdinal = momentDate.format("Do");
|
|
211
|
+
return withOrdinal.replace(num, "");
|
|
261
212
|
},
|
|
262
|
-
w:
|
|
213
|
+
w: "d",
|
|
263
214
|
/**
|
|
264
215
|
* Gets the day of the year (zero-indexed).
|
|
265
216
|
*
|
|
@@ -268,16 +219,15 @@ const formatMap = {
|
|
|
268
219
|
* @return Formatted date.
|
|
269
220
|
*/
|
|
270
221
|
z(momentDate) {
|
|
271
|
-
|
|
272
|
-
return (parseInt(momentDate.format('DDD'), 10) - 1).toString();
|
|
222
|
+
return (parseInt(momentDate.format("DDD"), 10) - 1).toString();
|
|
273
223
|
},
|
|
274
224
|
// Week.
|
|
275
|
-
W:
|
|
225
|
+
W: "W",
|
|
276
226
|
// Month.
|
|
277
|
-
F:
|
|
278
|
-
m:
|
|
279
|
-
M:
|
|
280
|
-
n:
|
|
227
|
+
F: "MMMM",
|
|
228
|
+
m: "MM",
|
|
229
|
+
M: "MMM",
|
|
230
|
+
n: "M",
|
|
281
231
|
/**
|
|
282
232
|
* Gets the days in the month.
|
|
283
233
|
*
|
|
@@ -297,14 +247,14 @@ const formatMap = {
|
|
|
297
247
|
* @return Formatted date.
|
|
298
248
|
*/
|
|
299
249
|
L(momentDate) {
|
|
300
|
-
return momentDate.isLeapYear() ?
|
|
250
|
+
return momentDate.isLeapYear() ? "1" : "0";
|
|
301
251
|
},
|
|
302
|
-
o:
|
|
303
|
-
Y:
|
|
304
|
-
y:
|
|
252
|
+
o: "GGGG",
|
|
253
|
+
Y: "YYYY",
|
|
254
|
+
y: "YY",
|
|
305
255
|
// Time.
|
|
306
|
-
a:
|
|
307
|
-
A:
|
|
256
|
+
a: "a",
|
|
257
|
+
A: "A",
|
|
308
258
|
/**
|
|
309
259
|
* Gets the current time in Swatch Internet Time (.beats).
|
|
310
260
|
*
|
|
@@ -313,22 +263,23 @@ const formatMap = {
|
|
|
313
263
|
* @return Formatted date.
|
|
314
264
|
*/
|
|
315
265
|
B(momentDate) {
|
|
316
|
-
const timezoned = (0,
|
|
317
|
-
const seconds = parseInt(timezoned.format(
|
|
318
|
-
|
|
319
|
-
hours
|
|
320
|
-
|
|
266
|
+
const timezoned = (0, import_moment.default)(momentDate).utcOffset(60);
|
|
267
|
+
const seconds = parseInt(timezoned.format("s"), 10), minutes = parseInt(timezoned.format("m"), 10), hours = parseInt(timezoned.format("H"), 10);
|
|
268
|
+
return parseInt(
|
|
269
|
+
((seconds + minutes * MINUTE_IN_SECONDS + hours * HOUR_IN_SECONDS) / 86.4).toString(),
|
|
270
|
+
10
|
|
271
|
+
);
|
|
321
272
|
},
|
|
322
|
-
g:
|
|
323
|
-
G:
|
|
324
|
-
h:
|
|
325
|
-
H:
|
|
326
|
-
i:
|
|
327
|
-
s:
|
|
328
|
-
u:
|
|
329
|
-
v:
|
|
273
|
+
g: "h",
|
|
274
|
+
G: "H",
|
|
275
|
+
h: "hh",
|
|
276
|
+
H: "HH",
|
|
277
|
+
i: "mm",
|
|
278
|
+
s: "ss",
|
|
279
|
+
u: "SSSSSS",
|
|
280
|
+
v: "SSS",
|
|
330
281
|
// Timezone.
|
|
331
|
-
e:
|
|
282
|
+
e: "zz",
|
|
332
283
|
/**
|
|
333
284
|
* Gets whether the timezone is in DST currently.
|
|
334
285
|
*
|
|
@@ -337,11 +288,11 @@ const formatMap = {
|
|
|
337
288
|
* @return Formatted date.
|
|
338
289
|
*/
|
|
339
290
|
I(momentDate) {
|
|
340
|
-
return momentDate.isDST() ?
|
|
291
|
+
return momentDate.isDST() ? "1" : "0";
|
|
341
292
|
},
|
|
342
|
-
O:
|
|
343
|
-
P:
|
|
344
|
-
T:
|
|
293
|
+
O: "ZZ",
|
|
294
|
+
P: "Z",
|
|
295
|
+
T: "z",
|
|
345
296
|
/**
|
|
346
297
|
* Gets the timezone offset in seconds.
|
|
347
298
|
*
|
|
@@ -350,14 +301,13 @@ const formatMap = {
|
|
|
350
301
|
* @return Formatted date.
|
|
351
302
|
*/
|
|
352
303
|
Z(momentDate) {
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const parts = offset.substring(1).split(':').map(n => parseInt(n, 10));
|
|
304
|
+
const offset = momentDate.format("Z");
|
|
305
|
+
const sign = offset[0] === "-" ? -1 : 1;
|
|
306
|
+
const parts = offset.substring(1).split(":").map((n) => parseInt(n, 10));
|
|
357
307
|
return sign * (parts[0] * HOUR_IN_MINUTES + parts[1]) * MINUTE_IN_SECONDS;
|
|
358
308
|
},
|
|
359
309
|
// Full date/time.
|
|
360
|
-
c:
|
|
310
|
+
c: "YYYY-MM-DDTHH:mm:ssZ",
|
|
361
311
|
// .toISOString.
|
|
362
312
|
/**
|
|
363
313
|
* Formats the date as RFC2822.
|
|
@@ -367,197 +317,77 @@ const formatMap = {
|
|
|
367
317
|
* @return Formatted date.
|
|
368
318
|
*/
|
|
369
319
|
r(momentDate) {
|
|
370
|
-
return momentDate.locale(
|
|
320
|
+
return momentDate.locale("en").format("ddd, DD MMM YYYY HH:mm:ss ZZ");
|
|
371
321
|
},
|
|
372
|
-
U:
|
|
322
|
+
U: "X"
|
|
373
323
|
};
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Formats a date. Does not alter the date's timezone.
|
|
377
|
-
*
|
|
378
|
-
* @param dateFormat PHP-style formatting string.
|
|
379
|
-
* See [php.net/date](https://www.php.net/manual/en/function.date.php).
|
|
380
|
-
* @param dateValue Date object or string,
|
|
381
|
-
* parsable by moment.js.
|
|
382
|
-
*
|
|
383
|
-
* @return Formatted date.
|
|
384
|
-
*/
|
|
385
|
-
function format(dateFormat, dateValue = new Date()) {
|
|
324
|
+
function format(dateFormat, dateValue = /* @__PURE__ */ new Date()) {
|
|
386
325
|
let i, char;
|
|
387
326
|
const newFormat = [];
|
|
388
|
-
const momentDate = (0,
|
|
327
|
+
const momentDate = (0, import_moment.default)(dateValue);
|
|
389
328
|
for (i = 0; i < dateFormat.length; i++) {
|
|
390
329
|
char = dateFormat[i];
|
|
391
|
-
|
|
392
|
-
if ('\\' === char) {
|
|
393
|
-
// Add next character, then move on.
|
|
330
|
+
if ("\\" === char) {
|
|
394
331
|
i++;
|
|
395
|
-
newFormat.push(
|
|
332
|
+
newFormat.push("[" + dateFormat[i] + "]");
|
|
396
333
|
continue;
|
|
397
334
|
}
|
|
398
335
|
if (char in formatMap) {
|
|
399
336
|
const formatter = formatMap[char];
|
|
400
|
-
if (typeof formatter !==
|
|
401
|
-
|
|
402
|
-
newFormat.push('[' + formatter(momentDate) + ']');
|
|
337
|
+
if (typeof formatter !== "string") {
|
|
338
|
+
newFormat.push("[" + formatter(momentDate) + "]");
|
|
403
339
|
} else {
|
|
404
|
-
// Otherwise, add as a formatting string.
|
|
405
340
|
newFormat.push(formatter);
|
|
406
341
|
}
|
|
407
342
|
} else {
|
|
408
|
-
newFormat.push(
|
|
343
|
+
newFormat.push("[" + char + "]");
|
|
409
344
|
}
|
|
410
345
|
}
|
|
411
|
-
|
|
412
|
-
// unneeded separators with static text.
|
|
413
|
-
return momentDate.format(newFormat.join('[]'));
|
|
346
|
+
return momentDate.format(newFormat.join("[]"));
|
|
414
347
|
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Formats a date (like `date()` in PHP).
|
|
418
|
-
*
|
|
419
|
-
* @param dateFormat PHP-style formatting string.
|
|
420
|
-
* See [php.net/date](https://www.php.net/manual/en/function.date.php).
|
|
421
|
-
* @param dateValue Date object or string, parsable
|
|
422
|
-
* by moment.js.
|
|
423
|
-
* @param timezone Timezone to output result in or a
|
|
424
|
-
* UTC offset. Defaults to timezone from
|
|
425
|
-
* site.
|
|
426
|
-
*
|
|
427
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
|
428
|
-
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
|
|
429
|
-
*
|
|
430
|
-
* @return {string} Formatted date in English.
|
|
431
|
-
*/
|
|
432
|
-
function date(dateFormat, dateValue = new Date(), timezone) {
|
|
348
|
+
function date(dateFormat, dateValue = /* @__PURE__ */ new Date(), timezone) {
|
|
433
349
|
const dateMoment = buildMoment(dateValue, timezone);
|
|
434
350
|
return format(dateFormat, dateMoment);
|
|
435
351
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
* Formats a date (like `date()` in PHP), in the UTC timezone.
|
|
439
|
-
*
|
|
440
|
-
* @param dateFormat PHP-style formatting string.
|
|
441
|
-
* See [php.net/date](https://www.php.net/manual/en/function.date.php).
|
|
442
|
-
* @param dateValue Date object or string,
|
|
443
|
-
* parsable by moment.js.
|
|
444
|
-
*
|
|
445
|
-
* @return Formatted date in English.
|
|
446
|
-
*/
|
|
447
|
-
function gmdate(dateFormat, dateValue = new Date()) {
|
|
448
|
-
const dateMoment = (0, _moment.default)(dateValue).utc();
|
|
352
|
+
function gmdate(dateFormat, dateValue = /* @__PURE__ */ new Date()) {
|
|
353
|
+
const dateMoment = (0, import_moment.default)(dateValue).utc();
|
|
449
354
|
return format(dateFormat, dateMoment);
|
|
450
355
|
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Formats a date (like `wp_date()` in PHP), translating it into site's locale.
|
|
454
|
-
*
|
|
455
|
-
* Backward Compatibility Notice: if `timezone` is set to `true`, the function
|
|
456
|
-
* behaves like `gmdateI18n`.
|
|
457
|
-
*
|
|
458
|
-
* @param dateFormat PHP-style formatting string.
|
|
459
|
-
* See [php.net/date](https://www.php.net/manual/en/function.date.php).
|
|
460
|
-
* @param dateValue Date object or string, parsable by
|
|
461
|
-
* moment.js.
|
|
462
|
-
* @param timezone Timezone to output result in or a
|
|
463
|
-
* UTC offset. Defaults to timezone from
|
|
464
|
-
* site. Notice: `boolean` is effectively
|
|
465
|
-
* deprecated, but still supported for
|
|
466
|
-
* backward compatibility reasons.
|
|
467
|
-
*
|
|
468
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
|
469
|
-
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
|
|
470
|
-
*
|
|
471
|
-
* @return Formatted date.
|
|
472
|
-
*/
|
|
473
|
-
function dateI18n(dateFormat, dateValue = new Date(), timezone) {
|
|
356
|
+
function dateI18n(dateFormat, dateValue = /* @__PURE__ */ new Date(), timezone) {
|
|
474
357
|
if (true === timezone) {
|
|
475
358
|
return gmdateI18n(dateFormat, dateValue);
|
|
476
359
|
}
|
|
477
360
|
if (false === timezone) {
|
|
478
|
-
timezone =
|
|
361
|
+
timezone = void 0;
|
|
479
362
|
}
|
|
480
363
|
const dateMoment = buildMoment(dateValue, timezone);
|
|
481
364
|
dateMoment.locale(settings.l10n.locale);
|
|
482
365
|
return format(dateFormat, dateMoment);
|
|
483
366
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
* Formats a date (like `wp_date()` in PHP), translating it into site's locale
|
|
487
|
-
* and using the UTC timezone.
|
|
488
|
-
*
|
|
489
|
-
* @param dateFormat PHP-style formatting string.
|
|
490
|
-
* See [php.net/date](https://www.php.net/manual/en/function.date.php).
|
|
491
|
-
* @param dateValue Date object or string,
|
|
492
|
-
* parsable by moment.js.
|
|
493
|
-
*
|
|
494
|
-
* @return Formatted date.
|
|
495
|
-
*/
|
|
496
|
-
function gmdateI18n(dateFormat, dateValue = new Date()) {
|
|
497
|
-
const dateMoment = (0, _moment.default)(dateValue).utc();
|
|
367
|
+
function gmdateI18n(dateFormat, dateValue = /* @__PURE__ */ new Date()) {
|
|
368
|
+
const dateMoment = (0, import_moment.default)(dateValue).utc();
|
|
498
369
|
dateMoment.locale(settings.l10n.locale);
|
|
499
370
|
return format(dateFormat, dateMoment);
|
|
500
371
|
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Check whether a date is considered in the future according to the WordPress settings.
|
|
504
|
-
*
|
|
505
|
-
* @param dateValue Date String or Date object in the Defined WP Timezone.
|
|
506
|
-
*
|
|
507
|
-
* @return Is in the future.
|
|
508
|
-
*/
|
|
509
372
|
function isInTheFuture(dateValue) {
|
|
510
|
-
const now =
|
|
511
|
-
const momentObject =
|
|
373
|
+
const now = import_moment.default.tz(WP_ZONE);
|
|
374
|
+
const momentObject = import_moment.default.tz(dateValue, WP_ZONE);
|
|
512
375
|
return momentObject.isAfter(now);
|
|
513
376
|
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Create and return a JavaScript Date Object from a date string in the WP timezone.
|
|
517
|
-
*
|
|
518
|
-
* @param dateString Date formatted in the WP timezone.
|
|
519
|
-
*
|
|
520
|
-
* @return Date
|
|
521
|
-
*/
|
|
522
377
|
function getDate(dateString) {
|
|
523
378
|
if (!dateString) {
|
|
524
|
-
return
|
|
379
|
+
return import_moment.default.tz(WP_ZONE).toDate();
|
|
525
380
|
}
|
|
526
|
-
return
|
|
381
|
+
return import_moment.default.tz(dateString, WP_ZONE).toDate();
|
|
527
382
|
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Returns a human-readable time difference between two dates, like human_time_diff() in PHP.
|
|
531
|
-
*
|
|
532
|
-
* @param from From date, in the WP timezone.
|
|
533
|
-
* @param to To date, formatted in the WP timezone.
|
|
534
|
-
*
|
|
535
|
-
* @return Human-readable time difference.
|
|
536
|
-
*/
|
|
537
383
|
function humanTimeDiff(from, to) {
|
|
538
|
-
const fromMoment =
|
|
539
|
-
const toMoment = to ?
|
|
384
|
+
const fromMoment = import_moment.default.tz(from, WP_ZONE);
|
|
385
|
+
const toMoment = to ? import_moment.default.tz(to, WP_ZONE) : import_moment.default.tz(WP_ZONE);
|
|
540
386
|
return fromMoment.from(toMoment);
|
|
541
387
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
* Creates a moment instance using the given timezone or, if none is provided, using global settings.
|
|
545
|
-
*
|
|
546
|
-
* @param dateValue Date object or string, parsable
|
|
547
|
-
* by moment.js.
|
|
548
|
-
* @param timezone Timezone to output result in or a
|
|
549
|
-
* UTC offset. Defaults to timezone from
|
|
550
|
-
* site.
|
|
551
|
-
*
|
|
552
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
|
553
|
-
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
|
|
554
|
-
*
|
|
555
|
-
* @return A moment instance.
|
|
556
|
-
*/
|
|
557
|
-
function buildMoment(dateValue, timezone = '') {
|
|
558
|
-
const dateMoment = (0, _moment.default)(dateValue);
|
|
388
|
+
function buildMoment(dateValue, timezone = "") {
|
|
389
|
+
const dateMoment = (0, import_moment.default)(dateValue);
|
|
559
390
|
if (timezone && !isUTCOffset(timezone)) {
|
|
560
|
-
// The ! isUTCOffset() check guarantees that timezone is a string.
|
|
561
391
|
return dateMoment.tz(timezone);
|
|
562
392
|
}
|
|
563
393
|
if (timezone && isUTCOffset(timezone)) {
|
|
@@ -568,19 +398,26 @@ function buildMoment(dateValue, timezone = '') {
|
|
|
568
398
|
}
|
|
569
399
|
return dateMoment.utcOffset(+settings.timezone.offset);
|
|
570
400
|
}
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Returns whether a certain UTC offset is valid or not.
|
|
574
|
-
*
|
|
575
|
-
* @param offset a UTC offset.
|
|
576
|
-
*
|
|
577
|
-
* @return whether a certain UTC offset is valid or not.
|
|
578
|
-
*/
|
|
579
401
|
function isUTCOffset(offset) {
|
|
580
|
-
if (
|
|
402
|
+
if ("number" === typeof offset) {
|
|
581
403
|
return true;
|
|
582
404
|
}
|
|
583
405
|
return VALID_UTC_OFFSET.test(offset);
|
|
584
406
|
}
|
|
585
407
|
setupWPTimezone();
|
|
586
|
-
|
|
408
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
409
|
+
0 && (module.exports = {
|
|
410
|
+
__experimentalGetSettings,
|
|
411
|
+
date,
|
|
412
|
+
dateI18n,
|
|
413
|
+
format,
|
|
414
|
+
getDate,
|
|
415
|
+
getSettings,
|
|
416
|
+
gmdate,
|
|
417
|
+
gmdateI18n,
|
|
418
|
+
humanTimeDiff,
|
|
419
|
+
isInTheFuture,
|
|
420
|
+
setSettings,
|
|
421
|
+
...require("./types")
|
|
422
|
+
});
|
|
423
|
+
//# sourceMappingURL=index.js.map
|