convex-cms 0.0.2 → 0.0.3
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/admin-dist/nitro.json +15 -0
- package/admin-dist/public/assets/CmsEmptyState-CRswfTzk.js +5 -0
- package/admin-dist/public/assets/CmsPageHeader-CirpXndm.js +1 -0
- package/admin-dist/public/assets/CmsStatusBadge-CbEUpQu-.js +1 -0
- package/admin-dist/public/assets/CmsToolbar-BI2nZOXp.js +1 -0
- package/admin-dist/public/assets/ContentEntryEditor-CBeCyK_m.js +4 -0
- package/admin-dist/public/assets/ErrorState-BIVaWmom.js +1 -0
- package/admin-dist/public/assets/TaxonomyFilter-ChaY6Y_x.js +1 -0
- package/admin-dist/public/assets/_contentTypeId-DQ8k_Rvw.js +1 -0
- package/admin-dist/public/assets/_entryId-CKU_glsK.js +1 -0
- package/admin-dist/public/assets/alert-BXjTqrwQ.js +1 -0
- package/admin-dist/public/assets/badge-hvUOzpVZ.js +1 -0
- package/admin-dist/public/assets/circle-check-big-CF_pR17r.js +1 -0
- package/admin-dist/public/assets/command-DU82cJlt.js +1 -0
- package/admin-dist/public/assets/content-_LXl3pp7.js +1 -0
- package/admin-dist/public/assets/content-types-KjxaXGxY.js +2 -0
- package/admin-dist/public/assets/globals-CS6BZ0zp.css +1 -0
- package/admin-dist/public/assets/index-DNGIZHL-.js +1 -0
- package/admin-dist/public/assets/label-KNtpL71g.js +1 -0
- package/admin-dist/public/assets/link-2-Bw2aI4V4.js +1 -0
- package/admin-dist/public/assets/list-sYepHjt_.js +1 -0
- package/admin-dist/public/assets/main-CKj5yfEi.js +97 -0
- package/admin-dist/public/assets/media-Bkrkffm7.js +1 -0
- package/admin-dist/public/assets/new._contentTypeId-C3LstjNs.js +1 -0
- package/admin-dist/public/assets/plus-DUn8v_Xf.js +1 -0
- package/admin-dist/public/assets/rotate-ccw-DJEoHcRI.js +1 -0
- package/admin-dist/public/assets/scroll-area-DfIlT0in.js +1 -0
- package/admin-dist/public/assets/search-MuAUDJKR.js +1 -0
- package/admin-dist/public/assets/select-BD29IXCI.js +1 -0
- package/admin-dist/public/assets/settings-DmMyn_6A.js +1 -0
- package/admin-dist/public/assets/switch-h3Rrnl5i.js +1 -0
- package/admin-dist/public/assets/tabs-imc8h-Dp.js +1 -0
- package/admin-dist/public/assets/taxonomies-dAsrT65H.js +1 -0
- package/admin-dist/public/assets/textarea-BTy7nwzR.js +1 -0
- package/admin-dist/public/assets/trash-SAWKZZHv.js +1 -0
- package/admin-dist/public/assets/triangle-alert-E52Vfeuh.js +1 -0
- package/admin-dist/public/assets/useBreadcrumbLabel-BECBMCzM.js +1 -0
- package/admin-dist/public/assets/usePermissions-Basjs9BT.js +1 -0
- package/admin-dist/public/favicon.ico +0 -0
- package/admin-dist/server/_chunks/_libs/@date-fns/tz.mjs +217 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/core.mjs +719 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/dom.mjs +622 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/react-dom.mjs +292 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/utils.mjs +320 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/number.mjs +6 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/primitive.mjs +11 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-arrow.mjs +23 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-avatar.mjs +119 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-checkbox.mjs +270 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-collection.mjs +69 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-compose-refs.mjs +39 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-context.mjs +137 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dialog.mjs +325 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-direction.mjs +9 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dismissable-layer.mjs +210 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dropdown-menu.mjs +253 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-guards.mjs +29 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-scope.mjs +206 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-id.mjs +14 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-label.mjs +23 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-menu.mjs +812 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-popover.mjs +300 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-popper.mjs +286 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-portal.mjs +16 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-presence.mjs +128 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-primitive.mjs +141 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-roving-focus.mjs +224 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-scroll-area.mjs +721 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-select.mjs +1163 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-separator.mjs +28 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-slot.mjs +601 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-switch.mjs +152 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-tabs.mjs +189 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-callback-ref.mjs +11 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-controllable-state.mjs +69 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-effect-event.mjs +1 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-escape-keydown.mjs +17 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-is-hydrated.mjs +15 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-layout-effect.mjs +6 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-previous.mjs +14 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-size.mjs +39 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-visually-hidden.mjs +33 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/history.mjs +409 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/react-router.mjs +1711 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/react-store.mjs +56 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/router-core.mjs +4829 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/store.mjs +134 -0
- package/admin-dist/server/_chunks/_libs/react-dom.mjs +10781 -0
- package/admin-dist/server/_chunks/_libs/react.mjs +513 -0
- package/admin-dist/server/_libs/aria-hidden.mjs +122 -0
- package/admin-dist/server/_libs/class-variance-authority.mjs +44 -0
- package/admin-dist/server/_libs/clsx.mjs +16 -0
- package/admin-dist/server/_libs/cmdk.mjs +315 -0
- package/admin-dist/server/_libs/convex.mjs +4841 -0
- package/admin-dist/server/_libs/cookie-es.mjs +58 -0
- package/admin-dist/server/_libs/croner.mjs +1 -0
- package/admin-dist/server/_libs/crossws.mjs +1 -0
- package/admin-dist/server/_libs/date-fns.mjs +1716 -0
- package/admin-dist/server/_libs/detect-node-es.mjs +1 -0
- package/admin-dist/server/_libs/get-nonce.mjs +9 -0
- package/admin-dist/server/_libs/h3-v2.mjs +277 -0
- package/admin-dist/server/_libs/h3.mjs +401 -0
- package/admin-dist/server/_libs/hookable.mjs +1 -0
- package/admin-dist/server/_libs/isbot.mjs +20 -0
- package/admin-dist/server/_libs/lucide-react.mjs +850 -0
- package/admin-dist/server/_libs/ohash.mjs +1 -0
- package/admin-dist/server/_libs/react-day-picker.mjs +2201 -0
- package/admin-dist/server/_libs/react-remove-scroll-bar.mjs +82 -0
- package/admin-dist/server/_libs/react-remove-scroll.mjs +328 -0
- package/admin-dist/server/_libs/react-style-singleton.mjs +69 -0
- package/admin-dist/server/_libs/rou3.mjs +8 -0
- package/admin-dist/server/_libs/seroval-plugins.mjs +58 -0
- package/admin-dist/server/_libs/seroval.mjs +1765 -0
- package/admin-dist/server/_libs/srvx.mjs +719 -0
- package/admin-dist/server/_libs/tailwind-merge.mjs +3010 -0
- package/admin-dist/server/_libs/tiny-invariant.mjs +12 -0
- package/admin-dist/server/_libs/tiny-warning.mjs +5 -0
- package/admin-dist/server/_libs/tslib.mjs +39 -0
- package/admin-dist/server/_libs/ufo.mjs +54 -0
- package/admin-dist/server/_libs/unctx.mjs +1 -0
- package/admin-dist/server/_libs/unstorage.mjs +1 -0
- package/admin-dist/server/_libs/use-callback-ref.mjs +66 -0
- package/admin-dist/server/_libs/use-sidecar.mjs +106 -0
- package/admin-dist/server/_libs/use-sync-external-store.mjs +139 -0
- package/admin-dist/server/_libs/zod.mjs +4223 -0
- package/admin-dist/server/_ssr/CmsEmptyState-DU7-7-mV.mjs +290 -0
- package/admin-dist/server/_ssr/CmsPageHeader-CseW0AHm.mjs +24 -0
- package/admin-dist/server/_ssr/CmsStatusBadge-B_pi4KCp.mjs +127 -0
- package/admin-dist/server/_ssr/CmsToolbar-X75ex6ek.mjs +49 -0
- package/admin-dist/server/_ssr/ContentEntryEditor-CepusRsA.mjs +3720 -0
- package/admin-dist/server/_ssr/ErrorState-cI-bKLez.mjs +89 -0
- package/admin-dist/server/_ssr/TaxonomyFilter-Bwrq0-cz.mjs +188 -0
- package/admin-dist/server/_ssr/_contentTypeId-BqYKEcLr.mjs +379 -0
- package/admin-dist/server/_ssr/_entryId-CRfnqeDf.mjs +161 -0
- package/admin-dist/server/_ssr/_tanstack-start-manifest_v-BwDlABVk.mjs +4 -0
- package/admin-dist/server/_ssr/alert-CVt45UUP.mjs +92 -0
- package/admin-dist/server/_ssr/badge-6BsP37vG.mjs +125 -0
- package/admin-dist/server/_ssr/command-fy8epIKf.mjs +128 -0
- package/admin-dist/server/_ssr/config.server-D7JHDcDv.mjs +117 -0
- package/admin-dist/server/_ssr/content-B5RhL7uW.mjs +532 -0
- package/admin-dist/server/_ssr/content-types-BIOqCQYN.mjs +1166 -0
- package/admin-dist/server/_ssr/index-DHSHDPt1.mjs +193 -0
- package/admin-dist/server/_ssr/index.mjs +1275 -0
- package/admin-dist/server/_ssr/label-C8Dko1j7.mjs +22 -0
- package/admin-dist/server/_ssr/media-CSx3XttC.mjs +1832 -0
- package/admin-dist/server/_ssr/new._contentTypeId-DzanEZQM.mjs +144 -0
- package/admin-dist/server/_ssr/router-DDWcF-kt.mjs +1556 -0
- package/admin-dist/server/_ssr/scroll-area-bjPYwhXN.mjs +59 -0
- package/admin-dist/server/_ssr/select-BUhDDf4T.mjs +142 -0
- package/admin-dist/server/_ssr/settings-DAsxnw2q.mjs +348 -0
- package/admin-dist/server/_ssr/start-HYkvq4Ni.mjs +4 -0
- package/admin-dist/server/_ssr/switch-BgyRtQ1Z.mjs +31 -0
- package/admin-dist/server/_ssr/tabs-DzMdRB1A.mjs +628 -0
- package/admin-dist/server/_ssr/taxonomies-C8j8g5Q5.mjs +915 -0
- package/admin-dist/server/_ssr/textarea-9jNeYJSc.mjs +18 -0
- package/admin-dist/server/_ssr/trash-DYMxwhZB.mjs +291 -0
- package/admin-dist/server/_ssr/useBreadcrumbLabel-FNSAr2Ha.mjs +16 -0
- package/admin-dist/server/_ssr/usePermissions-BJGGahrJ.mjs +68 -0
- package/admin-dist/server/favicon.ico +0 -0
- package/admin-dist/server/index.mjs +627 -0
- package/dist/cli/index.js +0 -0
- package/dist/client/admin-config.d.ts +0 -1
- package/dist/client/admin-config.d.ts.map +1 -1
- package/dist/client/admin-config.js +0 -1
- package/dist/client/admin-config.js.map +1 -1
- package/dist/client/adminApi.d.ts.map +1 -1
- package/dist/client/agentTools.d.ts +1237 -135
- package/dist/client/agentTools.d.ts.map +1 -1
- package/dist/client/agentTools.js +33 -9
- package/dist/client/agentTools.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/component.d.ts +9 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/mediaAssets.d.ts +35 -0
- package/dist/component/mediaAssets.d.ts.map +1 -1
- package/dist/component/mediaAssets.js +81 -0
- package/dist/component/mediaAssets.js.map +1 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +2 -1
- package/dist/test.js.map +1 -1
- package/package.json +9 -5
- package/dist/component/auditLog.d.ts +0 -410
- package/dist/component/auditLog.d.ts.map +0 -1
- package/dist/component/auditLog.js +0 -607
- package/dist/component/auditLog.js.map +0 -1
- package/dist/component/types.d.ts +0 -4
- package/dist/component/types.d.ts.map +0 -1
- package/dist/component/types.js +0 -2
- package/dist/component/types.js.map +0 -1
- package/src/cli/commands/admin.ts +0 -104
- package/src/cli/index.ts +0 -21
- package/src/cli/utils/detectConvexUrl.ts +0 -54
- package/src/cli/utils/openBrowser.ts +0 -16
- package/src/client/admin-config.ts +0 -138
- package/src/client/adminApi.ts +0 -942
- package/src/client/agentTools.ts +0 -1311
- package/src/client/argTypes.ts +0 -316
- package/src/client/field-types.ts +0 -187
- package/src/client/index.ts +0 -1301
- package/src/client/queryBuilder.ts +0 -1100
- package/src/client/schema/codegen.ts +0 -500
- package/src/client/schema/defineContentType.ts +0 -501
- package/src/client/schema/index.ts +0 -169
- package/src/client/schema/schemaDrift.ts +0 -574
- package/src/client/schema/typedClient.ts +0 -688
- package/src/client/schema/types.ts +0 -666
- package/src/client/types.ts +0 -723
- package/src/client/workflows.ts +0 -141
- package/src/client/wrapper.ts +0 -4304
- package/src/component/_generated/api.ts +0 -140
- package/src/component/_generated/component.ts +0 -5029
- package/src/component/_generated/dataModel.ts +0 -60
- package/src/component/_generated/server.ts +0 -156
- package/src/component/authorization.ts +0 -647
- package/src/component/authorizationHooks.ts +0 -668
- package/src/component/bulkOperations.ts +0 -687
- package/src/component/contentEntries.ts +0 -1976
- package/src/component/contentEntryMutations.ts +0 -1223
- package/src/component/contentEntryValidation.ts +0 -707
- package/src/component/contentLock.ts +0 -550
- package/src/component/contentTypeMigration.ts +0 -1064
- package/src/component/contentTypeMutations.ts +0 -969
- package/src/component/contentTypes.ts +0 -346
- package/src/component/convex.config.ts +0 -44
- package/src/component/documentTypes.ts +0 -240
- package/src/component/eventEmitter.ts +0 -485
- package/src/component/exportImport.ts +0 -1169
- package/src/component/index.ts +0 -491
- package/src/component/lib/deepReferenceResolver.ts +0 -999
- package/src/component/lib/errors.ts +0 -816
- package/src/component/lib/index.ts +0 -145
- package/src/component/lib/mediaReferenceResolver.ts +0 -495
- package/src/component/lib/metadataExtractor.ts +0 -792
- package/src/component/lib/mutationAuth.ts +0 -199
- package/src/component/lib/queries.ts +0 -79
- package/src/component/lib/ragContentChunker.ts +0 -1371
- package/src/component/lib/referenceResolver.ts +0 -430
- package/src/component/lib/slugGenerator.ts +0 -262
- package/src/component/lib/slugUniqueness.ts +0 -333
- package/src/component/lib/softDelete.ts +0 -44
- package/src/component/localeFallbackChain.ts +0 -673
- package/src/component/localeFields.ts +0 -896
- package/src/component/mediaAssetMutations.ts +0 -725
- package/src/component/mediaAssets.ts +0 -932
- package/src/component/mediaFolderMutations.ts +0 -1046
- package/src/component/mediaUploadMutations.ts +0 -224
- package/src/component/mediaVariantMutations.ts +0 -900
- package/src/component/mediaVariants.ts +0 -793
- package/src/component/ragContentIndexer.ts +0 -1067
- package/src/component/rateLimitHooks.ts +0 -572
- package/src/component/roles.ts +0 -1360
- package/src/component/scheduledPublish.ts +0 -358
- package/src/component/schema.ts +0 -617
- package/src/component/taxonomies.ts +0 -949
- package/src/component/taxonomyMutations.ts +0 -1210
- package/src/component/trash.ts +0 -724
- package/src/component/userContext.ts +0 -898
- package/src/component/validation.ts +0 -1388
- package/src/component/validators.ts +0 -949
- package/src/component/versionMutations.ts +0 -392
- package/src/component/webhookTrigger.ts +0 -1922
- package/src/react/index.ts +0 -898
- package/src/test.ts +0 -1580
|
@@ -0,0 +1,1716 @@
|
|
|
1
|
+
const millisecondsInWeek = 6048e5;
|
|
2
|
+
const millisecondsInDay = 864e5;
|
|
3
|
+
const constructFromSymbol = Symbol.for("constructDateFrom");
|
|
4
|
+
function constructFrom(date, value) {
|
|
5
|
+
if (typeof date === "function") return date(value);
|
|
6
|
+
if (date && typeof date === "object" && constructFromSymbol in date)
|
|
7
|
+
return date[constructFromSymbol](value);
|
|
8
|
+
if (date instanceof Date) return new date.constructor(value);
|
|
9
|
+
return new Date(value);
|
|
10
|
+
}
|
|
11
|
+
function toDate(argument, context) {
|
|
12
|
+
return constructFrom(context || argument, argument);
|
|
13
|
+
}
|
|
14
|
+
function addDays(date, amount, options) {
|
|
15
|
+
const _date = toDate(date, options?.in);
|
|
16
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
17
|
+
if (!amount) return _date;
|
|
18
|
+
_date.setDate(_date.getDate() + amount);
|
|
19
|
+
return _date;
|
|
20
|
+
}
|
|
21
|
+
function addMonths(date, amount, options) {
|
|
22
|
+
const _date = toDate(date, options?.in);
|
|
23
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
24
|
+
if (!amount) {
|
|
25
|
+
return _date;
|
|
26
|
+
}
|
|
27
|
+
const dayOfMonth = _date.getDate();
|
|
28
|
+
const endOfDesiredMonth = constructFrom(date, _date.getTime());
|
|
29
|
+
endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
|
|
30
|
+
const daysInMonth = endOfDesiredMonth.getDate();
|
|
31
|
+
if (dayOfMonth >= daysInMonth) {
|
|
32
|
+
return endOfDesiredMonth;
|
|
33
|
+
} else {
|
|
34
|
+
_date.setFullYear(
|
|
35
|
+
endOfDesiredMonth.getFullYear(),
|
|
36
|
+
endOfDesiredMonth.getMonth(),
|
|
37
|
+
dayOfMonth
|
|
38
|
+
);
|
|
39
|
+
return _date;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let defaultOptions = {};
|
|
43
|
+
function getDefaultOptions() {
|
|
44
|
+
return defaultOptions;
|
|
45
|
+
}
|
|
46
|
+
function startOfWeek(date, options) {
|
|
47
|
+
const defaultOptions2 = getDefaultOptions();
|
|
48
|
+
const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
|
|
49
|
+
const _date = toDate(date, options?.in);
|
|
50
|
+
const day = _date.getDay();
|
|
51
|
+
const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
|
52
|
+
_date.setDate(_date.getDate() - diff);
|
|
53
|
+
_date.setHours(0, 0, 0, 0);
|
|
54
|
+
return _date;
|
|
55
|
+
}
|
|
56
|
+
function startOfISOWeek(date, options) {
|
|
57
|
+
return startOfWeek(date, { ...options, weekStartsOn: 1 });
|
|
58
|
+
}
|
|
59
|
+
function getISOWeekYear(date, options) {
|
|
60
|
+
const _date = toDate(date, options?.in);
|
|
61
|
+
const year = _date.getFullYear();
|
|
62
|
+
const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
|
|
63
|
+
fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
|
|
64
|
+
fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
|
|
65
|
+
const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
|
|
66
|
+
const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
|
|
67
|
+
fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
|
|
68
|
+
fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
|
|
69
|
+
const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
|
|
70
|
+
if (_date.getTime() >= startOfNextYear.getTime()) {
|
|
71
|
+
return year + 1;
|
|
72
|
+
} else if (_date.getTime() >= startOfThisYear.getTime()) {
|
|
73
|
+
return year;
|
|
74
|
+
} else {
|
|
75
|
+
return year - 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getTimezoneOffsetInMilliseconds(date) {
|
|
79
|
+
const _date = toDate(date);
|
|
80
|
+
const utcDate = new Date(
|
|
81
|
+
Date.UTC(
|
|
82
|
+
_date.getFullYear(),
|
|
83
|
+
_date.getMonth(),
|
|
84
|
+
_date.getDate(),
|
|
85
|
+
_date.getHours(),
|
|
86
|
+
_date.getMinutes(),
|
|
87
|
+
_date.getSeconds(),
|
|
88
|
+
_date.getMilliseconds()
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
utcDate.setUTCFullYear(_date.getFullYear());
|
|
92
|
+
return +date - +utcDate;
|
|
93
|
+
}
|
|
94
|
+
function normalizeDates(context, ...dates) {
|
|
95
|
+
const normalize = constructFrom.bind(
|
|
96
|
+
null,
|
|
97
|
+
dates.find((date) => typeof date === "object")
|
|
98
|
+
);
|
|
99
|
+
return dates.map(normalize);
|
|
100
|
+
}
|
|
101
|
+
function startOfDay(date, options) {
|
|
102
|
+
const _date = toDate(date, options?.in);
|
|
103
|
+
_date.setHours(0, 0, 0, 0);
|
|
104
|
+
return _date;
|
|
105
|
+
}
|
|
106
|
+
function differenceInCalendarDays(laterDate, earlierDate, options) {
|
|
107
|
+
const [laterDate_, earlierDate_] = normalizeDates(
|
|
108
|
+
options?.in,
|
|
109
|
+
laterDate,
|
|
110
|
+
earlierDate
|
|
111
|
+
);
|
|
112
|
+
const laterStartOfDay = startOfDay(laterDate_);
|
|
113
|
+
const earlierStartOfDay = startOfDay(earlierDate_);
|
|
114
|
+
const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
|
|
115
|
+
const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
|
|
116
|
+
return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
|
|
117
|
+
}
|
|
118
|
+
function startOfISOWeekYear(date, options) {
|
|
119
|
+
const year = getISOWeekYear(date, options);
|
|
120
|
+
const fourthOfJanuary = constructFrom(date, 0);
|
|
121
|
+
fourthOfJanuary.setFullYear(year, 0, 4);
|
|
122
|
+
fourthOfJanuary.setHours(0, 0, 0, 0);
|
|
123
|
+
return startOfISOWeek(fourthOfJanuary);
|
|
124
|
+
}
|
|
125
|
+
function addWeeks(date, amount, options) {
|
|
126
|
+
return addDays(date, amount * 7, options);
|
|
127
|
+
}
|
|
128
|
+
function addYears(date, amount, options) {
|
|
129
|
+
return addMonths(date, amount * 12, options);
|
|
130
|
+
}
|
|
131
|
+
function max(dates, options) {
|
|
132
|
+
let result;
|
|
133
|
+
let context = options?.in;
|
|
134
|
+
dates.forEach((date) => {
|
|
135
|
+
if (!context && typeof date === "object")
|
|
136
|
+
context = constructFrom.bind(null, date);
|
|
137
|
+
const date_ = toDate(date, context);
|
|
138
|
+
if (!result || result < date_ || isNaN(+date_)) result = date_;
|
|
139
|
+
});
|
|
140
|
+
return constructFrom(context, result || NaN);
|
|
141
|
+
}
|
|
142
|
+
function min(dates, options) {
|
|
143
|
+
let result;
|
|
144
|
+
let context = options?.in;
|
|
145
|
+
dates.forEach((date) => {
|
|
146
|
+
if (!context && typeof date === "object")
|
|
147
|
+
context = constructFrom.bind(null, date);
|
|
148
|
+
const date_ = toDate(date, context);
|
|
149
|
+
if (!result || result > date_ || isNaN(+date_)) result = date_;
|
|
150
|
+
});
|
|
151
|
+
return constructFrom(context, result || NaN);
|
|
152
|
+
}
|
|
153
|
+
function isSameDay(laterDate, earlierDate, options) {
|
|
154
|
+
const [dateLeft_, dateRight_] = normalizeDates(
|
|
155
|
+
options?.in,
|
|
156
|
+
laterDate,
|
|
157
|
+
earlierDate
|
|
158
|
+
);
|
|
159
|
+
return +startOfDay(dateLeft_) === +startOfDay(dateRight_);
|
|
160
|
+
}
|
|
161
|
+
function isDate(value) {
|
|
162
|
+
return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
|
|
163
|
+
}
|
|
164
|
+
function isValid(date) {
|
|
165
|
+
return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
|
|
166
|
+
}
|
|
167
|
+
function differenceInCalendarMonths(laterDate, earlierDate, options) {
|
|
168
|
+
const [laterDate_, earlierDate_] = normalizeDates(
|
|
169
|
+
options?.in,
|
|
170
|
+
laterDate,
|
|
171
|
+
earlierDate
|
|
172
|
+
);
|
|
173
|
+
const yearsDiff = laterDate_.getFullYear() - earlierDate_.getFullYear();
|
|
174
|
+
const monthsDiff = laterDate_.getMonth() - earlierDate_.getMonth();
|
|
175
|
+
return yearsDiff * 12 + monthsDiff;
|
|
176
|
+
}
|
|
177
|
+
function endOfMonth(date, options) {
|
|
178
|
+
const _date = toDate(date, options?.in);
|
|
179
|
+
const month = _date.getMonth();
|
|
180
|
+
_date.setFullYear(_date.getFullYear(), month + 1, 0);
|
|
181
|
+
_date.setHours(23, 59, 59, 999);
|
|
182
|
+
return _date;
|
|
183
|
+
}
|
|
184
|
+
function normalizeInterval(context, interval) {
|
|
185
|
+
const [start, end] = normalizeDates(context, interval.start, interval.end);
|
|
186
|
+
return { start, end };
|
|
187
|
+
}
|
|
188
|
+
function eachMonthOfInterval(interval, options) {
|
|
189
|
+
const { start, end } = normalizeInterval(options?.in, interval);
|
|
190
|
+
let reversed = +start > +end;
|
|
191
|
+
const endTime = reversed ? +start : +end;
|
|
192
|
+
const date = reversed ? end : start;
|
|
193
|
+
date.setHours(0, 0, 0, 0);
|
|
194
|
+
date.setDate(1);
|
|
195
|
+
let step = 1;
|
|
196
|
+
const dates = [];
|
|
197
|
+
while (+date <= endTime) {
|
|
198
|
+
dates.push(constructFrom(start, date));
|
|
199
|
+
date.setMonth(date.getMonth() + step);
|
|
200
|
+
}
|
|
201
|
+
return reversed ? dates.reverse() : dates;
|
|
202
|
+
}
|
|
203
|
+
function startOfMonth(date, options) {
|
|
204
|
+
const _date = toDate(date, options?.in);
|
|
205
|
+
_date.setDate(1);
|
|
206
|
+
_date.setHours(0, 0, 0, 0);
|
|
207
|
+
return _date;
|
|
208
|
+
}
|
|
209
|
+
function endOfYear(date, options) {
|
|
210
|
+
const _date = toDate(date, options?.in);
|
|
211
|
+
const year = _date.getFullYear();
|
|
212
|
+
_date.setFullYear(year + 1, 0, 0);
|
|
213
|
+
_date.setHours(23, 59, 59, 999);
|
|
214
|
+
return _date;
|
|
215
|
+
}
|
|
216
|
+
function startOfYear(date, options) {
|
|
217
|
+
const date_ = toDate(date, options?.in);
|
|
218
|
+
date_.setFullYear(date_.getFullYear(), 0, 1);
|
|
219
|
+
date_.setHours(0, 0, 0, 0);
|
|
220
|
+
return date_;
|
|
221
|
+
}
|
|
222
|
+
function eachYearOfInterval(interval, options) {
|
|
223
|
+
const { start, end } = normalizeInterval(options?.in, interval);
|
|
224
|
+
let reversed = +start > +end;
|
|
225
|
+
const endTime = reversed ? +start : +end;
|
|
226
|
+
const date = reversed ? end : start;
|
|
227
|
+
date.setHours(0, 0, 0, 0);
|
|
228
|
+
date.setMonth(0, 1);
|
|
229
|
+
let step = 1;
|
|
230
|
+
const dates = [];
|
|
231
|
+
while (+date <= endTime) {
|
|
232
|
+
dates.push(constructFrom(start, date));
|
|
233
|
+
date.setFullYear(date.getFullYear() + step);
|
|
234
|
+
}
|
|
235
|
+
return reversed ? dates.reverse() : dates;
|
|
236
|
+
}
|
|
237
|
+
function endOfWeek(date, options) {
|
|
238
|
+
const defaultOptions2 = getDefaultOptions();
|
|
239
|
+
const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
|
|
240
|
+
const _date = toDate(date, options?.in);
|
|
241
|
+
const day = _date.getDay();
|
|
242
|
+
const diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn);
|
|
243
|
+
_date.setDate(_date.getDate() + diff);
|
|
244
|
+
_date.setHours(23, 59, 59, 999);
|
|
245
|
+
return _date;
|
|
246
|
+
}
|
|
247
|
+
function endOfISOWeek(date, options) {
|
|
248
|
+
return endOfWeek(date, { ...options, weekStartsOn: 1 });
|
|
249
|
+
}
|
|
250
|
+
const formatDistanceLocale = {
|
|
251
|
+
lessThanXSeconds: {
|
|
252
|
+
one: "less than a second",
|
|
253
|
+
other: "less than {{count}} seconds"
|
|
254
|
+
},
|
|
255
|
+
xSeconds: {
|
|
256
|
+
one: "1 second",
|
|
257
|
+
other: "{{count}} seconds"
|
|
258
|
+
},
|
|
259
|
+
halfAMinute: "half a minute",
|
|
260
|
+
lessThanXMinutes: {
|
|
261
|
+
one: "less than a minute",
|
|
262
|
+
other: "less than {{count}} minutes"
|
|
263
|
+
},
|
|
264
|
+
xMinutes: {
|
|
265
|
+
one: "1 minute",
|
|
266
|
+
other: "{{count}} minutes"
|
|
267
|
+
},
|
|
268
|
+
aboutXHours: {
|
|
269
|
+
one: "about 1 hour",
|
|
270
|
+
other: "about {{count}} hours"
|
|
271
|
+
},
|
|
272
|
+
xHours: {
|
|
273
|
+
one: "1 hour",
|
|
274
|
+
other: "{{count}} hours"
|
|
275
|
+
},
|
|
276
|
+
xDays: {
|
|
277
|
+
one: "1 day",
|
|
278
|
+
other: "{{count}} days"
|
|
279
|
+
},
|
|
280
|
+
aboutXWeeks: {
|
|
281
|
+
one: "about 1 week",
|
|
282
|
+
other: "about {{count}} weeks"
|
|
283
|
+
},
|
|
284
|
+
xWeeks: {
|
|
285
|
+
one: "1 week",
|
|
286
|
+
other: "{{count}} weeks"
|
|
287
|
+
},
|
|
288
|
+
aboutXMonths: {
|
|
289
|
+
one: "about 1 month",
|
|
290
|
+
other: "about {{count}} months"
|
|
291
|
+
},
|
|
292
|
+
xMonths: {
|
|
293
|
+
one: "1 month",
|
|
294
|
+
other: "{{count}} months"
|
|
295
|
+
},
|
|
296
|
+
aboutXYears: {
|
|
297
|
+
one: "about 1 year",
|
|
298
|
+
other: "about {{count}} years"
|
|
299
|
+
},
|
|
300
|
+
xYears: {
|
|
301
|
+
one: "1 year",
|
|
302
|
+
other: "{{count}} years"
|
|
303
|
+
},
|
|
304
|
+
overXYears: {
|
|
305
|
+
one: "over 1 year",
|
|
306
|
+
other: "over {{count}} years"
|
|
307
|
+
},
|
|
308
|
+
almostXYears: {
|
|
309
|
+
one: "almost 1 year",
|
|
310
|
+
other: "almost {{count}} years"
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const formatDistance = (token, count, options) => {
|
|
314
|
+
let result;
|
|
315
|
+
const tokenValue = formatDistanceLocale[token];
|
|
316
|
+
if (typeof tokenValue === "string") {
|
|
317
|
+
result = tokenValue;
|
|
318
|
+
} else if (count === 1) {
|
|
319
|
+
result = tokenValue.one;
|
|
320
|
+
} else {
|
|
321
|
+
result = tokenValue.other.replace("{{count}}", count.toString());
|
|
322
|
+
}
|
|
323
|
+
if (options?.addSuffix) {
|
|
324
|
+
if (options.comparison && options.comparison > 0) {
|
|
325
|
+
return "in " + result;
|
|
326
|
+
} else {
|
|
327
|
+
return result + " ago";
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
};
|
|
332
|
+
function buildFormatLongFn(args) {
|
|
333
|
+
return (options = {}) => {
|
|
334
|
+
const width = options.width ? String(options.width) : args.defaultWidth;
|
|
335
|
+
const format2 = args.formats[width] || args.formats[args.defaultWidth];
|
|
336
|
+
return format2;
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
const dateFormats = {
|
|
340
|
+
full: "EEEE, MMMM do, y",
|
|
341
|
+
long: "MMMM do, y",
|
|
342
|
+
medium: "MMM d, y",
|
|
343
|
+
short: "MM/dd/yyyy"
|
|
344
|
+
};
|
|
345
|
+
const timeFormats = {
|
|
346
|
+
full: "h:mm:ss a zzzz",
|
|
347
|
+
long: "h:mm:ss a z",
|
|
348
|
+
medium: "h:mm:ss a",
|
|
349
|
+
short: "h:mm a"
|
|
350
|
+
};
|
|
351
|
+
const dateTimeFormats = {
|
|
352
|
+
full: "{{date}} 'at' {{time}}",
|
|
353
|
+
long: "{{date}} 'at' {{time}}",
|
|
354
|
+
medium: "{{date}}, {{time}}",
|
|
355
|
+
short: "{{date}}, {{time}}"
|
|
356
|
+
};
|
|
357
|
+
const formatLong = {
|
|
358
|
+
date: buildFormatLongFn({
|
|
359
|
+
formats: dateFormats,
|
|
360
|
+
defaultWidth: "full"
|
|
361
|
+
}),
|
|
362
|
+
time: buildFormatLongFn({
|
|
363
|
+
formats: timeFormats,
|
|
364
|
+
defaultWidth: "full"
|
|
365
|
+
}),
|
|
366
|
+
dateTime: buildFormatLongFn({
|
|
367
|
+
formats: dateTimeFormats,
|
|
368
|
+
defaultWidth: "full"
|
|
369
|
+
})
|
|
370
|
+
};
|
|
371
|
+
const formatRelativeLocale = {
|
|
372
|
+
lastWeek: "'last' eeee 'at' p",
|
|
373
|
+
yesterday: "'yesterday at' p",
|
|
374
|
+
today: "'today at' p",
|
|
375
|
+
tomorrow: "'tomorrow at' p",
|
|
376
|
+
nextWeek: "eeee 'at' p",
|
|
377
|
+
other: "P"
|
|
378
|
+
};
|
|
379
|
+
const formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
|
|
380
|
+
function buildLocalizeFn(args) {
|
|
381
|
+
return (value, options) => {
|
|
382
|
+
const context = options?.context ? String(options.context) : "standalone";
|
|
383
|
+
let valuesArray;
|
|
384
|
+
if (context === "formatting" && args.formattingValues) {
|
|
385
|
+
const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
|
|
386
|
+
const width = options?.width ? String(options.width) : defaultWidth;
|
|
387
|
+
valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
|
|
388
|
+
} else {
|
|
389
|
+
const defaultWidth = args.defaultWidth;
|
|
390
|
+
const width = options?.width ? String(options.width) : args.defaultWidth;
|
|
391
|
+
valuesArray = args.values[width] || args.values[defaultWidth];
|
|
392
|
+
}
|
|
393
|
+
const index = args.argumentCallback ? args.argumentCallback(value) : value;
|
|
394
|
+
return valuesArray[index];
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const eraValues = {
|
|
398
|
+
narrow: ["B", "A"],
|
|
399
|
+
abbreviated: ["BC", "AD"],
|
|
400
|
+
wide: ["Before Christ", "Anno Domini"]
|
|
401
|
+
};
|
|
402
|
+
const quarterValues = {
|
|
403
|
+
narrow: ["1", "2", "3", "4"],
|
|
404
|
+
abbreviated: ["Q1", "Q2", "Q3", "Q4"],
|
|
405
|
+
wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
|
|
406
|
+
};
|
|
407
|
+
const monthValues = {
|
|
408
|
+
narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
|
|
409
|
+
abbreviated: [
|
|
410
|
+
"Jan",
|
|
411
|
+
"Feb",
|
|
412
|
+
"Mar",
|
|
413
|
+
"Apr",
|
|
414
|
+
"May",
|
|
415
|
+
"Jun",
|
|
416
|
+
"Jul",
|
|
417
|
+
"Aug",
|
|
418
|
+
"Sep",
|
|
419
|
+
"Oct",
|
|
420
|
+
"Nov",
|
|
421
|
+
"Dec"
|
|
422
|
+
],
|
|
423
|
+
wide: [
|
|
424
|
+
"January",
|
|
425
|
+
"February",
|
|
426
|
+
"March",
|
|
427
|
+
"April",
|
|
428
|
+
"May",
|
|
429
|
+
"June",
|
|
430
|
+
"July",
|
|
431
|
+
"August",
|
|
432
|
+
"September",
|
|
433
|
+
"October",
|
|
434
|
+
"November",
|
|
435
|
+
"December"
|
|
436
|
+
]
|
|
437
|
+
};
|
|
438
|
+
const dayValues = {
|
|
439
|
+
narrow: ["S", "M", "T", "W", "T", "F", "S"],
|
|
440
|
+
short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
|
|
441
|
+
abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
442
|
+
wide: [
|
|
443
|
+
"Sunday",
|
|
444
|
+
"Monday",
|
|
445
|
+
"Tuesday",
|
|
446
|
+
"Wednesday",
|
|
447
|
+
"Thursday",
|
|
448
|
+
"Friday",
|
|
449
|
+
"Saturday"
|
|
450
|
+
]
|
|
451
|
+
};
|
|
452
|
+
const dayPeriodValues = {
|
|
453
|
+
narrow: {
|
|
454
|
+
am: "a",
|
|
455
|
+
pm: "p",
|
|
456
|
+
midnight: "mi",
|
|
457
|
+
noon: "n",
|
|
458
|
+
morning: "morning",
|
|
459
|
+
afternoon: "afternoon",
|
|
460
|
+
evening: "evening",
|
|
461
|
+
night: "night"
|
|
462
|
+
},
|
|
463
|
+
abbreviated: {
|
|
464
|
+
am: "AM",
|
|
465
|
+
pm: "PM",
|
|
466
|
+
midnight: "midnight",
|
|
467
|
+
noon: "noon",
|
|
468
|
+
morning: "morning",
|
|
469
|
+
afternoon: "afternoon",
|
|
470
|
+
evening: "evening",
|
|
471
|
+
night: "night"
|
|
472
|
+
},
|
|
473
|
+
wide: {
|
|
474
|
+
am: "a.m.",
|
|
475
|
+
pm: "p.m.",
|
|
476
|
+
midnight: "midnight",
|
|
477
|
+
noon: "noon",
|
|
478
|
+
morning: "morning",
|
|
479
|
+
afternoon: "afternoon",
|
|
480
|
+
evening: "evening",
|
|
481
|
+
night: "night"
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
const formattingDayPeriodValues = {
|
|
485
|
+
narrow: {
|
|
486
|
+
am: "a",
|
|
487
|
+
pm: "p",
|
|
488
|
+
midnight: "mi",
|
|
489
|
+
noon: "n",
|
|
490
|
+
morning: "in the morning",
|
|
491
|
+
afternoon: "in the afternoon",
|
|
492
|
+
evening: "in the evening",
|
|
493
|
+
night: "at night"
|
|
494
|
+
},
|
|
495
|
+
abbreviated: {
|
|
496
|
+
am: "AM",
|
|
497
|
+
pm: "PM",
|
|
498
|
+
midnight: "midnight",
|
|
499
|
+
noon: "noon",
|
|
500
|
+
morning: "in the morning",
|
|
501
|
+
afternoon: "in the afternoon",
|
|
502
|
+
evening: "in the evening",
|
|
503
|
+
night: "at night"
|
|
504
|
+
},
|
|
505
|
+
wide: {
|
|
506
|
+
am: "a.m.",
|
|
507
|
+
pm: "p.m.",
|
|
508
|
+
midnight: "midnight",
|
|
509
|
+
noon: "noon",
|
|
510
|
+
morning: "in the morning",
|
|
511
|
+
afternoon: "in the afternoon",
|
|
512
|
+
evening: "in the evening",
|
|
513
|
+
night: "at night"
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
const ordinalNumber = (dirtyNumber, _options) => {
|
|
517
|
+
const number = Number(dirtyNumber);
|
|
518
|
+
const rem100 = number % 100;
|
|
519
|
+
if (rem100 > 20 || rem100 < 10) {
|
|
520
|
+
switch (rem100 % 10) {
|
|
521
|
+
case 1:
|
|
522
|
+
return number + "st";
|
|
523
|
+
case 2:
|
|
524
|
+
return number + "nd";
|
|
525
|
+
case 3:
|
|
526
|
+
return number + "rd";
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return number + "th";
|
|
530
|
+
};
|
|
531
|
+
const localize = {
|
|
532
|
+
ordinalNumber,
|
|
533
|
+
era: buildLocalizeFn({
|
|
534
|
+
values: eraValues,
|
|
535
|
+
defaultWidth: "wide"
|
|
536
|
+
}),
|
|
537
|
+
quarter: buildLocalizeFn({
|
|
538
|
+
values: quarterValues,
|
|
539
|
+
defaultWidth: "wide",
|
|
540
|
+
argumentCallback: (quarter) => quarter - 1
|
|
541
|
+
}),
|
|
542
|
+
month: buildLocalizeFn({
|
|
543
|
+
values: monthValues,
|
|
544
|
+
defaultWidth: "wide"
|
|
545
|
+
}),
|
|
546
|
+
day: buildLocalizeFn({
|
|
547
|
+
values: dayValues,
|
|
548
|
+
defaultWidth: "wide"
|
|
549
|
+
}),
|
|
550
|
+
dayPeriod: buildLocalizeFn({
|
|
551
|
+
values: dayPeriodValues,
|
|
552
|
+
defaultWidth: "wide",
|
|
553
|
+
formattingValues: formattingDayPeriodValues,
|
|
554
|
+
defaultFormattingWidth: "wide"
|
|
555
|
+
})
|
|
556
|
+
};
|
|
557
|
+
function buildMatchFn(args) {
|
|
558
|
+
return (string, options = {}) => {
|
|
559
|
+
const width = options.width;
|
|
560
|
+
const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
|
|
561
|
+
const matchResult = string.match(matchPattern);
|
|
562
|
+
if (!matchResult) {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
const matchedString = matchResult[0];
|
|
566
|
+
const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
|
|
567
|
+
const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
|
|
568
|
+
// [TODO] -- I challenge you to fix the type
|
|
569
|
+
findKey(parsePatterns, (pattern) => pattern.test(matchedString))
|
|
570
|
+
);
|
|
571
|
+
let value;
|
|
572
|
+
value = args.valueCallback ? args.valueCallback(key) : key;
|
|
573
|
+
value = options.valueCallback ? (
|
|
574
|
+
// [TODO] -- I challenge you to fix the type
|
|
575
|
+
options.valueCallback(value)
|
|
576
|
+
) : value;
|
|
577
|
+
const rest = string.slice(matchedString.length);
|
|
578
|
+
return { value, rest };
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function findKey(object, predicate) {
|
|
582
|
+
for (const key in object) {
|
|
583
|
+
if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
|
|
584
|
+
return key;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return void 0;
|
|
588
|
+
}
|
|
589
|
+
function findIndex(array, predicate) {
|
|
590
|
+
for (let key = 0; key < array.length; key++) {
|
|
591
|
+
if (predicate(array[key])) {
|
|
592
|
+
return key;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return void 0;
|
|
596
|
+
}
|
|
597
|
+
function buildMatchPatternFn(args) {
|
|
598
|
+
return (string, options = {}) => {
|
|
599
|
+
const matchResult = string.match(args.matchPattern);
|
|
600
|
+
if (!matchResult) return null;
|
|
601
|
+
const matchedString = matchResult[0];
|
|
602
|
+
const parseResult = string.match(args.parsePattern);
|
|
603
|
+
if (!parseResult) return null;
|
|
604
|
+
let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
|
|
605
|
+
value = options.valueCallback ? options.valueCallback(value) : value;
|
|
606
|
+
const rest = string.slice(matchedString.length);
|
|
607
|
+
return { value, rest };
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
|
|
611
|
+
const parseOrdinalNumberPattern = /\d+/i;
|
|
612
|
+
const matchEraPatterns = {
|
|
613
|
+
narrow: /^(b|a)/i,
|
|
614
|
+
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
|
|
615
|
+
wide: /^(before christ|before common era|anno domini|common era)/i
|
|
616
|
+
};
|
|
617
|
+
const parseEraPatterns = {
|
|
618
|
+
any: [/^b/i, /^(a|c)/i]
|
|
619
|
+
};
|
|
620
|
+
const matchQuarterPatterns = {
|
|
621
|
+
narrow: /^[1234]/i,
|
|
622
|
+
abbreviated: /^q[1234]/i,
|
|
623
|
+
wide: /^[1234](th|st|nd|rd)? quarter/i
|
|
624
|
+
};
|
|
625
|
+
const parseQuarterPatterns = {
|
|
626
|
+
any: [/1/i, /2/i, /3/i, /4/i]
|
|
627
|
+
};
|
|
628
|
+
const matchMonthPatterns = {
|
|
629
|
+
narrow: /^[jfmasond]/i,
|
|
630
|
+
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
|
|
631
|
+
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
|
|
632
|
+
};
|
|
633
|
+
const parseMonthPatterns = {
|
|
634
|
+
narrow: [
|
|
635
|
+
/^j/i,
|
|
636
|
+
/^f/i,
|
|
637
|
+
/^m/i,
|
|
638
|
+
/^a/i,
|
|
639
|
+
/^m/i,
|
|
640
|
+
/^j/i,
|
|
641
|
+
/^j/i,
|
|
642
|
+
/^a/i,
|
|
643
|
+
/^s/i,
|
|
644
|
+
/^o/i,
|
|
645
|
+
/^n/i,
|
|
646
|
+
/^d/i
|
|
647
|
+
],
|
|
648
|
+
any: [
|
|
649
|
+
/^ja/i,
|
|
650
|
+
/^f/i,
|
|
651
|
+
/^mar/i,
|
|
652
|
+
/^ap/i,
|
|
653
|
+
/^may/i,
|
|
654
|
+
/^jun/i,
|
|
655
|
+
/^jul/i,
|
|
656
|
+
/^au/i,
|
|
657
|
+
/^s/i,
|
|
658
|
+
/^o/i,
|
|
659
|
+
/^n/i,
|
|
660
|
+
/^d/i
|
|
661
|
+
]
|
|
662
|
+
};
|
|
663
|
+
const matchDayPatterns = {
|
|
664
|
+
narrow: /^[smtwf]/i,
|
|
665
|
+
short: /^(su|mo|tu|we|th|fr|sa)/i,
|
|
666
|
+
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
|
|
667
|
+
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
|
|
668
|
+
};
|
|
669
|
+
const parseDayPatterns = {
|
|
670
|
+
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
|
|
671
|
+
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
|
|
672
|
+
};
|
|
673
|
+
const matchDayPeriodPatterns = {
|
|
674
|
+
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
|
|
675
|
+
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
|
|
676
|
+
};
|
|
677
|
+
const parseDayPeriodPatterns = {
|
|
678
|
+
any: {
|
|
679
|
+
am: /^a/i,
|
|
680
|
+
pm: /^p/i,
|
|
681
|
+
midnight: /^mi/i,
|
|
682
|
+
noon: /^no/i,
|
|
683
|
+
morning: /morning/i,
|
|
684
|
+
afternoon: /afternoon/i,
|
|
685
|
+
evening: /evening/i,
|
|
686
|
+
night: /night/i
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
const match = {
|
|
690
|
+
ordinalNumber: buildMatchPatternFn({
|
|
691
|
+
matchPattern: matchOrdinalNumberPattern,
|
|
692
|
+
parsePattern: parseOrdinalNumberPattern,
|
|
693
|
+
valueCallback: (value) => parseInt(value, 10)
|
|
694
|
+
}),
|
|
695
|
+
era: buildMatchFn({
|
|
696
|
+
matchPatterns: matchEraPatterns,
|
|
697
|
+
defaultMatchWidth: "wide",
|
|
698
|
+
parsePatterns: parseEraPatterns,
|
|
699
|
+
defaultParseWidth: "any"
|
|
700
|
+
}),
|
|
701
|
+
quarter: buildMatchFn({
|
|
702
|
+
matchPatterns: matchQuarterPatterns,
|
|
703
|
+
defaultMatchWidth: "wide",
|
|
704
|
+
parsePatterns: parseQuarterPatterns,
|
|
705
|
+
defaultParseWidth: "any",
|
|
706
|
+
valueCallback: (index) => index + 1
|
|
707
|
+
}),
|
|
708
|
+
month: buildMatchFn({
|
|
709
|
+
matchPatterns: matchMonthPatterns,
|
|
710
|
+
defaultMatchWidth: "wide",
|
|
711
|
+
parsePatterns: parseMonthPatterns,
|
|
712
|
+
defaultParseWidth: "any"
|
|
713
|
+
}),
|
|
714
|
+
day: buildMatchFn({
|
|
715
|
+
matchPatterns: matchDayPatterns,
|
|
716
|
+
defaultMatchWidth: "wide",
|
|
717
|
+
parsePatterns: parseDayPatterns,
|
|
718
|
+
defaultParseWidth: "any"
|
|
719
|
+
}),
|
|
720
|
+
dayPeriod: buildMatchFn({
|
|
721
|
+
matchPatterns: matchDayPeriodPatterns,
|
|
722
|
+
defaultMatchWidth: "any",
|
|
723
|
+
parsePatterns: parseDayPeriodPatterns,
|
|
724
|
+
defaultParseWidth: "any"
|
|
725
|
+
})
|
|
726
|
+
};
|
|
727
|
+
const enUS = {
|
|
728
|
+
code: "en-US",
|
|
729
|
+
formatDistance,
|
|
730
|
+
formatLong,
|
|
731
|
+
formatRelative,
|
|
732
|
+
localize,
|
|
733
|
+
match,
|
|
734
|
+
options: {
|
|
735
|
+
weekStartsOn: 0,
|
|
736
|
+
firstWeekContainsDate: 1
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
function getDayOfYear(date, options) {
|
|
740
|
+
const _date = toDate(date, options?.in);
|
|
741
|
+
const diff = differenceInCalendarDays(_date, startOfYear(_date));
|
|
742
|
+
const dayOfYear = diff + 1;
|
|
743
|
+
return dayOfYear;
|
|
744
|
+
}
|
|
745
|
+
function getISOWeek(date, options) {
|
|
746
|
+
const _date = toDate(date, options?.in);
|
|
747
|
+
const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
|
|
748
|
+
return Math.round(diff / millisecondsInWeek) + 1;
|
|
749
|
+
}
|
|
750
|
+
function getWeekYear(date, options) {
|
|
751
|
+
const _date = toDate(date, options?.in);
|
|
752
|
+
const year = _date.getFullYear();
|
|
753
|
+
const defaultOptions2 = getDefaultOptions();
|
|
754
|
+
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
|
|
755
|
+
const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
|
|
756
|
+
firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
|
|
757
|
+
firstWeekOfNextYear.setHours(0, 0, 0, 0);
|
|
758
|
+
const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
|
|
759
|
+
const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
|
|
760
|
+
firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
|
|
761
|
+
firstWeekOfThisYear.setHours(0, 0, 0, 0);
|
|
762
|
+
const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
|
|
763
|
+
if (+_date >= +startOfNextYear) {
|
|
764
|
+
return year + 1;
|
|
765
|
+
} else if (+_date >= +startOfThisYear) {
|
|
766
|
+
return year;
|
|
767
|
+
} else {
|
|
768
|
+
return year - 1;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function startOfWeekYear(date, options) {
|
|
772
|
+
const defaultOptions2 = getDefaultOptions();
|
|
773
|
+
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
|
|
774
|
+
const year = getWeekYear(date, options);
|
|
775
|
+
const firstWeek = constructFrom(options?.in || date, 0);
|
|
776
|
+
firstWeek.setFullYear(year, 0, firstWeekContainsDate);
|
|
777
|
+
firstWeek.setHours(0, 0, 0, 0);
|
|
778
|
+
const _date = startOfWeek(firstWeek, options);
|
|
779
|
+
return _date;
|
|
780
|
+
}
|
|
781
|
+
function getWeek(date, options) {
|
|
782
|
+
const _date = toDate(date, options?.in);
|
|
783
|
+
const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
|
|
784
|
+
return Math.round(diff / millisecondsInWeek) + 1;
|
|
785
|
+
}
|
|
786
|
+
function addLeadingZeros(number, targetLength) {
|
|
787
|
+
const sign = number < 0 ? "-" : "";
|
|
788
|
+
const output = Math.abs(number).toString().padStart(targetLength, "0");
|
|
789
|
+
return sign + output;
|
|
790
|
+
}
|
|
791
|
+
const lightFormatters = {
|
|
792
|
+
// Year
|
|
793
|
+
y(date, token) {
|
|
794
|
+
const signedYear = date.getFullYear();
|
|
795
|
+
const year = signedYear > 0 ? signedYear : 1 - signedYear;
|
|
796
|
+
return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
|
|
797
|
+
},
|
|
798
|
+
// Month
|
|
799
|
+
M(date, token) {
|
|
800
|
+
const month = date.getMonth();
|
|
801
|
+
return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
|
|
802
|
+
},
|
|
803
|
+
// Day of the month
|
|
804
|
+
d(date, token) {
|
|
805
|
+
return addLeadingZeros(date.getDate(), token.length);
|
|
806
|
+
},
|
|
807
|
+
// AM or PM
|
|
808
|
+
a(date, token) {
|
|
809
|
+
const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
|
|
810
|
+
switch (token) {
|
|
811
|
+
case "a":
|
|
812
|
+
case "aa":
|
|
813
|
+
return dayPeriodEnumValue.toUpperCase();
|
|
814
|
+
case "aaa":
|
|
815
|
+
return dayPeriodEnumValue;
|
|
816
|
+
case "aaaaa":
|
|
817
|
+
return dayPeriodEnumValue[0];
|
|
818
|
+
case "aaaa":
|
|
819
|
+
default:
|
|
820
|
+
return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
// Hour [1-12]
|
|
824
|
+
h(date, token) {
|
|
825
|
+
return addLeadingZeros(date.getHours() % 12 || 12, token.length);
|
|
826
|
+
},
|
|
827
|
+
// Hour [0-23]
|
|
828
|
+
H(date, token) {
|
|
829
|
+
return addLeadingZeros(date.getHours(), token.length);
|
|
830
|
+
},
|
|
831
|
+
// Minute
|
|
832
|
+
m(date, token) {
|
|
833
|
+
return addLeadingZeros(date.getMinutes(), token.length);
|
|
834
|
+
},
|
|
835
|
+
// Second
|
|
836
|
+
s(date, token) {
|
|
837
|
+
return addLeadingZeros(date.getSeconds(), token.length);
|
|
838
|
+
},
|
|
839
|
+
// Fraction of second
|
|
840
|
+
S(date, token) {
|
|
841
|
+
const numberOfDigits = token.length;
|
|
842
|
+
const milliseconds = date.getMilliseconds();
|
|
843
|
+
const fractionalSeconds = Math.trunc(
|
|
844
|
+
milliseconds * Math.pow(10, numberOfDigits - 3)
|
|
845
|
+
);
|
|
846
|
+
return addLeadingZeros(fractionalSeconds, token.length);
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
const dayPeriodEnum = {
|
|
850
|
+
midnight: "midnight",
|
|
851
|
+
noon: "noon",
|
|
852
|
+
morning: "morning",
|
|
853
|
+
afternoon: "afternoon",
|
|
854
|
+
evening: "evening",
|
|
855
|
+
night: "night"
|
|
856
|
+
};
|
|
857
|
+
const formatters = {
|
|
858
|
+
// Era
|
|
859
|
+
G: function(date, token, localize2) {
|
|
860
|
+
const era = date.getFullYear() > 0 ? 1 : 0;
|
|
861
|
+
switch (token) {
|
|
862
|
+
// AD, BC
|
|
863
|
+
case "G":
|
|
864
|
+
case "GG":
|
|
865
|
+
case "GGG":
|
|
866
|
+
return localize2.era(era, { width: "abbreviated" });
|
|
867
|
+
// A, B
|
|
868
|
+
case "GGGGG":
|
|
869
|
+
return localize2.era(era, { width: "narrow" });
|
|
870
|
+
// Anno Domini, Before Christ
|
|
871
|
+
case "GGGG":
|
|
872
|
+
default:
|
|
873
|
+
return localize2.era(era, { width: "wide" });
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
// Year
|
|
877
|
+
y: function(date, token, localize2) {
|
|
878
|
+
if (token === "yo") {
|
|
879
|
+
const signedYear = date.getFullYear();
|
|
880
|
+
const year = signedYear > 0 ? signedYear : 1 - signedYear;
|
|
881
|
+
return localize2.ordinalNumber(year, { unit: "year" });
|
|
882
|
+
}
|
|
883
|
+
return lightFormatters.y(date, token);
|
|
884
|
+
},
|
|
885
|
+
// Local week-numbering year
|
|
886
|
+
Y: function(date, token, localize2, options) {
|
|
887
|
+
const signedWeekYear = getWeekYear(date, options);
|
|
888
|
+
const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
|
|
889
|
+
if (token === "YY") {
|
|
890
|
+
const twoDigitYear = weekYear % 100;
|
|
891
|
+
return addLeadingZeros(twoDigitYear, 2);
|
|
892
|
+
}
|
|
893
|
+
if (token === "Yo") {
|
|
894
|
+
return localize2.ordinalNumber(weekYear, { unit: "year" });
|
|
895
|
+
}
|
|
896
|
+
return addLeadingZeros(weekYear, token.length);
|
|
897
|
+
},
|
|
898
|
+
// ISO week-numbering year
|
|
899
|
+
R: function(date, token) {
|
|
900
|
+
const isoWeekYear = getISOWeekYear(date);
|
|
901
|
+
return addLeadingZeros(isoWeekYear, token.length);
|
|
902
|
+
},
|
|
903
|
+
// Extended year. This is a single number designating the year of this calendar system.
|
|
904
|
+
// The main difference between `y` and `u` localizers are B.C. years:
|
|
905
|
+
// | Year | `y` | `u` |
|
|
906
|
+
// |------|-----|-----|
|
|
907
|
+
// | AC 1 | 1 | 1 |
|
|
908
|
+
// | BC 1 | 1 | 0 |
|
|
909
|
+
// | BC 2 | 2 | -1 |
|
|
910
|
+
// Also `yy` always returns the last two digits of a year,
|
|
911
|
+
// while `uu` pads single digit years to 2 characters and returns other years unchanged.
|
|
912
|
+
u: function(date, token) {
|
|
913
|
+
const year = date.getFullYear();
|
|
914
|
+
return addLeadingZeros(year, token.length);
|
|
915
|
+
},
|
|
916
|
+
// Quarter
|
|
917
|
+
Q: function(date, token, localize2) {
|
|
918
|
+
const quarter = Math.ceil((date.getMonth() + 1) / 3);
|
|
919
|
+
switch (token) {
|
|
920
|
+
// 1, 2, 3, 4
|
|
921
|
+
case "Q":
|
|
922
|
+
return String(quarter);
|
|
923
|
+
// 01, 02, 03, 04
|
|
924
|
+
case "QQ":
|
|
925
|
+
return addLeadingZeros(quarter, 2);
|
|
926
|
+
// 1st, 2nd, 3rd, 4th
|
|
927
|
+
case "Qo":
|
|
928
|
+
return localize2.ordinalNumber(quarter, { unit: "quarter" });
|
|
929
|
+
// Q1, Q2, Q3, Q4
|
|
930
|
+
case "QQQ":
|
|
931
|
+
return localize2.quarter(quarter, {
|
|
932
|
+
width: "abbreviated",
|
|
933
|
+
context: "formatting"
|
|
934
|
+
});
|
|
935
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
936
|
+
case "QQQQQ":
|
|
937
|
+
return localize2.quarter(quarter, {
|
|
938
|
+
width: "narrow",
|
|
939
|
+
context: "formatting"
|
|
940
|
+
});
|
|
941
|
+
// 1st quarter, 2nd quarter, ...
|
|
942
|
+
case "QQQQ":
|
|
943
|
+
default:
|
|
944
|
+
return localize2.quarter(quarter, {
|
|
945
|
+
width: "wide",
|
|
946
|
+
context: "formatting"
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
},
|
|
950
|
+
// Stand-alone quarter
|
|
951
|
+
q: function(date, token, localize2) {
|
|
952
|
+
const quarter = Math.ceil((date.getMonth() + 1) / 3);
|
|
953
|
+
switch (token) {
|
|
954
|
+
// 1, 2, 3, 4
|
|
955
|
+
case "q":
|
|
956
|
+
return String(quarter);
|
|
957
|
+
// 01, 02, 03, 04
|
|
958
|
+
case "qq":
|
|
959
|
+
return addLeadingZeros(quarter, 2);
|
|
960
|
+
// 1st, 2nd, 3rd, 4th
|
|
961
|
+
case "qo":
|
|
962
|
+
return localize2.ordinalNumber(quarter, { unit: "quarter" });
|
|
963
|
+
// Q1, Q2, Q3, Q4
|
|
964
|
+
case "qqq":
|
|
965
|
+
return localize2.quarter(quarter, {
|
|
966
|
+
width: "abbreviated",
|
|
967
|
+
context: "standalone"
|
|
968
|
+
});
|
|
969
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
970
|
+
case "qqqqq":
|
|
971
|
+
return localize2.quarter(quarter, {
|
|
972
|
+
width: "narrow",
|
|
973
|
+
context: "standalone"
|
|
974
|
+
});
|
|
975
|
+
// 1st quarter, 2nd quarter, ...
|
|
976
|
+
case "qqqq":
|
|
977
|
+
default:
|
|
978
|
+
return localize2.quarter(quarter, {
|
|
979
|
+
width: "wide",
|
|
980
|
+
context: "standalone"
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
// Month
|
|
985
|
+
M: function(date, token, localize2) {
|
|
986
|
+
const month = date.getMonth();
|
|
987
|
+
switch (token) {
|
|
988
|
+
case "M":
|
|
989
|
+
case "MM":
|
|
990
|
+
return lightFormatters.M(date, token);
|
|
991
|
+
// 1st, 2nd, ..., 12th
|
|
992
|
+
case "Mo":
|
|
993
|
+
return localize2.ordinalNumber(month + 1, { unit: "month" });
|
|
994
|
+
// Jan, Feb, ..., Dec
|
|
995
|
+
case "MMM":
|
|
996
|
+
return localize2.month(month, {
|
|
997
|
+
width: "abbreviated",
|
|
998
|
+
context: "formatting"
|
|
999
|
+
});
|
|
1000
|
+
// J, F, ..., D
|
|
1001
|
+
case "MMMMM":
|
|
1002
|
+
return localize2.month(month, {
|
|
1003
|
+
width: "narrow",
|
|
1004
|
+
context: "formatting"
|
|
1005
|
+
});
|
|
1006
|
+
// January, February, ..., December
|
|
1007
|
+
case "MMMM":
|
|
1008
|
+
default:
|
|
1009
|
+
return localize2.month(month, { width: "wide", context: "formatting" });
|
|
1010
|
+
}
|
|
1011
|
+
},
|
|
1012
|
+
// Stand-alone month
|
|
1013
|
+
L: function(date, token, localize2) {
|
|
1014
|
+
const month = date.getMonth();
|
|
1015
|
+
switch (token) {
|
|
1016
|
+
// 1, 2, ..., 12
|
|
1017
|
+
case "L":
|
|
1018
|
+
return String(month + 1);
|
|
1019
|
+
// 01, 02, ..., 12
|
|
1020
|
+
case "LL":
|
|
1021
|
+
return addLeadingZeros(month + 1, 2);
|
|
1022
|
+
// 1st, 2nd, ..., 12th
|
|
1023
|
+
case "Lo":
|
|
1024
|
+
return localize2.ordinalNumber(month + 1, { unit: "month" });
|
|
1025
|
+
// Jan, Feb, ..., Dec
|
|
1026
|
+
case "LLL":
|
|
1027
|
+
return localize2.month(month, {
|
|
1028
|
+
width: "abbreviated",
|
|
1029
|
+
context: "standalone"
|
|
1030
|
+
});
|
|
1031
|
+
// J, F, ..., D
|
|
1032
|
+
case "LLLLL":
|
|
1033
|
+
return localize2.month(month, {
|
|
1034
|
+
width: "narrow",
|
|
1035
|
+
context: "standalone"
|
|
1036
|
+
});
|
|
1037
|
+
// January, February, ..., December
|
|
1038
|
+
case "LLLL":
|
|
1039
|
+
default:
|
|
1040
|
+
return localize2.month(month, { width: "wide", context: "standalone" });
|
|
1041
|
+
}
|
|
1042
|
+
},
|
|
1043
|
+
// Local week of year
|
|
1044
|
+
w: function(date, token, localize2, options) {
|
|
1045
|
+
const week = getWeek(date, options);
|
|
1046
|
+
if (token === "wo") {
|
|
1047
|
+
return localize2.ordinalNumber(week, { unit: "week" });
|
|
1048
|
+
}
|
|
1049
|
+
return addLeadingZeros(week, token.length);
|
|
1050
|
+
},
|
|
1051
|
+
// ISO week of year
|
|
1052
|
+
I: function(date, token, localize2) {
|
|
1053
|
+
const isoWeek = getISOWeek(date);
|
|
1054
|
+
if (token === "Io") {
|
|
1055
|
+
return localize2.ordinalNumber(isoWeek, { unit: "week" });
|
|
1056
|
+
}
|
|
1057
|
+
return addLeadingZeros(isoWeek, token.length);
|
|
1058
|
+
},
|
|
1059
|
+
// Day of the month
|
|
1060
|
+
d: function(date, token, localize2) {
|
|
1061
|
+
if (token === "do") {
|
|
1062
|
+
return localize2.ordinalNumber(date.getDate(), { unit: "date" });
|
|
1063
|
+
}
|
|
1064
|
+
return lightFormatters.d(date, token);
|
|
1065
|
+
},
|
|
1066
|
+
// Day of year
|
|
1067
|
+
D: function(date, token, localize2) {
|
|
1068
|
+
const dayOfYear = getDayOfYear(date);
|
|
1069
|
+
if (token === "Do") {
|
|
1070
|
+
return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
|
|
1071
|
+
}
|
|
1072
|
+
return addLeadingZeros(dayOfYear, token.length);
|
|
1073
|
+
},
|
|
1074
|
+
// Day of week
|
|
1075
|
+
E: function(date, token, localize2) {
|
|
1076
|
+
const dayOfWeek = date.getDay();
|
|
1077
|
+
switch (token) {
|
|
1078
|
+
// Tue
|
|
1079
|
+
case "E":
|
|
1080
|
+
case "EE":
|
|
1081
|
+
case "EEE":
|
|
1082
|
+
return localize2.day(dayOfWeek, {
|
|
1083
|
+
width: "abbreviated",
|
|
1084
|
+
context: "formatting"
|
|
1085
|
+
});
|
|
1086
|
+
// T
|
|
1087
|
+
case "EEEEE":
|
|
1088
|
+
return localize2.day(dayOfWeek, {
|
|
1089
|
+
width: "narrow",
|
|
1090
|
+
context: "formatting"
|
|
1091
|
+
});
|
|
1092
|
+
// Tu
|
|
1093
|
+
case "EEEEEE":
|
|
1094
|
+
return localize2.day(dayOfWeek, {
|
|
1095
|
+
width: "short",
|
|
1096
|
+
context: "formatting"
|
|
1097
|
+
});
|
|
1098
|
+
// Tuesday
|
|
1099
|
+
case "EEEE":
|
|
1100
|
+
default:
|
|
1101
|
+
return localize2.day(dayOfWeek, {
|
|
1102
|
+
width: "wide",
|
|
1103
|
+
context: "formatting"
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1107
|
+
// Local day of week
|
|
1108
|
+
e: function(date, token, localize2, options) {
|
|
1109
|
+
const dayOfWeek = date.getDay();
|
|
1110
|
+
const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
|
1111
|
+
switch (token) {
|
|
1112
|
+
// Numerical value (Nth day of week with current locale or weekStartsOn)
|
|
1113
|
+
case "e":
|
|
1114
|
+
return String(localDayOfWeek);
|
|
1115
|
+
// Padded numerical value
|
|
1116
|
+
case "ee":
|
|
1117
|
+
return addLeadingZeros(localDayOfWeek, 2);
|
|
1118
|
+
// 1st, 2nd, ..., 7th
|
|
1119
|
+
case "eo":
|
|
1120
|
+
return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
|
|
1121
|
+
case "eee":
|
|
1122
|
+
return localize2.day(dayOfWeek, {
|
|
1123
|
+
width: "abbreviated",
|
|
1124
|
+
context: "formatting"
|
|
1125
|
+
});
|
|
1126
|
+
// T
|
|
1127
|
+
case "eeeee":
|
|
1128
|
+
return localize2.day(dayOfWeek, {
|
|
1129
|
+
width: "narrow",
|
|
1130
|
+
context: "formatting"
|
|
1131
|
+
});
|
|
1132
|
+
// Tu
|
|
1133
|
+
case "eeeeee":
|
|
1134
|
+
return localize2.day(dayOfWeek, {
|
|
1135
|
+
width: "short",
|
|
1136
|
+
context: "formatting"
|
|
1137
|
+
});
|
|
1138
|
+
// Tuesday
|
|
1139
|
+
case "eeee":
|
|
1140
|
+
default:
|
|
1141
|
+
return localize2.day(dayOfWeek, {
|
|
1142
|
+
width: "wide",
|
|
1143
|
+
context: "formatting"
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
},
|
|
1147
|
+
// Stand-alone local day of week
|
|
1148
|
+
c: function(date, token, localize2, options) {
|
|
1149
|
+
const dayOfWeek = date.getDay();
|
|
1150
|
+
const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
|
1151
|
+
switch (token) {
|
|
1152
|
+
// Numerical value (same as in `e`)
|
|
1153
|
+
case "c":
|
|
1154
|
+
return String(localDayOfWeek);
|
|
1155
|
+
// Padded numerical value
|
|
1156
|
+
case "cc":
|
|
1157
|
+
return addLeadingZeros(localDayOfWeek, token.length);
|
|
1158
|
+
// 1st, 2nd, ..., 7th
|
|
1159
|
+
case "co":
|
|
1160
|
+
return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
|
|
1161
|
+
case "ccc":
|
|
1162
|
+
return localize2.day(dayOfWeek, {
|
|
1163
|
+
width: "abbreviated",
|
|
1164
|
+
context: "standalone"
|
|
1165
|
+
});
|
|
1166
|
+
// T
|
|
1167
|
+
case "ccccc":
|
|
1168
|
+
return localize2.day(dayOfWeek, {
|
|
1169
|
+
width: "narrow",
|
|
1170
|
+
context: "standalone"
|
|
1171
|
+
});
|
|
1172
|
+
// Tu
|
|
1173
|
+
case "cccccc":
|
|
1174
|
+
return localize2.day(dayOfWeek, {
|
|
1175
|
+
width: "short",
|
|
1176
|
+
context: "standalone"
|
|
1177
|
+
});
|
|
1178
|
+
// Tuesday
|
|
1179
|
+
case "cccc":
|
|
1180
|
+
default:
|
|
1181
|
+
return localize2.day(dayOfWeek, {
|
|
1182
|
+
width: "wide",
|
|
1183
|
+
context: "standalone"
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
},
|
|
1187
|
+
// ISO day of week
|
|
1188
|
+
i: function(date, token, localize2) {
|
|
1189
|
+
const dayOfWeek = date.getDay();
|
|
1190
|
+
const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
|
|
1191
|
+
switch (token) {
|
|
1192
|
+
// 2
|
|
1193
|
+
case "i":
|
|
1194
|
+
return String(isoDayOfWeek);
|
|
1195
|
+
// 02
|
|
1196
|
+
case "ii":
|
|
1197
|
+
return addLeadingZeros(isoDayOfWeek, token.length);
|
|
1198
|
+
// 2nd
|
|
1199
|
+
case "io":
|
|
1200
|
+
return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
|
|
1201
|
+
// Tue
|
|
1202
|
+
case "iii":
|
|
1203
|
+
return localize2.day(dayOfWeek, {
|
|
1204
|
+
width: "abbreviated",
|
|
1205
|
+
context: "formatting"
|
|
1206
|
+
});
|
|
1207
|
+
// T
|
|
1208
|
+
case "iiiii":
|
|
1209
|
+
return localize2.day(dayOfWeek, {
|
|
1210
|
+
width: "narrow",
|
|
1211
|
+
context: "formatting"
|
|
1212
|
+
});
|
|
1213
|
+
// Tu
|
|
1214
|
+
case "iiiiii":
|
|
1215
|
+
return localize2.day(dayOfWeek, {
|
|
1216
|
+
width: "short",
|
|
1217
|
+
context: "formatting"
|
|
1218
|
+
});
|
|
1219
|
+
// Tuesday
|
|
1220
|
+
case "iiii":
|
|
1221
|
+
default:
|
|
1222
|
+
return localize2.day(dayOfWeek, {
|
|
1223
|
+
width: "wide",
|
|
1224
|
+
context: "formatting"
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
1228
|
+
// AM or PM
|
|
1229
|
+
a: function(date, token, localize2) {
|
|
1230
|
+
const hours = date.getHours();
|
|
1231
|
+
const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
|
|
1232
|
+
switch (token) {
|
|
1233
|
+
case "a":
|
|
1234
|
+
case "aa":
|
|
1235
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1236
|
+
width: "abbreviated",
|
|
1237
|
+
context: "formatting"
|
|
1238
|
+
});
|
|
1239
|
+
case "aaa":
|
|
1240
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1241
|
+
width: "abbreviated",
|
|
1242
|
+
context: "formatting"
|
|
1243
|
+
}).toLowerCase();
|
|
1244
|
+
case "aaaaa":
|
|
1245
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1246
|
+
width: "narrow",
|
|
1247
|
+
context: "formatting"
|
|
1248
|
+
});
|
|
1249
|
+
case "aaaa":
|
|
1250
|
+
default:
|
|
1251
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1252
|
+
width: "wide",
|
|
1253
|
+
context: "formatting"
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
},
|
|
1257
|
+
// AM, PM, midnight, noon
|
|
1258
|
+
b: function(date, token, localize2) {
|
|
1259
|
+
const hours = date.getHours();
|
|
1260
|
+
let dayPeriodEnumValue;
|
|
1261
|
+
if (hours === 12) {
|
|
1262
|
+
dayPeriodEnumValue = dayPeriodEnum.noon;
|
|
1263
|
+
} else if (hours === 0) {
|
|
1264
|
+
dayPeriodEnumValue = dayPeriodEnum.midnight;
|
|
1265
|
+
} else {
|
|
1266
|
+
dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
|
|
1267
|
+
}
|
|
1268
|
+
switch (token) {
|
|
1269
|
+
case "b":
|
|
1270
|
+
case "bb":
|
|
1271
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1272
|
+
width: "abbreviated",
|
|
1273
|
+
context: "formatting"
|
|
1274
|
+
});
|
|
1275
|
+
case "bbb":
|
|
1276
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1277
|
+
width: "abbreviated",
|
|
1278
|
+
context: "formatting"
|
|
1279
|
+
}).toLowerCase();
|
|
1280
|
+
case "bbbbb":
|
|
1281
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1282
|
+
width: "narrow",
|
|
1283
|
+
context: "formatting"
|
|
1284
|
+
});
|
|
1285
|
+
case "bbbb":
|
|
1286
|
+
default:
|
|
1287
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1288
|
+
width: "wide",
|
|
1289
|
+
context: "formatting"
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1293
|
+
// in the morning, in the afternoon, in the evening, at night
|
|
1294
|
+
B: function(date, token, localize2) {
|
|
1295
|
+
const hours = date.getHours();
|
|
1296
|
+
let dayPeriodEnumValue;
|
|
1297
|
+
if (hours >= 17) {
|
|
1298
|
+
dayPeriodEnumValue = dayPeriodEnum.evening;
|
|
1299
|
+
} else if (hours >= 12) {
|
|
1300
|
+
dayPeriodEnumValue = dayPeriodEnum.afternoon;
|
|
1301
|
+
} else if (hours >= 4) {
|
|
1302
|
+
dayPeriodEnumValue = dayPeriodEnum.morning;
|
|
1303
|
+
} else {
|
|
1304
|
+
dayPeriodEnumValue = dayPeriodEnum.night;
|
|
1305
|
+
}
|
|
1306
|
+
switch (token) {
|
|
1307
|
+
case "B":
|
|
1308
|
+
case "BB":
|
|
1309
|
+
case "BBB":
|
|
1310
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1311
|
+
width: "abbreviated",
|
|
1312
|
+
context: "formatting"
|
|
1313
|
+
});
|
|
1314
|
+
case "BBBBB":
|
|
1315
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1316
|
+
width: "narrow",
|
|
1317
|
+
context: "formatting"
|
|
1318
|
+
});
|
|
1319
|
+
case "BBBB":
|
|
1320
|
+
default:
|
|
1321
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1322
|
+
width: "wide",
|
|
1323
|
+
context: "formatting"
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
},
|
|
1327
|
+
// Hour [1-12]
|
|
1328
|
+
h: function(date, token, localize2) {
|
|
1329
|
+
if (token === "ho") {
|
|
1330
|
+
let hours = date.getHours() % 12;
|
|
1331
|
+
if (hours === 0) hours = 12;
|
|
1332
|
+
return localize2.ordinalNumber(hours, { unit: "hour" });
|
|
1333
|
+
}
|
|
1334
|
+
return lightFormatters.h(date, token);
|
|
1335
|
+
},
|
|
1336
|
+
// Hour [0-23]
|
|
1337
|
+
H: function(date, token, localize2) {
|
|
1338
|
+
if (token === "Ho") {
|
|
1339
|
+
return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
|
|
1340
|
+
}
|
|
1341
|
+
return lightFormatters.H(date, token);
|
|
1342
|
+
},
|
|
1343
|
+
// Hour [0-11]
|
|
1344
|
+
K: function(date, token, localize2) {
|
|
1345
|
+
const hours = date.getHours() % 12;
|
|
1346
|
+
if (token === "Ko") {
|
|
1347
|
+
return localize2.ordinalNumber(hours, { unit: "hour" });
|
|
1348
|
+
}
|
|
1349
|
+
return addLeadingZeros(hours, token.length);
|
|
1350
|
+
},
|
|
1351
|
+
// Hour [1-24]
|
|
1352
|
+
k: function(date, token, localize2) {
|
|
1353
|
+
let hours = date.getHours();
|
|
1354
|
+
if (hours === 0) hours = 24;
|
|
1355
|
+
if (token === "ko") {
|
|
1356
|
+
return localize2.ordinalNumber(hours, { unit: "hour" });
|
|
1357
|
+
}
|
|
1358
|
+
return addLeadingZeros(hours, token.length);
|
|
1359
|
+
},
|
|
1360
|
+
// Minute
|
|
1361
|
+
m: function(date, token, localize2) {
|
|
1362
|
+
if (token === "mo") {
|
|
1363
|
+
return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
|
|
1364
|
+
}
|
|
1365
|
+
return lightFormatters.m(date, token);
|
|
1366
|
+
},
|
|
1367
|
+
// Second
|
|
1368
|
+
s: function(date, token, localize2) {
|
|
1369
|
+
if (token === "so") {
|
|
1370
|
+
return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
|
|
1371
|
+
}
|
|
1372
|
+
return lightFormatters.s(date, token);
|
|
1373
|
+
},
|
|
1374
|
+
// Fraction of second
|
|
1375
|
+
S: function(date, token) {
|
|
1376
|
+
return lightFormatters.S(date, token);
|
|
1377
|
+
},
|
|
1378
|
+
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
|
|
1379
|
+
X: function(date, token, _localize) {
|
|
1380
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1381
|
+
if (timezoneOffset === 0) {
|
|
1382
|
+
return "Z";
|
|
1383
|
+
}
|
|
1384
|
+
switch (token) {
|
|
1385
|
+
// Hours and optional minutes
|
|
1386
|
+
case "X":
|
|
1387
|
+
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
|
1388
|
+
// Hours, minutes and optional seconds without `:` delimiter
|
|
1389
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1390
|
+
// so this token always has the same output as `XX`
|
|
1391
|
+
case "XXXX":
|
|
1392
|
+
case "XX":
|
|
1393
|
+
return formatTimezone(timezoneOffset);
|
|
1394
|
+
// Hours, minutes and optional seconds with `:` delimiter
|
|
1395
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1396
|
+
// so this token always has the same output as `XXX`
|
|
1397
|
+
case "XXXXX":
|
|
1398
|
+
case "XXX":
|
|
1399
|
+
// Hours and minutes with `:` delimiter
|
|
1400
|
+
default:
|
|
1401
|
+
return formatTimezone(timezoneOffset, ":");
|
|
1402
|
+
}
|
|
1403
|
+
},
|
|
1404
|
+
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
|
|
1405
|
+
x: function(date, token, _localize) {
|
|
1406
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1407
|
+
switch (token) {
|
|
1408
|
+
// Hours and optional minutes
|
|
1409
|
+
case "x":
|
|
1410
|
+
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
|
1411
|
+
// Hours, minutes and optional seconds without `:` delimiter
|
|
1412
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1413
|
+
// so this token always has the same output as `xx`
|
|
1414
|
+
case "xxxx":
|
|
1415
|
+
case "xx":
|
|
1416
|
+
return formatTimezone(timezoneOffset);
|
|
1417
|
+
// Hours, minutes and optional seconds with `:` delimiter
|
|
1418
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1419
|
+
// so this token always has the same output as `xxx`
|
|
1420
|
+
case "xxxxx":
|
|
1421
|
+
case "xxx":
|
|
1422
|
+
// Hours and minutes with `:` delimiter
|
|
1423
|
+
default:
|
|
1424
|
+
return formatTimezone(timezoneOffset, ":");
|
|
1425
|
+
}
|
|
1426
|
+
},
|
|
1427
|
+
// Timezone (GMT)
|
|
1428
|
+
O: function(date, token, _localize) {
|
|
1429
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1430
|
+
switch (token) {
|
|
1431
|
+
// Short
|
|
1432
|
+
case "O":
|
|
1433
|
+
case "OO":
|
|
1434
|
+
case "OOO":
|
|
1435
|
+
return "GMT" + formatTimezoneShort(timezoneOffset, ":");
|
|
1436
|
+
// Long
|
|
1437
|
+
case "OOOO":
|
|
1438
|
+
default:
|
|
1439
|
+
return "GMT" + formatTimezone(timezoneOffset, ":");
|
|
1440
|
+
}
|
|
1441
|
+
},
|
|
1442
|
+
// Timezone (specific non-location)
|
|
1443
|
+
z: function(date, token, _localize) {
|
|
1444
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1445
|
+
switch (token) {
|
|
1446
|
+
// Short
|
|
1447
|
+
case "z":
|
|
1448
|
+
case "zz":
|
|
1449
|
+
case "zzz":
|
|
1450
|
+
return "GMT" + formatTimezoneShort(timezoneOffset, ":");
|
|
1451
|
+
// Long
|
|
1452
|
+
case "zzzz":
|
|
1453
|
+
default:
|
|
1454
|
+
return "GMT" + formatTimezone(timezoneOffset, ":");
|
|
1455
|
+
}
|
|
1456
|
+
},
|
|
1457
|
+
// Seconds timestamp
|
|
1458
|
+
t: function(date, token, _localize) {
|
|
1459
|
+
const timestamp = Math.trunc(+date / 1e3);
|
|
1460
|
+
return addLeadingZeros(timestamp, token.length);
|
|
1461
|
+
},
|
|
1462
|
+
// Milliseconds timestamp
|
|
1463
|
+
T: function(date, token, _localize) {
|
|
1464
|
+
return addLeadingZeros(+date, token.length);
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
function formatTimezoneShort(offset, delimiter = "") {
|
|
1468
|
+
const sign = offset > 0 ? "-" : "+";
|
|
1469
|
+
const absOffset = Math.abs(offset);
|
|
1470
|
+
const hours = Math.trunc(absOffset / 60);
|
|
1471
|
+
const minutes = absOffset % 60;
|
|
1472
|
+
if (minutes === 0) {
|
|
1473
|
+
return sign + String(hours);
|
|
1474
|
+
}
|
|
1475
|
+
return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
|
|
1476
|
+
}
|
|
1477
|
+
function formatTimezoneWithOptionalMinutes(offset, delimiter) {
|
|
1478
|
+
if (offset % 60 === 0) {
|
|
1479
|
+
const sign = offset > 0 ? "-" : "+";
|
|
1480
|
+
return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
|
|
1481
|
+
}
|
|
1482
|
+
return formatTimezone(offset, delimiter);
|
|
1483
|
+
}
|
|
1484
|
+
function formatTimezone(offset, delimiter = "") {
|
|
1485
|
+
const sign = offset > 0 ? "-" : "+";
|
|
1486
|
+
const absOffset = Math.abs(offset);
|
|
1487
|
+
const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
|
|
1488
|
+
const minutes = addLeadingZeros(absOffset % 60, 2);
|
|
1489
|
+
return sign + hours + delimiter + minutes;
|
|
1490
|
+
}
|
|
1491
|
+
const dateLongFormatter = (pattern, formatLong2) => {
|
|
1492
|
+
switch (pattern) {
|
|
1493
|
+
case "P":
|
|
1494
|
+
return formatLong2.date({ width: "short" });
|
|
1495
|
+
case "PP":
|
|
1496
|
+
return formatLong2.date({ width: "medium" });
|
|
1497
|
+
case "PPP":
|
|
1498
|
+
return formatLong2.date({ width: "long" });
|
|
1499
|
+
case "PPPP":
|
|
1500
|
+
default:
|
|
1501
|
+
return formatLong2.date({ width: "full" });
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
const timeLongFormatter = (pattern, formatLong2) => {
|
|
1505
|
+
switch (pattern) {
|
|
1506
|
+
case "p":
|
|
1507
|
+
return formatLong2.time({ width: "short" });
|
|
1508
|
+
case "pp":
|
|
1509
|
+
return formatLong2.time({ width: "medium" });
|
|
1510
|
+
case "ppp":
|
|
1511
|
+
return formatLong2.time({ width: "long" });
|
|
1512
|
+
case "pppp":
|
|
1513
|
+
default:
|
|
1514
|
+
return formatLong2.time({ width: "full" });
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
const dateTimeLongFormatter = (pattern, formatLong2) => {
|
|
1518
|
+
const matchResult = pattern.match(/(P+)(p+)?/) || [];
|
|
1519
|
+
const datePattern = matchResult[1];
|
|
1520
|
+
const timePattern = matchResult[2];
|
|
1521
|
+
if (!timePattern) {
|
|
1522
|
+
return dateLongFormatter(pattern, formatLong2);
|
|
1523
|
+
}
|
|
1524
|
+
let dateTimeFormat;
|
|
1525
|
+
switch (datePattern) {
|
|
1526
|
+
case "P":
|
|
1527
|
+
dateTimeFormat = formatLong2.dateTime({ width: "short" });
|
|
1528
|
+
break;
|
|
1529
|
+
case "PP":
|
|
1530
|
+
dateTimeFormat = formatLong2.dateTime({ width: "medium" });
|
|
1531
|
+
break;
|
|
1532
|
+
case "PPP":
|
|
1533
|
+
dateTimeFormat = formatLong2.dateTime({ width: "long" });
|
|
1534
|
+
break;
|
|
1535
|
+
case "PPPP":
|
|
1536
|
+
default:
|
|
1537
|
+
dateTimeFormat = formatLong2.dateTime({ width: "full" });
|
|
1538
|
+
break;
|
|
1539
|
+
}
|
|
1540
|
+
return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
|
|
1541
|
+
};
|
|
1542
|
+
const longFormatters = {
|
|
1543
|
+
p: timeLongFormatter,
|
|
1544
|
+
P: dateTimeLongFormatter
|
|
1545
|
+
};
|
|
1546
|
+
const dayOfYearTokenRE = /^D+$/;
|
|
1547
|
+
const weekYearTokenRE = /^Y+$/;
|
|
1548
|
+
const throwTokens = ["D", "DD", "YY", "YYYY"];
|
|
1549
|
+
function isProtectedDayOfYearToken(token) {
|
|
1550
|
+
return dayOfYearTokenRE.test(token);
|
|
1551
|
+
}
|
|
1552
|
+
function isProtectedWeekYearToken(token) {
|
|
1553
|
+
return weekYearTokenRE.test(token);
|
|
1554
|
+
}
|
|
1555
|
+
function warnOrThrowProtectedError(token, format2, input) {
|
|
1556
|
+
const _message = message(token, format2, input);
|
|
1557
|
+
console.warn(_message);
|
|
1558
|
+
if (throwTokens.includes(token)) throw new RangeError(_message);
|
|
1559
|
+
}
|
|
1560
|
+
function message(token, format2, input) {
|
|
1561
|
+
const subject = token[0] === "Y" ? "years" : "days of the month";
|
|
1562
|
+
return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format2}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
|
|
1563
|
+
}
|
|
1564
|
+
const formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
|
|
1565
|
+
const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
1566
|
+
const escapedStringRegExp = /^'([^]*?)'?$/;
|
|
1567
|
+
const doubleQuoteRegExp = /''/g;
|
|
1568
|
+
const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
|
|
1569
|
+
function format(date, formatStr, options) {
|
|
1570
|
+
const defaultOptions2 = getDefaultOptions();
|
|
1571
|
+
const locale = options?.locale ?? defaultOptions2.locale ?? enUS;
|
|
1572
|
+
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
|
|
1573
|
+
const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
|
|
1574
|
+
const originalDate = toDate(date, options?.in);
|
|
1575
|
+
if (!isValid(originalDate)) {
|
|
1576
|
+
throw new RangeError("Invalid time value");
|
|
1577
|
+
}
|
|
1578
|
+
let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
|
|
1579
|
+
const firstCharacter = substring[0];
|
|
1580
|
+
if (firstCharacter === "p" || firstCharacter === "P") {
|
|
1581
|
+
const longFormatter = longFormatters[firstCharacter];
|
|
1582
|
+
return longFormatter(substring, locale.formatLong);
|
|
1583
|
+
}
|
|
1584
|
+
return substring;
|
|
1585
|
+
}).join("").match(formattingTokensRegExp).map((substring) => {
|
|
1586
|
+
if (substring === "''") {
|
|
1587
|
+
return { isToken: false, value: "'" };
|
|
1588
|
+
}
|
|
1589
|
+
const firstCharacter = substring[0];
|
|
1590
|
+
if (firstCharacter === "'") {
|
|
1591
|
+
return { isToken: false, value: cleanEscapedString(substring) };
|
|
1592
|
+
}
|
|
1593
|
+
if (formatters[firstCharacter]) {
|
|
1594
|
+
return { isToken: true, value: substring };
|
|
1595
|
+
}
|
|
1596
|
+
if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
|
|
1597
|
+
throw new RangeError(
|
|
1598
|
+
"Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1601
|
+
return { isToken: false, value: substring };
|
|
1602
|
+
});
|
|
1603
|
+
if (locale.localize.preprocessor) {
|
|
1604
|
+
parts = locale.localize.preprocessor(originalDate, parts);
|
|
1605
|
+
}
|
|
1606
|
+
const formatterOptions = {
|
|
1607
|
+
firstWeekContainsDate,
|
|
1608
|
+
weekStartsOn,
|
|
1609
|
+
locale
|
|
1610
|
+
};
|
|
1611
|
+
return parts.map((part) => {
|
|
1612
|
+
if (!part.isToken) return part.value;
|
|
1613
|
+
const token = part.value;
|
|
1614
|
+
if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token) || !options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) {
|
|
1615
|
+
warnOrThrowProtectedError(token, formatStr, String(date));
|
|
1616
|
+
}
|
|
1617
|
+
const formatter = formatters[token[0]];
|
|
1618
|
+
return formatter(originalDate, token, locale.localize, formatterOptions);
|
|
1619
|
+
}).join("");
|
|
1620
|
+
}
|
|
1621
|
+
function cleanEscapedString(input) {
|
|
1622
|
+
const matched = input.match(escapedStringRegExp);
|
|
1623
|
+
if (!matched) {
|
|
1624
|
+
return input;
|
|
1625
|
+
}
|
|
1626
|
+
return matched[1].replace(doubleQuoteRegExp, "'");
|
|
1627
|
+
}
|
|
1628
|
+
function getDaysInMonth(date, options) {
|
|
1629
|
+
const _date = toDate(date, options?.in);
|
|
1630
|
+
const year = _date.getFullYear();
|
|
1631
|
+
const monthIndex = _date.getMonth();
|
|
1632
|
+
const lastDayOfMonth = constructFrom(_date, 0);
|
|
1633
|
+
lastDayOfMonth.setFullYear(year, monthIndex + 1, 0);
|
|
1634
|
+
lastDayOfMonth.setHours(0, 0, 0, 0);
|
|
1635
|
+
return lastDayOfMonth.getDate();
|
|
1636
|
+
}
|
|
1637
|
+
function getMonth(date, options) {
|
|
1638
|
+
return toDate(date, options?.in).getMonth();
|
|
1639
|
+
}
|
|
1640
|
+
function getYear(date, options) {
|
|
1641
|
+
return toDate(date, options?.in).getFullYear();
|
|
1642
|
+
}
|
|
1643
|
+
function isAfter(date, dateToCompare) {
|
|
1644
|
+
return +toDate(date) > +toDate(dateToCompare);
|
|
1645
|
+
}
|
|
1646
|
+
function isBefore(date, dateToCompare) {
|
|
1647
|
+
return +toDate(date) < +toDate(dateToCompare);
|
|
1648
|
+
}
|
|
1649
|
+
function isSameMonth(laterDate, earlierDate, options) {
|
|
1650
|
+
const [laterDate_, earlierDate_] = normalizeDates(
|
|
1651
|
+
options?.in,
|
|
1652
|
+
laterDate,
|
|
1653
|
+
earlierDate
|
|
1654
|
+
);
|
|
1655
|
+
return laterDate_.getFullYear() === earlierDate_.getFullYear() && laterDate_.getMonth() === earlierDate_.getMonth();
|
|
1656
|
+
}
|
|
1657
|
+
function isSameYear(laterDate, earlierDate, options) {
|
|
1658
|
+
const [laterDate_, earlierDate_] = normalizeDates(
|
|
1659
|
+
options?.in,
|
|
1660
|
+
laterDate,
|
|
1661
|
+
earlierDate
|
|
1662
|
+
);
|
|
1663
|
+
return laterDate_.getFullYear() === earlierDate_.getFullYear();
|
|
1664
|
+
}
|
|
1665
|
+
function setMonth(date, month, options) {
|
|
1666
|
+
const _date = toDate(date, options?.in);
|
|
1667
|
+
const year = _date.getFullYear();
|
|
1668
|
+
const day = _date.getDate();
|
|
1669
|
+
const midMonth = constructFrom(date, 0);
|
|
1670
|
+
midMonth.setFullYear(year, month, 15);
|
|
1671
|
+
midMonth.setHours(0, 0, 0, 0);
|
|
1672
|
+
const daysInMonth = getDaysInMonth(midMonth);
|
|
1673
|
+
_date.setMonth(month, Math.min(day, daysInMonth));
|
|
1674
|
+
return _date;
|
|
1675
|
+
}
|
|
1676
|
+
function setYear(date, year, options) {
|
|
1677
|
+
const date_ = toDate(date, options?.in);
|
|
1678
|
+
if (isNaN(+date_)) return constructFrom(date, NaN);
|
|
1679
|
+
date_.setFullYear(year);
|
|
1680
|
+
return date_;
|
|
1681
|
+
}
|
|
1682
|
+
export {
|
|
1683
|
+
setMonth as A,
|
|
1684
|
+
setYear as B,
|
|
1685
|
+
startOfDay as C,
|
|
1686
|
+
startOfISOWeek as D,
|
|
1687
|
+
startOfMonth as E,
|
|
1688
|
+
startOfWeek as F,
|
|
1689
|
+
startOfYear as G,
|
|
1690
|
+
addDays as a,
|
|
1691
|
+
addMonths as b,
|
|
1692
|
+
addWeeks as c,
|
|
1693
|
+
addYears as d,
|
|
1694
|
+
enUS as e,
|
|
1695
|
+
format as f,
|
|
1696
|
+
differenceInCalendarDays as g,
|
|
1697
|
+
differenceInCalendarMonths as h,
|
|
1698
|
+
eachMonthOfInterval as i,
|
|
1699
|
+
eachYearOfInterval as j,
|
|
1700
|
+
endOfISOWeek as k,
|
|
1701
|
+
endOfMonth as l,
|
|
1702
|
+
endOfWeek as m,
|
|
1703
|
+
endOfYear as n,
|
|
1704
|
+
getISOWeek as o,
|
|
1705
|
+
getMonth as p,
|
|
1706
|
+
getYear as q,
|
|
1707
|
+
getWeek as r,
|
|
1708
|
+
isAfter as s,
|
|
1709
|
+
isBefore as t,
|
|
1710
|
+
isDate as u,
|
|
1711
|
+
isSameDay as v,
|
|
1712
|
+
isSameMonth as w,
|
|
1713
|
+
isSameYear as x,
|
|
1714
|
+
max as y,
|
|
1715
|
+
min as z
|
|
1716
|
+
};
|