@wordpress/date 5.31.1-next.f56bd8138.0 → 5.32.1-next.47f435fc9.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 CHANGED
@@ -1,145 +1,137 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- var _exportNames = {
8
- setSettings: true,
9
- getSettings: true,
10
- __experimentalGetSettings: true,
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
- exports.__experimentalGetSettings = __experimentalGetSettings;
21
- exports.date = date;
22
- exports.dateI18n = dateI18n;
23
- exports.format = format;
24
- exports.getDate = getDate;
25
- exports.getSettings = getSettings;
26
- exports.gmdate = gmdate;
27
- exports.gmdateI18n = gmdateI18n;
28
- exports.humanTimeDiff = humanTimeDiff;
29
- exports.isInTheFuture = isInTheFuture;
30
- exports.setSettings = setSettings;
31
- var _moment = _interopRequireDefault(require("moment"));
32
- require("moment-timezone/moment-timezone");
33
- require("moment-timezone/moment-timezone-utils");
34
- var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
35
- var _types = require("./types");
36
- Object.keys(_types).forEach(function (key) {
37
- if (key === "default" || key === "__esModule") return;
38
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
39
- if (key in exports && exports[key] === _types[key]) return;
40
- Object.defineProperty(exports, key, {
41
- enumerable: true,
42
- get: function () {
43
- return _types[key];
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
- * External dependencies
49
- */
50
-
51
- /**
52
- * WordPress dependencies
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: 'en',
70
- months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
71
- monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
72
- weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
73
- weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
74
- meridiem: {
75
- am: 'am',
76
- pm: 'pm',
77
- AM: 'AM',
78
- PM: 'PM'
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: '%s from now',
82
- past: '%s ago',
83
- s: 'a few seconds',
84
- ss: '%d seconds',
85
- m: 'a minute',
86
- mm: '%d minutes',
87
- h: 'an hour',
88
- hh: '%d hours',
89
- d: 'a day',
90
- dd: '%d days',
91
- M: 'a month',
92
- MM: '%d months',
93
- y: 'a year',
94
- yy: '%d years'
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: 'g: i a',
100
- date: 'F j, Y',
101
- datetime: 'F j, Y g: i a',
102
- datetimeAbbreviated: 'M j, Y g: i a'
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
- // Does moment already have a locale with the right name?
122
- if (_moment.default.locales().includes(dateSettings.l10n.locale)) {
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
- // defineLocale() will modify the current locale, so back it up.
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: 'en',
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: _moment.default.localeData('en').longDateFormat('LTS'),
156
- L: _moment.default.localeData('en').longDateFormat('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: _moment.default.localeData('en').longDateFormat('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, _deprecated.default)('wp.date.__experimentalGetSettings', {
187
- since: '6.1',
188
- alternative: 'wp.date.getSettings'
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
- // Get the current timezone settings from the WP timezone string.
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
- // Create WP timezone based off settings.timezone.string. We need to include the additional data so that we
199
- // don't lose information about daylight savings time and other items.
200
- // See https://github.com/WordPress/gutenberg/pull/48083
201
- _moment.default.tz.add(_moment.default.tz.pack({
202
- name: WP_ZONE,
203
- abbrs: currentTimezone.abbrs,
204
- untils: currentTimezone.untils,
205
- offsets: currentTimezone.offsets
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
- // Create WP timezone based off dateSettings.
209
- _moment.default.tz.add(_moment.default.tz.pack({
210
- name: WP_ZONE,
211
- abbrs: [WP_ZONE],
212
- untils: [null],
213
- offsets: [-settings.timezone.offset * 60 || 0]
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: 'DD',
245
- D: 'ddd',
246
- j: 'D',
247
- l: 'dddd',
248
- N: 'E',
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
- // Do - D.
258
- const num = momentDate.format('D');
259
- const withOrdinal = momentDate.format('Do');
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: 'd',
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
- // DDD - 1.
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: 'W',
225
+ W: "W",
276
226
  // Month.
277
- F: 'MMMM',
278
- m: 'MM',
279
- M: 'MMM',
280
- n: 'M',
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() ? '1' : '0';
250
+ return momentDate.isLeapYear() ? "1" : "0";
301
251
  },
302
- o: 'GGGG',
303
- Y: 'YYYY',
304
- y: 'YY',
252
+ o: "GGGG",
253
+ Y: "YYYY",
254
+ y: "YY",
305
255
  // Time.
306
- a: 'a',
307
- A: '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, _moment.default)(momentDate).utcOffset(60);
317
- const seconds = parseInt(timezoned.format('s'), 10),
318
- minutes = parseInt(timezoned.format('m'), 10),
319
- hours = parseInt(timezoned.format('H'), 10);
320
- return parseInt(((seconds + minutes * MINUTE_IN_SECONDS + hours * HOUR_IN_SECONDS) / 86.4).toString(), 10);
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: 'h',
323
- G: 'H',
324
- h: 'hh',
325
- H: 'HH',
326
- i: 'mm',
327
- s: 'ss',
328
- u: 'SSSSSS',
329
- v: 'SSS',
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: 'zz',
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() ? '1' : '0';
291
+ return momentDate.isDST() ? "1" : "0";
341
292
  },
342
- O: 'ZZ',
343
- P: 'Z',
344
- T: 'z',
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
- // Timezone offset in seconds.
354
- const offset = momentDate.format('Z');
355
- const sign = offset[0] === '-' ? -1 : 1;
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: 'YYYY-MM-DDTHH:mm:ssZ',
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('en').format('ddd, DD MMM YYYY HH:mm:ss ZZ');
320
+ return momentDate.locale("en").format("ddd, DD MMM YYYY HH:mm:ss ZZ");
371
321
  },
372
- U: 'X'
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, _moment.default)(dateValue);
327
+ const momentDate = (0, import_moment.default)(dateValue);
389
328
  for (i = 0; i < dateFormat.length; i++) {
390
329
  char = dateFormat[i];
391
- // Is this an escape?
392
- if ('\\' === char) {
393
- // Add next character, then move on.
330
+ if ("\\" === char) {
394
331
  i++;
395
- newFormat.push('[' + dateFormat[i] + ']');
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 !== 'string') {
401
- // If the format is a function, call it.
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('[' + char + ']');
343
+ newFormat.push("[" + char + "]");
409
344
  }
410
345
  }
411
- // Join with [] between to separate characters, and replace
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 = undefined;
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 = _moment.default.tz(WP_ZONE);
511
- const momentObject = _moment.default.tz(dateValue, WP_ZONE);
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 _moment.default.tz(WP_ZONE).toDate();
379
+ return import_moment.default.tz(WP_ZONE).toDate();
525
380
  }
526
- return _moment.default.tz(dateString, WP_ZONE).toDate();
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 = _moment.default.tz(from, WP_ZONE);
539
- const toMoment = to ? _moment.default.tz(to, WP_ZONE) : _moment.default.tz(WP_ZONE);
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 ('number' === typeof offset) {
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
- //# sourceMappingURL=index.js.map
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