ivt 0.5.0 → 0.5.2
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/dist/accordion/index.mjs +15 -15
- package/dist/alert/index.mjs +2 -2
- package/dist/alert-dialog/index.mjs +17 -17
- package/dist/aspect-ratio/index.mjs +1 -1
- package/dist/aspect-ratio/index.mjs.map +1 -1
- package/dist/avatar/index.mjs +7 -7
- package/dist/badge/index.mjs +3 -3
- package/dist/base/index.d.ts +19 -2
- package/dist/base/index.mjs +46 -74
- package/dist/base/index.mjs.map +1 -1
- package/dist/breadcrumb/index.mjs +5 -5
- package/dist/button/index.mjs +3 -3
- package/dist/button-group/index.mjs +3 -3
- package/dist/calendar/index.mjs +9 -8
- package/dist/calendar/index.mjs.map +1 -1
- package/dist/card/index.mjs +4 -55
- package/dist/card/index.mjs.map +1 -1
- package/dist/carousel/index.mjs +4 -4
- package/dist/chart/index.mjs +15975 -15658
- package/dist/chart/index.mjs.map +1 -1
- package/dist/checkbox/index.mjs +16 -221
- package/dist/checkbox/index.mjs.map +1 -1
- package/dist/chunks/CalendarRange-cGKHXdiT.mjs +45 -0
- package/dist/chunks/CalendarRange-cGKHXdiT.mjs.map +1 -0
- package/dist/chunks/ComboboxField-BTKXl9y7.mjs +67 -0
- package/dist/chunks/ComboboxField-BTKXl9y7.mjs.map +1 -0
- package/dist/chunks/{Container-LlUz2Xf7.mjs → Container-BUT39dlc.mjs} +2 -2
- package/dist/chunks/{Container-LlUz2Xf7.mjs.map → Container-BUT39dlc.mjs.map} +1 -1
- package/dist/chunks/TooltipIndicator-EfXM1ogO.mjs +44 -0
- package/dist/chunks/TooltipIndicator-EfXM1ogO.mjs.map +1 -0
- package/dist/chunks/{_commonjsHelpers-CZIfjjiR.mjs → _commonjsHelpers-DCzDIER3.mjs} +1 -1
- package/dist/chunks/_commonjsHelpers-DCzDIER3.mjs.map +1 -0
- package/dist/chunks/{accordion-BBMhFkK5.mjs → accordion-BXurL6Pv.mjs} +11 -11
- package/dist/chunks/{accordion-BBMhFkK5.mjs.map → accordion-BXurL6Pv.mjs.map} +1 -1
- package/dist/chunks/{badge-CShT6Er8.mjs → badge-CpWQDnGV.mjs} +2 -2
- package/dist/chunks/{badge-CShT6Er8.mjs.map → badge-CpWQDnGV.mjs.map} +1 -1
- package/dist/chunks/{bundle-mjs-CXcNQyyo.mjs → bundle-mjs-C9OlPgmH.mjs} +1 -1
- package/dist/chunks/{bundle-mjs-CXcNQyyo.mjs.map → bundle-mjs-C9OlPgmH.mjs.map} +1 -1
- package/dist/chunks/{button-ay7E6KrE.mjs → button-BrmYbiY8.mjs} +2 -2
- package/dist/chunks/{button-ay7E6KrE.mjs.map → button-BrmYbiY8.mjs.map} +1 -1
- package/dist/chunks/{calendar-D98dWxWB.mjs → calendar-BQgywKTj.mjs} +8 -2641
- package/dist/chunks/calendar-BQgywKTj.mjs.map +1 -0
- package/dist/chunks/calendar-days-C_RzSweF.mjs +82 -0
- package/dist/chunks/calendar-days-C_RzSweF.mjs.map +1 -0
- package/dist/chunks/card-DeaeODxs.mjs +55 -0
- package/dist/chunks/card-DeaeODxs.mjs.map +1 -0
- package/dist/chunks/{check-M4AEcM3j.mjs → check-CP6BCwvU.mjs} +2 -2
- package/dist/chunks/{check-M4AEcM3j.mjs.map → check-CP6BCwvU.mjs.map} +1 -1
- package/dist/chunks/checkbox-BvnI-3Q6.mjs +219 -0
- package/dist/chunks/checkbox-BvnI-3Q6.mjs.map +1 -0
- package/dist/chunks/{chevron-down-BgIYlWhk.mjs → chevron-down-cCIwKwmA.mjs} +2 -2
- package/dist/chunks/{chevron-down-BgIYlWhk.mjs.map → chevron-down-cCIwKwmA.mjs.map} +1 -1
- package/dist/chunks/{chevron-left-wvVA3SWH.mjs → chevron-left-BPWGf-Mt.mjs} +2 -2
- package/dist/chunks/{chevron-left-wvVA3SWH.mjs.map → chevron-left-BPWGf-Mt.mjs.map} +1 -1
- package/dist/chunks/{chevron-right-aTufSnLl.mjs → chevron-right-Bk4Jys-R.mjs} +2 -2
- package/dist/chunks/{chevron-right-aTufSnLl.mjs.map → chevron-right-Bk4Jys-R.mjs.map} +1 -1
- package/dist/chunks/{chevrons-up-down-TytmUcIx.mjs → chevrons-up-down-BDmpiJmb.mjs} +2 -2
- package/dist/chunks/{chevrons-up-down-TytmUcIx.mjs.map → chevrons-up-down-BDmpiJmb.mjs.map} +1 -1
- package/dist/chunks/{command-OnnopJEP.mjs → command-CTTPLJSd.mjs} +54 -64
- package/dist/chunks/command-CTTPLJSd.mjs.map +1 -0
- package/dist/chunks/{createLucideIcon-DwD3HsEs.mjs → createLucideIcon-rdK7ReAV.mjs} +1 -1
- package/dist/chunks/{createLucideIcon-DwD3HsEs.mjs.map → createLucideIcon-rdK7ReAV.mjs.map} +1 -1
- package/dist/chunks/{pt-BR-on-YW6Ay.mjs → date-BF0VPeD6.mjs} +62 -97
- package/dist/chunks/date-BF0VPeD6.mjs.map +1 -0
- package/dist/chunks/{dialog-D-h9t9_b.mjs → dialog-BZ1Bem1X.mjs} +22 -21
- package/dist/chunks/dialog-BZ1Bem1X.mjs.map +1 -0
- package/dist/chunks/{ellipsis-x68Orkqp.mjs → ellipsis-CvvEpdNm.mjs} +2 -2
- package/dist/chunks/{ellipsis-x68Orkqp.mjs.map → ellipsis-CvvEpdNm.mjs.map} +1 -1
- package/dist/chunks/form-CLuajH9A.mjs +2223 -0
- package/dist/chunks/form-CLuajH9A.mjs.map +1 -0
- package/dist/chunks/format-DvB2IToG.mjs +2636 -0
- package/dist/chunks/format-DvB2IToG.mjs.map +1 -0
- package/dist/chunks/format-numbers-DtAwKNYo.mjs +55 -0
- package/dist/chunks/format-numbers-DtAwKNYo.mjs.map +1 -0
- package/dist/chunks/{hover-card-DXAGq71O.mjs → hover-card-Cwtai5wK.mjs} +11 -11
- package/dist/chunks/{hover-card-DXAGq71O.mjs.map → hover-card-Cwtai5wK.mjs.map} +1 -1
- package/dist/chunks/{index-BLAYpkjT.mjs → index-2wUt7vgM.mjs} +5 -5
- package/dist/chunks/{index-BLAYpkjT.mjs.map → index-2wUt7vgM.mjs.map} +1 -1
- package/dist/chunks/{index-DRdSNmMB.mjs → index-9Ejb37i6.mjs} +2 -2
- package/dist/chunks/{index-DRdSNmMB.mjs.map → index-9Ejb37i6.mjs.map} +1 -1
- package/dist/chunks/{index-B7kZbHfd.mjs → index-B0fljwsr.mjs} +1 -1
- package/dist/chunks/{index-B7kZbHfd.mjs.map → index-B0fljwsr.mjs.map} +1 -1
- package/dist/chunks/{index-BW3aCz7h.mjs → index-B1HovDby.mjs} +1 -1
- package/dist/chunks/{index-BW3aCz7h.mjs.map → index-B1HovDby.mjs.map} +1 -1
- package/dist/chunks/{index-BtRo1b5t.mjs → index-BpfkkunI.mjs} +3 -3
- package/dist/chunks/{index-BtRo1b5t.mjs.map → index-BpfkkunI.mjs.map} +1 -1
- package/dist/chunks/{index-DfjpL9Sk.mjs → index-C5dQnmlR.mjs} +9 -9
- package/dist/chunks/{index-DfjpL9Sk.mjs.map → index-C5dQnmlR.mjs.map} +1 -1
- package/dist/chunks/{index-C5cl9B-D.mjs → index-C7WDAsMc.mjs} +2 -2
- package/dist/chunks/{index-C5cl9B-D.mjs.map → index-C7WDAsMc.mjs.map} +1 -1
- package/dist/chunks/{index-BdYD9SA8.mjs → index-C8YG6ZVI.mjs} +1 -1
- package/dist/chunks/{index-BdYD9SA8.mjs.map → index-C8YG6ZVI.mjs.map} +1 -1
- package/dist/chunks/{index-BBONAxxm.mjs → index-CJIjOsdz.mjs} +1 -1
- package/dist/chunks/{index-BBONAxxm.mjs.map → index-CJIjOsdz.mjs.map} +1 -1
- package/dist/chunks/{index-DpqIXFxh.mjs → index-CN-1P6oe.mjs} +9 -9
- package/dist/chunks/{index-DpqIXFxh.mjs.map → index-CN-1P6oe.mjs.map} +1 -1
- package/dist/chunks/{index-C45e7-3X.mjs → index-CcfhA3fh.mjs} +11 -11
- package/dist/chunks/{index-C45e7-3X.mjs.map → index-CcfhA3fh.mjs.map} +1 -1
- package/dist/chunks/{index-CMbJ1I29.mjs → index-CdbLHZ-v.mjs} +2 -2
- package/dist/chunks/{index-CMbJ1I29.mjs.map → index-CdbLHZ-v.mjs.map} +1 -1
- package/dist/chunks/{index-BBC4sR1G.mjs → index-D4Y6_Jit.mjs} +5 -5
- package/dist/chunks/{index-BBC4sR1G.mjs.map → index-D4Y6_Jit.mjs.map} +1 -1
- package/dist/chunks/{index-Db1acFFW.mjs → index-DEFfOyUE.mjs} +1 -1
- package/dist/chunks/{index-Db1acFFW.mjs.map → index-DEFfOyUE.mjs.map} +1 -1
- package/dist/chunks/{index-Bs4nZmb7.mjs → index-DFMyqwc8.mjs} +2 -2
- package/dist/chunks/{index-Bs4nZmb7.mjs.map → index-DFMyqwc8.mjs.map} +1 -1
- package/dist/chunks/{index-D5pght6h.mjs → index-DNPAHxPV.mjs} +1 -1
- package/dist/chunks/{index-D5pght6h.mjs.map → index-DNPAHxPV.mjs.map} +1 -1
- package/dist/chunks/{index-qOZvnMSQ.mjs → index-DkhtbUNc.mjs} +1 -1
- package/dist/chunks/{index-qOZvnMSQ.mjs.map → index-DkhtbUNc.mjs.map} +1 -1
- package/dist/chunks/{index-DU7dxusa.mjs → index-Dpe5NTKJ.mjs} +7 -7
- package/dist/chunks/{index-DU7dxusa.mjs.map → index-Dpe5NTKJ.mjs.map} +1 -1
- package/dist/chunks/{index-CLb4rDzh.mjs → index-DymROPqb.mjs} +1 -1
- package/dist/chunks/{index-CLb4rDzh.mjs.map → index-DymROPqb.mjs.map} +1 -1
- package/dist/chunks/{index-BxaETqU9.mjs → index-LOIUbp1N.mjs} +3 -3
- package/dist/chunks/{index-BxaETqU9.mjs.map → index-LOIUbp1N.mjs.map} +1 -1
- package/dist/chunks/{index-C9twRC0t.mjs → index-N54PlKgO.mjs} +1 -1
- package/dist/chunks/{index-C9twRC0t.mjs.map → index-N54PlKgO.mjs.map} +1 -1
- package/dist/chunks/{index-BsVg0u5v.mjs → index-SHhYuecD.mjs} +1 -1
- package/dist/chunks/{index-BsVg0u5v.mjs.map → index-SHhYuecD.mjs.map} +1 -1
- package/dist/chunks/{index-CVGBR4nU.mjs → index-eIYpJRu_.mjs} +15 -15
- package/dist/chunks/{index-CVGBR4nU.mjs.map → index-eIYpJRu_.mjs.map} +1 -1
- package/dist/chunks/{input-CqipwgOY.mjs → input-BRRi8JbN.mjs} +2 -2
- package/dist/chunks/{input-CqipwgOY.mjs.map → input-BRRi8JbN.mjs.map} +1 -1
- package/dist/chunks/{label-Cx4XtbXv.mjs → label-DyMdyPfF.mjs} +3 -3
- package/dist/chunks/{label-Cx4XtbXv.mjs.map → label-DyMdyPfF.mjs.map} +1 -1
- package/dist/chunks/{loader-circle-CfhWFS-M.mjs → loader-circle-DlDf3jDF.mjs} +2 -2
- package/dist/chunks/{loader-circle-CfhWFS-M.mjs.map → loader-circle-DlDf3jDF.mjs.map} +1 -1
- package/dist/chunks/multi-select-BAp66njF.mjs +277 -0
- package/dist/chunks/multi-select-BAp66njF.mjs.map +1 -0
- package/dist/chunks/{pagination-CzDSUdbY.mjs → pagination-CoQF8H-y.mjs} +6 -6
- package/dist/chunks/{pagination-CzDSUdbY.mjs.map → pagination-CoQF8H-y.mjs.map} +1 -1
- package/dist/chunks/{popover-BFcKYAot.mjs → popover-Bx3Ak-qS.mjs} +13 -13
- package/dist/chunks/{popover-BFcKYAot.mjs.map → popover-Bx3Ak-qS.mjs.map} +1 -1
- package/dist/chunks/{progress-Cm71BOo_.mjs → progress-Unv1Ywou.mjs} +4 -4
- package/dist/chunks/{progress-Cm71BOo_.mjs.map → progress-Unv1Ywou.mjs.map} +1 -1
- package/dist/chunks/{scroll-area-B9cWImdG.mjs → scroll-area-Bu_eg6tq.mjs} +11 -11
- package/dist/chunks/{scroll-area-B9cWImdG.mjs.map → scroll-area-Bu_eg6tq.mjs.map} +1 -1
- package/dist/chunks/{select-CQBb4aB3.mjs → select-VgTkuC8i.mjs} +5 -5
- package/dist/chunks/{select-CQBb4aB3.mjs.map → select-VgTkuC8i.mjs.map} +1 -1
- package/dist/chunks/{separator-D6zbGj0R.mjs → separator-ChTsmHyH.mjs} +3 -3
- package/dist/chunks/{separator-D6zbGj0R.mjs.map → separator-ChTsmHyH.mjs.map} +1 -1
- package/dist/chunks/{sheet-C0AR_o6p.mjs → sheet-CX9dlZuk.mjs} +4 -4
- package/dist/chunks/{sheet-C0AR_o6p.mjs.map → sheet-CX9dlZuk.mjs.map} +1 -1
- package/dist/chunks/{skeleton-Bd9uEq1R.mjs → skeleton-TvPSLZ-7.mjs} +2 -2
- package/dist/chunks/{skeleton-Bd9uEq1R.mjs.map → skeleton-TvPSLZ-7.mjs.map} +1 -1
- package/dist/chunks/{sortable-CTcnqQX_.mjs → sortable-DQ0ESvYM.mjs} +3 -3
- package/dist/chunks/{sortable-CTcnqQX_.mjs.map → sortable-DQ0ESvYM.mjs.map} +1 -1
- package/dist/chunks/{table-C829r3Zv.mjs → table-5dae4DKj.mjs} +2 -2
- package/dist/chunks/{table-C829r3Zv.mjs.map → table-5dae4DKj.mjs.map} +1 -1
- package/dist/chunks/{textarea-CD6y9GNW.mjs → textarea-C6sc9FNI.mjs} +2 -2
- package/dist/chunks/{textarea-CD6y9GNW.mjs.map → textarea-C6sc9FNI.mjs.map} +1 -1
- package/dist/chunks/{toggle-C8fZP79W.mjs → toggle-SS3ISGud.mjs} +5 -5
- package/dist/chunks/{toggle-C8fZP79W.mjs.map → toggle-SS3ISGud.mjs.map} +1 -1
- package/dist/chunks/{tooltip-R49U1IPs.mjs → tooltip-WyVePJR7.mjs} +13 -13
- package/dist/chunks/{tooltip-R49U1IPs.mjs.map → tooltip-WyVePJR7.mjs.map} +1 -1
- package/dist/chunks/{trash-2-ZC16Df_k.mjs → trash-2-Dp8LY8vw.mjs} +2 -2
- package/dist/chunks/{trash-2-ZC16Df_k.mjs.map → trash-2-Dp8LY8vw.mjs.map} +1 -1
- package/dist/chunks/triangle-alert-CpLMma6K.mjs +29 -0
- package/dist/chunks/triangle-alert-CpLMma6K.mjs.map +1 -0
- package/dist/chunks/{tslib.es6-CnQYzBlA.mjs → tslib.es6-BgXxJBc3.mjs} +1 -1
- package/dist/chunks/{tslib.es6-CnQYzBlA.mjs.map → tslib.es6-BgXxJBc3.mjs.map} +1 -1
- package/dist/chunks/{utils-DwA_HfJw.mjs → utils-DfaTa-5f.mjs} +2 -2
- package/dist/chunks/{utils-DwA_HfJw.mjs.map → utils-DfaTa-5f.mjs.map} +1 -1
- package/dist/chunks/{x-BZdVnIMx.mjs → x-BtRqeVV7.mjs} +2 -2
- package/dist/chunks/{x-BZdVnIMx.mjs.map → x-BtRqeVV7.mjs.map} +1 -1
- package/dist/collapsible/index.mjs +9 -9
- package/dist/combobox/index.d.ts +8 -1
- package/dist/combobox/index.mjs +121 -39
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/command/index.d.ts +79 -16
- package/dist/command/index.mjs +20 -20
- package/dist/context-menu/index.mjs +23 -23
- package/dist/dash/index.d.ts +49 -0
- package/dist/dash/index.mjs +105 -0
- package/dist/dash/index.mjs.map +1 -0
- package/dist/data-table/index.d.ts +9 -4
- package/dist/data-table/index.mjs +71 -60
- package/dist/data-table/index.mjs.map +1 -1
- package/dist/date-picker/index.mjs +27 -25
- package/dist/date-picker/index.mjs.map +1 -1
- package/dist/dialog/index.d.ts +13 -11
- package/dist/dialog/index.mjs +19 -19
- package/dist/drawer/index.mjs +16 -16
- package/dist/dropdown-menu/index.mjs +23 -23
- package/dist/dropzone/index.d.ts +6 -0
- package/dist/dropzone/index.mjs +40 -28
- package/dist/dropzone/index.mjs.map +1 -1
- package/dist/empty/index.mjs +2 -2
- package/dist/field/index.mjs +5 -5
- package/dist/form/index.mjs +7 -653
- package/dist/form/index.mjs.map +1 -1
- package/dist/form-fields/index.d.ts +13 -0
- package/dist/form-fields/index.mjs +34 -0
- package/dist/form-fields/index.mjs.map +1 -0
- package/dist/hover-card/index.mjs +15 -15
- package/dist/icon/index.mjs +1 -1
- package/dist/index.css +1 -1
- package/dist/input/index.mjs +3 -3
- package/dist/input-group/index.mjs +5 -5
- package/dist/input-otp/index.mjs +3 -3
- package/dist/item/index.mjs +4 -4
- package/dist/ivt.css +1 -1
- package/dist/kbd/index.mjs +2 -2
- package/dist/label/index.mjs +4 -4
- package/dist/layout/index.mjs +6 -30
- package/dist/layout/index.mjs.map +1 -1
- package/dist/menubar/index.mjs +23 -23
- package/dist/multi-select/index.mjs +33 -295
- package/dist/multi-select/index.mjs.map +1 -1
- package/dist/navigation-menu/index.mjs +17 -17
- package/dist/pagination/index.mjs +8 -8
- package/dist/popover/index.mjs +18 -18
- package/dist/progress/index.mjs +5 -5
- package/dist/radio-group/index.mjs +17 -17
- package/dist/resizable/index.mjs +3 -3
- package/dist/scroll-area/index.mjs +12 -12
- package/dist/select/index.mjs +6 -6
- package/dist/separator/index.mjs +4 -4
- package/dist/shared/index.mjs +5 -5
- package/dist/sheet/index.mjs +19 -19
- package/dist/sidebar/index.mjs +27 -27
- package/dist/skeleton/index.mjs +3 -3
- package/dist/skeleton-component/index.mjs +4 -4
- package/dist/slider/index.mjs +12 -12
- package/dist/slider/index.mjs.map +1 -1
- package/dist/sortable/index.mjs +4 -4
- package/dist/spinner/index.mjs +4 -4
- package/dist/switch/index.mjs +10 -10
- package/dist/table/index.mjs +3 -3
- package/dist/table-filter/index.d.ts +49 -0
- package/dist/table-filter/index.mjs +2068 -0
- package/dist/table-filter/index.mjs.map +1 -0
- package/dist/tabs/index.mjs +13 -13
- package/dist/textarea/index.mjs +3 -3
- package/dist/toast/index.mjs +15 -15
- package/dist/toggle/index.mjs +7 -7
- package/dist/toggle-group/index.mjs +13 -13
- package/dist/tooltip/index.mjs +17 -17
- package/package.json +15 -2
- package/dist/chunks/_commonjsHelpers-CZIfjjiR.mjs.map +0 -1
- package/dist/chunks/calendar-D98dWxWB.mjs.map +0 -1
- package/dist/chunks/command-OnnopJEP.mjs.map +0 -1
- package/dist/chunks/dialog-D-h9t9_b.mjs.map +0 -1
- package/dist/chunks/pt-BR-on-YW6Ay.mjs.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { createContext, useContext, useCallback, useRef, useLayoutEffect, useState, useEffect, useMemo } from 'react';
|
|
3
|
-
import { c as cn } from './utils-
|
|
4
|
-
import { C as
|
|
5
|
-
import { C as
|
|
6
|
-
import { C as
|
|
7
|
-
import {
|
|
3
|
+
import { c as cn } from './utils-DfaTa-5f.mjs';
|
|
4
|
+
import { t as toDate, c as constructFrom, j as addDays, y as normalizeDates, z as startOfDay, g as getDefaultOptions, A as differenceInCalendarDays, f as format, i as getISOWeek, h as getWeek, B as isDate, e as startOfISOWeek, s as startOfWeek, C as startOfYear, l as enUS } from './format-DvB2IToG.mjs';
|
|
5
|
+
import { C as ChevronLeft } from './chevron-left-BPWGf-Mt.mjs';
|
|
6
|
+
import { C as ChevronRight } from './chevron-right-Bk4Jys-R.mjs';
|
|
7
|
+
import { C as ChevronDown } from './chevron-down-cCIwKwmA.mjs';
|
|
8
|
+
import { b as buttonVariants, B as Button$1 } from './button-BrmYbiY8.mjs';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Time zone name format.
|
|
@@ -346,158 +347,6 @@ class TZDate extends TZDateMini {
|
|
|
346
347
|
}
|
|
347
348
|
}
|
|
348
349
|
|
|
349
|
-
/**
|
|
350
|
-
* @constant
|
|
351
|
-
* @name millisecondsInWeek
|
|
352
|
-
* @summary Milliseconds in 1 week.
|
|
353
|
-
*/ const millisecondsInWeek = 604800000;
|
|
354
|
-
/**
|
|
355
|
-
* @constant
|
|
356
|
-
* @name millisecondsInDay
|
|
357
|
-
* @summary Milliseconds in 1 day.
|
|
358
|
-
*/ const millisecondsInDay = 86400000;
|
|
359
|
-
/**
|
|
360
|
-
* @constant
|
|
361
|
-
* @name millisecondsInMinute
|
|
362
|
-
* @summary Milliseconds in 1 minute
|
|
363
|
-
*/ const millisecondsInMinute = 60000;
|
|
364
|
-
/**
|
|
365
|
-
* @constant
|
|
366
|
-
* @name millisecondsInHour
|
|
367
|
-
* @summary Milliseconds in 1 hour
|
|
368
|
-
*/ const millisecondsInHour = 3600000;
|
|
369
|
-
/**
|
|
370
|
-
* @constant
|
|
371
|
-
* @name millisecondsInSecond
|
|
372
|
-
* @summary Milliseconds in 1 second
|
|
373
|
-
*/ const millisecondsInSecond = 1000;
|
|
374
|
-
/**
|
|
375
|
-
* @constant
|
|
376
|
-
* @name constructFromSymbol
|
|
377
|
-
* @summary Symbol enabling Date extensions to inherit properties from the reference date.
|
|
378
|
-
*
|
|
379
|
-
* The symbol is used to enable the `constructFrom` function to construct a date
|
|
380
|
-
* using a reference date and a value. It allows to transfer extra properties
|
|
381
|
-
* from the reference date to the new date. It's useful for extensions like
|
|
382
|
-
* [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
|
|
383
|
-
* a constructor argument.
|
|
384
|
-
*/ const constructFromSymbol = Symbol.for("constructDateFrom");
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* @name constructFrom
|
|
388
|
-
* @category Generic Helpers
|
|
389
|
-
* @summary Constructs a date using the reference date and the value
|
|
390
|
-
*
|
|
391
|
-
* @description
|
|
392
|
-
* The function constructs a new date using the constructor from the reference
|
|
393
|
-
* date and the given value. It helps to build generic functions that accept
|
|
394
|
-
* date extensions.
|
|
395
|
-
*
|
|
396
|
-
* It defaults to `Date` if the passed reference date is a number or a string.
|
|
397
|
-
*
|
|
398
|
-
* Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
|
|
399
|
-
* enabling to transfer extra properties from the reference date to the new date.
|
|
400
|
-
* It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
|
|
401
|
-
* that accept a time zone as a constructor argument.
|
|
402
|
-
*
|
|
403
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
404
|
-
*
|
|
405
|
-
* @param date - The reference date to take constructor from
|
|
406
|
-
* @param value - The value to create the date
|
|
407
|
-
*
|
|
408
|
-
* @returns Date initialized using the given date and value
|
|
409
|
-
*
|
|
410
|
-
* @example
|
|
411
|
-
* import { constructFrom } from "./constructFrom/date-fns";
|
|
412
|
-
*
|
|
413
|
-
* // A function that clones a date preserving the original type
|
|
414
|
-
* function cloneDate<DateType extends Date>(date: DateType): DateType {
|
|
415
|
-
* return constructFrom(
|
|
416
|
-
* date, // Use constructor from the given date
|
|
417
|
-
* date.getTime() // Use the date value to create a new date
|
|
418
|
-
* );
|
|
419
|
-
* }
|
|
420
|
-
*/ function constructFrom(date, value) {
|
|
421
|
-
if (typeof date === "function") return date(value);
|
|
422
|
-
if (date && typeof date === "object" && constructFromSymbol in date) return date[constructFromSymbol](value);
|
|
423
|
-
if (date instanceof Date) return new date.constructor(value);
|
|
424
|
-
return new Date(value);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* @name toDate
|
|
429
|
-
* @category Common Helpers
|
|
430
|
-
* @summary Convert the given argument to an instance of Date.
|
|
431
|
-
*
|
|
432
|
-
* @description
|
|
433
|
-
* Convert the given argument to an instance of Date.
|
|
434
|
-
*
|
|
435
|
-
* If the argument is an instance of Date, the function returns its clone.
|
|
436
|
-
*
|
|
437
|
-
* If the argument is a number, it is treated as a timestamp.
|
|
438
|
-
*
|
|
439
|
-
* If the argument is none of the above, the function returns Invalid Date.
|
|
440
|
-
*
|
|
441
|
-
* Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
|
|
442
|
-
* enabling to transfer extra properties from the reference date to the new date.
|
|
443
|
-
* It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
|
|
444
|
-
* that accept a time zone as a constructor argument.
|
|
445
|
-
*
|
|
446
|
-
* **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
|
|
447
|
-
*
|
|
448
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
449
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
450
|
-
*
|
|
451
|
-
* @param argument - The value to convert
|
|
452
|
-
*
|
|
453
|
-
* @returns The parsed date in the local time zone
|
|
454
|
-
*
|
|
455
|
-
* @example
|
|
456
|
-
* // Clone the date:
|
|
457
|
-
* const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
|
|
458
|
-
* //=> Tue Feb 11 2014 11:30:30
|
|
459
|
-
*
|
|
460
|
-
* @example
|
|
461
|
-
* // Convert the timestamp to date:
|
|
462
|
-
* const result = toDate(1392098430000)
|
|
463
|
-
* //=> Tue Feb 11 2014 11:30:30
|
|
464
|
-
*/ function toDate(argument, context) {
|
|
465
|
-
// [TODO] Get rid of `toDate` or `constructFrom`?
|
|
466
|
-
return constructFrom(context || argument, argument);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* The {@link addDays} function options.
|
|
471
|
-
*/ /**
|
|
472
|
-
* @name addDays
|
|
473
|
-
* @category Day Helpers
|
|
474
|
-
* @summary Add the specified number of days to the given date.
|
|
475
|
-
*
|
|
476
|
-
* @description
|
|
477
|
-
* Add the specified number of days to the given date.
|
|
478
|
-
*
|
|
479
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
480
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
481
|
-
*
|
|
482
|
-
* @param date - The date to be changed
|
|
483
|
-
* @param amount - The amount of days to be added.
|
|
484
|
-
* @param options - An object with options
|
|
485
|
-
*
|
|
486
|
-
* @returns The new date with the days added
|
|
487
|
-
*
|
|
488
|
-
* @example
|
|
489
|
-
* // Add 10 days to 1 September 2014:
|
|
490
|
-
* const result = addDays(new Date(2014, 8, 1), 10)
|
|
491
|
-
* //=> Thu Sep 11 2014 00:00:00
|
|
492
|
-
*/ function addDays(date, amount, options) {
|
|
493
|
-
const _date = toDate(date, options?.in);
|
|
494
|
-
if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
|
|
495
|
-
// If 0 days, no-op to avoid changing times in the hour before end of DST
|
|
496
|
-
if (!amount) return _date;
|
|
497
|
-
_date.setDate(_date.getDate() + amount);
|
|
498
|
-
return _date;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
350
|
/**
|
|
502
351
|
* The {@link addMonths} function options.
|
|
503
352
|
*/ /**
|
|
@@ -561,252 +410,6 @@ class TZDate extends TZDateMini {
|
|
|
561
410
|
}
|
|
562
411
|
}
|
|
563
412
|
|
|
564
|
-
let defaultOptions = {};
|
|
565
|
-
function getDefaultOptions() {
|
|
566
|
-
return defaultOptions;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* The {@link startOfWeek} function options.
|
|
571
|
-
*/ /**
|
|
572
|
-
* @name startOfWeek
|
|
573
|
-
* @category Week Helpers
|
|
574
|
-
* @summary Return the start of a week for the given date.
|
|
575
|
-
*
|
|
576
|
-
* @description
|
|
577
|
-
* Return the start of a week for the given date.
|
|
578
|
-
* The result will be in the local timezone.
|
|
579
|
-
*
|
|
580
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
581
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
582
|
-
*
|
|
583
|
-
* @param date - The original date
|
|
584
|
-
* @param options - An object with options
|
|
585
|
-
*
|
|
586
|
-
* @returns The start of a week
|
|
587
|
-
*
|
|
588
|
-
* @example
|
|
589
|
-
* // The start of a week for 2 September 2014 11:55:00:
|
|
590
|
-
* const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
|
|
591
|
-
* //=> Sun Aug 31 2014 00:00:00
|
|
592
|
-
*
|
|
593
|
-
* @example
|
|
594
|
-
* // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
|
|
595
|
-
* const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
|
|
596
|
-
* //=> Mon Sep 01 2014 00:00:00
|
|
597
|
-
*/ function startOfWeek(date, options) {
|
|
598
|
-
const defaultOptions = getDefaultOptions();
|
|
599
|
-
const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions.weekStartsOn ?? defaultOptions.locale?.options?.weekStartsOn ?? 0;
|
|
600
|
-
const _date = toDate(date, options?.in);
|
|
601
|
-
const day = _date.getDay();
|
|
602
|
-
const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
|
603
|
-
_date.setDate(_date.getDate() - diff);
|
|
604
|
-
_date.setHours(0, 0, 0, 0);
|
|
605
|
-
return _date;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* The {@link startOfISOWeek} function options.
|
|
610
|
-
*/ /**
|
|
611
|
-
* @name startOfISOWeek
|
|
612
|
-
* @category ISO Week Helpers
|
|
613
|
-
* @summary Return the start of an ISO week for the given date.
|
|
614
|
-
*
|
|
615
|
-
* @description
|
|
616
|
-
* Return the start of an ISO week for the given date.
|
|
617
|
-
* The result will be in the local timezone.
|
|
618
|
-
*
|
|
619
|
-
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
|
620
|
-
*
|
|
621
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
622
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
623
|
-
*
|
|
624
|
-
* @param date - The original date
|
|
625
|
-
* @param options - An object with options
|
|
626
|
-
*
|
|
627
|
-
* @returns The start of an ISO week
|
|
628
|
-
*
|
|
629
|
-
* @example
|
|
630
|
-
* // The start of an ISO week for 2 September 2014 11:55:00:
|
|
631
|
-
* const result = startOfISOWeek(new Date(2014, 8, 2, 11, 55, 0))
|
|
632
|
-
* //=> Mon Sep 01 2014 00:00:00
|
|
633
|
-
*/ function startOfISOWeek(date, options) {
|
|
634
|
-
return startOfWeek(date, {
|
|
635
|
-
...options,
|
|
636
|
-
weekStartsOn: 1
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
/**
|
|
641
|
-
* The {@link getISOWeekYear} function options.
|
|
642
|
-
*/ /**
|
|
643
|
-
* @name getISOWeekYear
|
|
644
|
-
* @category ISO Week-Numbering Year Helpers
|
|
645
|
-
* @summary Get the ISO week-numbering year of the given date.
|
|
646
|
-
*
|
|
647
|
-
* @description
|
|
648
|
-
* Get the ISO week-numbering year of the given date,
|
|
649
|
-
* which always starts 3 days before the year's first Thursday.
|
|
650
|
-
*
|
|
651
|
-
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
|
652
|
-
*
|
|
653
|
-
* @param date - The given date
|
|
654
|
-
*
|
|
655
|
-
* @returns The ISO week-numbering year
|
|
656
|
-
*
|
|
657
|
-
* @example
|
|
658
|
-
* // Which ISO-week numbering year is 2 January 2005?
|
|
659
|
-
* const result = getISOWeekYear(new Date(2005, 0, 2))
|
|
660
|
-
* //=> 2004
|
|
661
|
-
*/ function getISOWeekYear(date, options) {
|
|
662
|
-
const _date = toDate(date, options?.in);
|
|
663
|
-
const year = _date.getFullYear();
|
|
664
|
-
const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
|
|
665
|
-
fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
|
|
666
|
-
fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
|
|
667
|
-
const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
|
|
668
|
-
const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
|
|
669
|
-
fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
|
|
670
|
-
fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
|
|
671
|
-
const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
|
|
672
|
-
if (_date.getTime() >= startOfNextYear.getTime()) {
|
|
673
|
-
return year + 1;
|
|
674
|
-
} else if (_date.getTime() >= startOfThisYear.getTime()) {
|
|
675
|
-
return year;
|
|
676
|
-
} else {
|
|
677
|
-
return year - 1;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
|
|
683
|
-
* They usually appear for dates that denote time before the timezones were introduced
|
|
684
|
-
* (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
|
|
685
|
-
* and GMT+01:00:00 after that date)
|
|
686
|
-
*
|
|
687
|
-
* Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
|
|
688
|
-
* which would lead to incorrect calculations.
|
|
689
|
-
*
|
|
690
|
-
* This function returns the timezone offset in milliseconds that takes seconds in account.
|
|
691
|
-
*/ function getTimezoneOffsetInMilliseconds(date) {
|
|
692
|
-
const _date = toDate(date);
|
|
693
|
-
const utcDate = new Date(Date.UTC(_date.getFullYear(), _date.getMonth(), _date.getDate(), _date.getHours(), _date.getMinutes(), _date.getSeconds(), _date.getMilliseconds()));
|
|
694
|
-
utcDate.setUTCFullYear(_date.getFullYear());
|
|
695
|
-
return +date - +utcDate;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
function normalizeDates(context, ...dates) {
|
|
699
|
-
const normalize = constructFrom.bind(null, dates.find((date)=>typeof date === "object"));
|
|
700
|
-
return dates.map(normalize);
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/**
|
|
704
|
-
* The {@link startOfDay} function options.
|
|
705
|
-
*/ /**
|
|
706
|
-
* @name startOfDay
|
|
707
|
-
* @category Day Helpers
|
|
708
|
-
* @summary Return the start of a day for the given date.
|
|
709
|
-
*
|
|
710
|
-
* @description
|
|
711
|
-
* Return the start of a day for the given date.
|
|
712
|
-
* The result will be in the local timezone.
|
|
713
|
-
*
|
|
714
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
715
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
716
|
-
*
|
|
717
|
-
* @param date - The original date
|
|
718
|
-
* @param options - The options
|
|
719
|
-
*
|
|
720
|
-
* @returns The start of a day
|
|
721
|
-
*
|
|
722
|
-
* @example
|
|
723
|
-
* // The start of a day for 2 September 2014 11:55:00:
|
|
724
|
-
* const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
|
|
725
|
-
* //=> Tue Sep 02 2014 00:00:00
|
|
726
|
-
*/ function startOfDay(date, options) {
|
|
727
|
-
const _date = toDate(date, options?.in);
|
|
728
|
-
_date.setHours(0, 0, 0, 0);
|
|
729
|
-
return _date;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
/**
|
|
733
|
-
* The {@link differenceInCalendarDays} function options.
|
|
734
|
-
*/ /**
|
|
735
|
-
* @name differenceInCalendarDays
|
|
736
|
-
* @category Day Helpers
|
|
737
|
-
* @summary Get the number of calendar days between the given dates.
|
|
738
|
-
*
|
|
739
|
-
* @description
|
|
740
|
-
* Get the number of calendar days between the given dates. This means that the times are removed
|
|
741
|
-
* from the dates and then the difference in days is calculated.
|
|
742
|
-
*
|
|
743
|
-
* @param laterDate - The later date
|
|
744
|
-
* @param earlierDate - The earlier date
|
|
745
|
-
* @param options - The options object
|
|
746
|
-
*
|
|
747
|
-
* @returns The number of calendar days
|
|
748
|
-
*
|
|
749
|
-
* @example
|
|
750
|
-
* // How many calendar days are between
|
|
751
|
-
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
|
752
|
-
* const result = differenceInCalendarDays(
|
|
753
|
-
* new Date(2012, 6, 2, 0, 0),
|
|
754
|
-
* new Date(2011, 6, 2, 23, 0)
|
|
755
|
-
* )
|
|
756
|
-
* //=> 366
|
|
757
|
-
* // How many calendar days are between
|
|
758
|
-
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
|
759
|
-
* const result = differenceInCalendarDays(
|
|
760
|
-
* new Date(2011, 6, 3, 0, 1),
|
|
761
|
-
* new Date(2011, 6, 2, 23, 59)
|
|
762
|
-
* )
|
|
763
|
-
* //=> 1
|
|
764
|
-
*/ function differenceInCalendarDays(laterDate, earlierDate, options) {
|
|
765
|
-
const [laterDate_, earlierDate_] = normalizeDates(options?.in, laterDate, earlierDate);
|
|
766
|
-
const laterStartOfDay = startOfDay(laterDate_);
|
|
767
|
-
const earlierStartOfDay = startOfDay(earlierDate_);
|
|
768
|
-
const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
|
|
769
|
-
const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
|
|
770
|
-
// Round the number of days to the nearest integer because the number of
|
|
771
|
-
// milliseconds in a day is not constant (e.g. it's different in the week of
|
|
772
|
-
// the daylight saving time clock shift).
|
|
773
|
-
return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
/**
|
|
777
|
-
* The {@link startOfISOWeekYear} function options.
|
|
778
|
-
*/ /**
|
|
779
|
-
* @name startOfISOWeekYear
|
|
780
|
-
* @category ISO Week-Numbering Year Helpers
|
|
781
|
-
* @summary Return the start of an ISO week-numbering year for the given date.
|
|
782
|
-
*
|
|
783
|
-
* @description
|
|
784
|
-
* Return the start of an ISO week-numbering year,
|
|
785
|
-
* which always starts 3 days before the year's first Thursday.
|
|
786
|
-
* The result will be in the local timezone.
|
|
787
|
-
*
|
|
788
|
-
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
|
789
|
-
*
|
|
790
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
791
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
792
|
-
*
|
|
793
|
-
* @param date - The original date
|
|
794
|
-
* @param options - An object with options
|
|
795
|
-
*
|
|
796
|
-
* @returns The start of an ISO week-numbering year
|
|
797
|
-
*
|
|
798
|
-
* @example
|
|
799
|
-
* // The start of an ISO week-numbering year for 2 July 2005:
|
|
800
|
-
* const result = startOfISOWeekYear(new Date(2005, 6, 2))
|
|
801
|
-
* //=> Mon Jan 03 2005 00:00:00
|
|
802
|
-
*/ function startOfISOWeekYear(date, options) {
|
|
803
|
-
const year = getISOWeekYear(date, options);
|
|
804
|
-
const fourthOfJanuary = constructFrom(date, 0);
|
|
805
|
-
fourthOfJanuary.setFullYear(year, 0, 4);
|
|
806
|
-
fourthOfJanuary.setHours(0, 0, 0, 0);
|
|
807
|
-
return startOfISOWeek(fourthOfJanuary);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
413
|
/**
|
|
811
414
|
* The {@link addWeeks} function options.
|
|
812
415
|
*/ /**
|
|
@@ -972,75 +575,6 @@ function normalizeDates(context, ...dates) {
|
|
|
972
575
|
return +startOfDay(dateLeft_) === +startOfDay(dateRight_);
|
|
973
576
|
}
|
|
974
577
|
|
|
975
|
-
/**
|
|
976
|
-
* @name isDate
|
|
977
|
-
* @category Common Helpers
|
|
978
|
-
* @summary Is the given value a date?
|
|
979
|
-
*
|
|
980
|
-
* @description
|
|
981
|
-
* Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
|
|
982
|
-
*
|
|
983
|
-
* @param value - The value to check
|
|
984
|
-
*
|
|
985
|
-
* @returns True if the given value is a date
|
|
986
|
-
*
|
|
987
|
-
* @example
|
|
988
|
-
* // For a valid date:
|
|
989
|
-
* const result = isDate(new Date())
|
|
990
|
-
* //=> true
|
|
991
|
-
*
|
|
992
|
-
* @example
|
|
993
|
-
* // For an invalid date:
|
|
994
|
-
* const result = isDate(new Date(NaN))
|
|
995
|
-
* //=> true
|
|
996
|
-
*
|
|
997
|
-
* @example
|
|
998
|
-
* // For some value:
|
|
999
|
-
* const result = isDate('2014-02-31')
|
|
1000
|
-
* //=> false
|
|
1001
|
-
*
|
|
1002
|
-
* @example
|
|
1003
|
-
* // For an object:
|
|
1004
|
-
* const result = isDate({})
|
|
1005
|
-
* //=> false
|
|
1006
|
-
*/ function isDate(value) {
|
|
1007
|
-
return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
/**
|
|
1011
|
-
* @name isValid
|
|
1012
|
-
* @category Common Helpers
|
|
1013
|
-
* @summary Is the given date valid?
|
|
1014
|
-
*
|
|
1015
|
-
* @description
|
|
1016
|
-
* Returns false if argument is Invalid Date and true otherwise.
|
|
1017
|
-
* Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate)
|
|
1018
|
-
* Invalid Date is a Date, whose time value is NaN.
|
|
1019
|
-
*
|
|
1020
|
-
* Time value of Date: http://es5.github.io/#x15.9.1.1
|
|
1021
|
-
*
|
|
1022
|
-
* @param date - The date to check
|
|
1023
|
-
*
|
|
1024
|
-
* @returns The date is valid
|
|
1025
|
-
*
|
|
1026
|
-
* @example
|
|
1027
|
-
* // For the valid date:
|
|
1028
|
-
* const result = isValid(new Date(2014, 1, 31))
|
|
1029
|
-
* //=> true
|
|
1030
|
-
*
|
|
1031
|
-
* @example
|
|
1032
|
-
* // For the value, convertible into a date:
|
|
1033
|
-
* const result = isValid(1393804800000)
|
|
1034
|
-
* //=> true
|
|
1035
|
-
*
|
|
1036
|
-
* @example
|
|
1037
|
-
* // For the invalid date:
|
|
1038
|
-
* const result = isValid(new Date(''))
|
|
1039
|
-
* //=> false
|
|
1040
|
-
*/ function isValid(date) {
|
|
1041
|
-
return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
578
|
/**
|
|
1045
579
|
* The {@link differenceInCalendarMonths} function options.
|
|
1046
580
|
*/ /**
|
|
@@ -1223,36 +757,6 @@ function normalizeInterval(context, interval) {
|
|
|
1223
757
|
return _date;
|
|
1224
758
|
}
|
|
1225
759
|
|
|
1226
|
-
/**
|
|
1227
|
-
* The {@link startOfYear} function options.
|
|
1228
|
-
*/ /**
|
|
1229
|
-
* @name startOfYear
|
|
1230
|
-
* @category Year Helpers
|
|
1231
|
-
* @summary Return the start of a year for the given date.
|
|
1232
|
-
*
|
|
1233
|
-
* @description
|
|
1234
|
-
* Return the start of a year for the given date.
|
|
1235
|
-
* The result will be in the local timezone.
|
|
1236
|
-
*
|
|
1237
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
1238
|
-
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
1239
|
-
*
|
|
1240
|
-
* @param date - The original date
|
|
1241
|
-
* @param options - The options
|
|
1242
|
-
*
|
|
1243
|
-
* @returns The start of a year
|
|
1244
|
-
*
|
|
1245
|
-
* @example
|
|
1246
|
-
* // The start of a year for 2 September 2014 11:55:00:
|
|
1247
|
-
* const result = startOfYear(new Date(2014, 8, 2, 11, 55, 00))
|
|
1248
|
-
* //=> Wed Jan 01 2014 00:00:00
|
|
1249
|
-
*/ function startOfYear(date, options) {
|
|
1250
|
-
const date_ = toDate(date, options?.in);
|
|
1251
|
-
date_.setFullYear(date_.getFullYear(), 0, 1);
|
|
1252
|
-
date_.setHours(0, 0, 0, 0);
|
|
1253
|
-
return date_;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
760
|
/**
|
|
1257
761
|
* The {@link eachYearOfInterval} function options.
|
|
1258
762
|
*/ /**
|
|
@@ -1375,2143 +879,6 @@ function normalizeInterval(context, interval) {
|
|
|
1375
879
|
});
|
|
1376
880
|
}
|
|
1377
881
|
|
|
1378
|
-
const formatDistanceLocale = {
|
|
1379
|
-
lessThanXSeconds: {
|
|
1380
|
-
one: "less than a second",
|
|
1381
|
-
other: "less than {{count}} seconds"
|
|
1382
|
-
},
|
|
1383
|
-
xSeconds: {
|
|
1384
|
-
one: "1 second",
|
|
1385
|
-
other: "{{count}} seconds"
|
|
1386
|
-
},
|
|
1387
|
-
halfAMinute: "half a minute",
|
|
1388
|
-
lessThanXMinutes: {
|
|
1389
|
-
one: "less than a minute",
|
|
1390
|
-
other: "less than {{count}} minutes"
|
|
1391
|
-
},
|
|
1392
|
-
xMinutes: {
|
|
1393
|
-
one: "1 minute",
|
|
1394
|
-
other: "{{count}} minutes"
|
|
1395
|
-
},
|
|
1396
|
-
aboutXHours: {
|
|
1397
|
-
one: "about 1 hour",
|
|
1398
|
-
other: "about {{count}} hours"
|
|
1399
|
-
},
|
|
1400
|
-
xHours: {
|
|
1401
|
-
one: "1 hour",
|
|
1402
|
-
other: "{{count}} hours"
|
|
1403
|
-
},
|
|
1404
|
-
xDays: {
|
|
1405
|
-
one: "1 day",
|
|
1406
|
-
other: "{{count}} days"
|
|
1407
|
-
},
|
|
1408
|
-
aboutXWeeks: {
|
|
1409
|
-
one: "about 1 week",
|
|
1410
|
-
other: "about {{count}} weeks"
|
|
1411
|
-
},
|
|
1412
|
-
xWeeks: {
|
|
1413
|
-
one: "1 week",
|
|
1414
|
-
other: "{{count}} weeks"
|
|
1415
|
-
},
|
|
1416
|
-
aboutXMonths: {
|
|
1417
|
-
one: "about 1 month",
|
|
1418
|
-
other: "about {{count}} months"
|
|
1419
|
-
},
|
|
1420
|
-
xMonths: {
|
|
1421
|
-
one: "1 month",
|
|
1422
|
-
other: "{{count}} months"
|
|
1423
|
-
},
|
|
1424
|
-
aboutXYears: {
|
|
1425
|
-
one: "about 1 year",
|
|
1426
|
-
other: "about {{count}} years"
|
|
1427
|
-
},
|
|
1428
|
-
xYears: {
|
|
1429
|
-
one: "1 year",
|
|
1430
|
-
other: "{{count}} years"
|
|
1431
|
-
},
|
|
1432
|
-
overXYears: {
|
|
1433
|
-
one: "over 1 year",
|
|
1434
|
-
other: "over {{count}} years"
|
|
1435
|
-
},
|
|
1436
|
-
almostXYears: {
|
|
1437
|
-
one: "almost 1 year",
|
|
1438
|
-
other: "almost {{count}} years"
|
|
1439
|
-
}
|
|
1440
|
-
};
|
|
1441
|
-
const formatDistance = (token, count, options)=>{
|
|
1442
|
-
let result;
|
|
1443
|
-
const tokenValue = formatDistanceLocale[token];
|
|
1444
|
-
if (typeof tokenValue === "string") {
|
|
1445
|
-
result = tokenValue;
|
|
1446
|
-
} else if (count === 1) {
|
|
1447
|
-
result = tokenValue.one;
|
|
1448
|
-
} else {
|
|
1449
|
-
result = tokenValue.other.replace("{{count}}", count.toString());
|
|
1450
|
-
}
|
|
1451
|
-
if (options?.addSuffix) {
|
|
1452
|
-
if (options.comparison && options.comparison > 0) {
|
|
1453
|
-
return "in " + result;
|
|
1454
|
-
} else {
|
|
1455
|
-
return result + " ago";
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
return result;
|
|
1459
|
-
};
|
|
1460
|
-
|
|
1461
|
-
function buildFormatLongFn(args) {
|
|
1462
|
-
return (options = {})=>{
|
|
1463
|
-
// TODO: Remove String()
|
|
1464
|
-
const width = options.width ? String(options.width) : args.defaultWidth;
|
|
1465
|
-
const format = args.formats[width] || args.formats[args.defaultWidth];
|
|
1466
|
-
return format;
|
|
1467
|
-
};
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
const dateFormats = {
|
|
1471
|
-
full: "EEEE, MMMM do, y",
|
|
1472
|
-
long: "MMMM do, y",
|
|
1473
|
-
medium: "MMM d, y",
|
|
1474
|
-
short: "MM/dd/yyyy"
|
|
1475
|
-
};
|
|
1476
|
-
const timeFormats = {
|
|
1477
|
-
full: "h:mm:ss a zzzz",
|
|
1478
|
-
long: "h:mm:ss a z",
|
|
1479
|
-
medium: "h:mm:ss a",
|
|
1480
|
-
short: "h:mm a"
|
|
1481
|
-
};
|
|
1482
|
-
const dateTimeFormats = {
|
|
1483
|
-
full: "{{date}} 'at' {{time}}",
|
|
1484
|
-
long: "{{date}} 'at' {{time}}",
|
|
1485
|
-
medium: "{{date}}, {{time}}",
|
|
1486
|
-
short: "{{date}}, {{time}}"
|
|
1487
|
-
};
|
|
1488
|
-
const formatLong = {
|
|
1489
|
-
date: buildFormatLongFn({
|
|
1490
|
-
formats: dateFormats,
|
|
1491
|
-
defaultWidth: "full"
|
|
1492
|
-
}),
|
|
1493
|
-
time: buildFormatLongFn({
|
|
1494
|
-
formats: timeFormats,
|
|
1495
|
-
defaultWidth: "full"
|
|
1496
|
-
}),
|
|
1497
|
-
dateTime: buildFormatLongFn({
|
|
1498
|
-
formats: dateTimeFormats,
|
|
1499
|
-
defaultWidth: "full"
|
|
1500
|
-
})
|
|
1501
|
-
};
|
|
1502
|
-
|
|
1503
|
-
const formatRelativeLocale = {
|
|
1504
|
-
lastWeek: "'last' eeee 'at' p",
|
|
1505
|
-
yesterday: "'yesterday at' p",
|
|
1506
|
-
today: "'today at' p",
|
|
1507
|
-
tomorrow: "'tomorrow at' p",
|
|
1508
|
-
nextWeek: "eeee 'at' p",
|
|
1509
|
-
other: "P"
|
|
1510
|
-
};
|
|
1511
|
-
const formatRelative = (token, _date, _baseDate, _options)=>formatRelativeLocale[token];
|
|
1512
|
-
|
|
1513
|
-
/**
|
|
1514
|
-
* The localize function argument callback which allows to convert raw value to
|
|
1515
|
-
* the actual type.
|
|
1516
|
-
*
|
|
1517
|
-
* @param value - The value to convert
|
|
1518
|
-
*
|
|
1519
|
-
* @returns The converted value
|
|
1520
|
-
*/ /**
|
|
1521
|
-
* The map of localized values for each width.
|
|
1522
|
-
*/ /**
|
|
1523
|
-
* The index type of the locale unit value. It types conversion of units of
|
|
1524
|
-
* values that don't start at 0 (i.e. quarters).
|
|
1525
|
-
*/ /**
|
|
1526
|
-
* Converts the unit value to the tuple of values.
|
|
1527
|
-
*/ /**
|
|
1528
|
-
* The tuple of localized era values. The first element represents BC,
|
|
1529
|
-
* the second element represents AD.
|
|
1530
|
-
*/ /**
|
|
1531
|
-
* The tuple of localized quarter values. The first element represents Q1.
|
|
1532
|
-
*/ /**
|
|
1533
|
-
* The tuple of localized day values. The first element represents Sunday.
|
|
1534
|
-
*/ /**
|
|
1535
|
-
* The tuple of localized month values. The first element represents January.
|
|
1536
|
-
*/ function buildLocalizeFn(args) {
|
|
1537
|
-
return (value, options)=>{
|
|
1538
|
-
const context = options?.context ? String(options.context) : "standalone";
|
|
1539
|
-
let valuesArray;
|
|
1540
|
-
if (context === "formatting" && args.formattingValues) {
|
|
1541
|
-
const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
|
|
1542
|
-
const width = options?.width ? String(options.width) : defaultWidth;
|
|
1543
|
-
valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
|
|
1544
|
-
} else {
|
|
1545
|
-
const defaultWidth = args.defaultWidth;
|
|
1546
|
-
const width = options?.width ? String(options.width) : args.defaultWidth;
|
|
1547
|
-
valuesArray = args.values[width] || args.values[defaultWidth];
|
|
1548
|
-
}
|
|
1549
|
-
const index = args.argumentCallback ? args.argumentCallback(value) : value;
|
|
1550
|
-
// @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
|
|
1551
|
-
return valuesArray[index];
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
const eraValues = {
|
|
1556
|
-
narrow: [
|
|
1557
|
-
"B",
|
|
1558
|
-
"A"
|
|
1559
|
-
],
|
|
1560
|
-
abbreviated: [
|
|
1561
|
-
"BC",
|
|
1562
|
-
"AD"
|
|
1563
|
-
],
|
|
1564
|
-
wide: [
|
|
1565
|
-
"Before Christ",
|
|
1566
|
-
"Anno Domini"
|
|
1567
|
-
]
|
|
1568
|
-
};
|
|
1569
|
-
const quarterValues = {
|
|
1570
|
-
narrow: [
|
|
1571
|
-
"1",
|
|
1572
|
-
"2",
|
|
1573
|
-
"3",
|
|
1574
|
-
"4"
|
|
1575
|
-
],
|
|
1576
|
-
abbreviated: [
|
|
1577
|
-
"Q1",
|
|
1578
|
-
"Q2",
|
|
1579
|
-
"Q3",
|
|
1580
|
-
"Q4"
|
|
1581
|
-
],
|
|
1582
|
-
wide: [
|
|
1583
|
-
"1st quarter",
|
|
1584
|
-
"2nd quarter",
|
|
1585
|
-
"3rd quarter",
|
|
1586
|
-
"4th quarter"
|
|
1587
|
-
]
|
|
1588
|
-
};
|
|
1589
|
-
// Note: in English, the names of days of the week and months are capitalized.
|
|
1590
|
-
// If you are making a new locale based on this one, check if the same is true for the language you're working on.
|
|
1591
|
-
// Generally, formatted dates should look like they are in the middle of a sentence,
|
|
1592
|
-
// e.g. in Spanish language the weekdays and months should be in the lowercase.
|
|
1593
|
-
const monthValues = {
|
|
1594
|
-
narrow: [
|
|
1595
|
-
"J",
|
|
1596
|
-
"F",
|
|
1597
|
-
"M",
|
|
1598
|
-
"A",
|
|
1599
|
-
"M",
|
|
1600
|
-
"J",
|
|
1601
|
-
"J",
|
|
1602
|
-
"A",
|
|
1603
|
-
"S",
|
|
1604
|
-
"O",
|
|
1605
|
-
"N",
|
|
1606
|
-
"D"
|
|
1607
|
-
],
|
|
1608
|
-
abbreviated: [
|
|
1609
|
-
"Jan",
|
|
1610
|
-
"Feb",
|
|
1611
|
-
"Mar",
|
|
1612
|
-
"Apr",
|
|
1613
|
-
"May",
|
|
1614
|
-
"Jun",
|
|
1615
|
-
"Jul",
|
|
1616
|
-
"Aug",
|
|
1617
|
-
"Sep",
|
|
1618
|
-
"Oct",
|
|
1619
|
-
"Nov",
|
|
1620
|
-
"Dec"
|
|
1621
|
-
],
|
|
1622
|
-
wide: [
|
|
1623
|
-
"January",
|
|
1624
|
-
"February",
|
|
1625
|
-
"March",
|
|
1626
|
-
"April",
|
|
1627
|
-
"May",
|
|
1628
|
-
"June",
|
|
1629
|
-
"July",
|
|
1630
|
-
"August",
|
|
1631
|
-
"September",
|
|
1632
|
-
"October",
|
|
1633
|
-
"November",
|
|
1634
|
-
"December"
|
|
1635
|
-
]
|
|
1636
|
-
};
|
|
1637
|
-
const dayValues = {
|
|
1638
|
-
narrow: [
|
|
1639
|
-
"S",
|
|
1640
|
-
"M",
|
|
1641
|
-
"T",
|
|
1642
|
-
"W",
|
|
1643
|
-
"T",
|
|
1644
|
-
"F",
|
|
1645
|
-
"S"
|
|
1646
|
-
],
|
|
1647
|
-
short: [
|
|
1648
|
-
"Su",
|
|
1649
|
-
"Mo",
|
|
1650
|
-
"Tu",
|
|
1651
|
-
"We",
|
|
1652
|
-
"Th",
|
|
1653
|
-
"Fr",
|
|
1654
|
-
"Sa"
|
|
1655
|
-
],
|
|
1656
|
-
abbreviated: [
|
|
1657
|
-
"Sun",
|
|
1658
|
-
"Mon",
|
|
1659
|
-
"Tue",
|
|
1660
|
-
"Wed",
|
|
1661
|
-
"Thu",
|
|
1662
|
-
"Fri",
|
|
1663
|
-
"Sat"
|
|
1664
|
-
],
|
|
1665
|
-
wide: [
|
|
1666
|
-
"Sunday",
|
|
1667
|
-
"Monday",
|
|
1668
|
-
"Tuesday",
|
|
1669
|
-
"Wednesday",
|
|
1670
|
-
"Thursday",
|
|
1671
|
-
"Friday",
|
|
1672
|
-
"Saturday"
|
|
1673
|
-
]
|
|
1674
|
-
};
|
|
1675
|
-
const dayPeriodValues = {
|
|
1676
|
-
narrow: {
|
|
1677
|
-
am: "a",
|
|
1678
|
-
pm: "p",
|
|
1679
|
-
midnight: "mi",
|
|
1680
|
-
noon: "n",
|
|
1681
|
-
morning: "morning",
|
|
1682
|
-
afternoon: "afternoon",
|
|
1683
|
-
evening: "evening",
|
|
1684
|
-
night: "night"
|
|
1685
|
-
},
|
|
1686
|
-
abbreviated: {
|
|
1687
|
-
am: "AM",
|
|
1688
|
-
pm: "PM",
|
|
1689
|
-
midnight: "midnight",
|
|
1690
|
-
noon: "noon",
|
|
1691
|
-
morning: "morning",
|
|
1692
|
-
afternoon: "afternoon",
|
|
1693
|
-
evening: "evening",
|
|
1694
|
-
night: "night"
|
|
1695
|
-
},
|
|
1696
|
-
wide: {
|
|
1697
|
-
am: "a.m.",
|
|
1698
|
-
pm: "p.m.",
|
|
1699
|
-
midnight: "midnight",
|
|
1700
|
-
noon: "noon",
|
|
1701
|
-
morning: "morning",
|
|
1702
|
-
afternoon: "afternoon",
|
|
1703
|
-
evening: "evening",
|
|
1704
|
-
night: "night"
|
|
1705
|
-
}
|
|
1706
|
-
};
|
|
1707
|
-
const formattingDayPeriodValues = {
|
|
1708
|
-
narrow: {
|
|
1709
|
-
am: "a",
|
|
1710
|
-
pm: "p",
|
|
1711
|
-
midnight: "mi",
|
|
1712
|
-
noon: "n",
|
|
1713
|
-
morning: "in the morning",
|
|
1714
|
-
afternoon: "in the afternoon",
|
|
1715
|
-
evening: "in the evening",
|
|
1716
|
-
night: "at night"
|
|
1717
|
-
},
|
|
1718
|
-
abbreviated: {
|
|
1719
|
-
am: "AM",
|
|
1720
|
-
pm: "PM",
|
|
1721
|
-
midnight: "midnight",
|
|
1722
|
-
noon: "noon",
|
|
1723
|
-
morning: "in the morning",
|
|
1724
|
-
afternoon: "in the afternoon",
|
|
1725
|
-
evening: "in the evening",
|
|
1726
|
-
night: "at night"
|
|
1727
|
-
},
|
|
1728
|
-
wide: {
|
|
1729
|
-
am: "a.m.",
|
|
1730
|
-
pm: "p.m.",
|
|
1731
|
-
midnight: "midnight",
|
|
1732
|
-
noon: "noon",
|
|
1733
|
-
morning: "in the morning",
|
|
1734
|
-
afternoon: "in the afternoon",
|
|
1735
|
-
evening: "in the evening",
|
|
1736
|
-
night: "at night"
|
|
1737
|
-
}
|
|
1738
|
-
};
|
|
1739
|
-
const ordinalNumber = (dirtyNumber, _options)=>{
|
|
1740
|
-
const number = Number(dirtyNumber);
|
|
1741
|
-
// If ordinal numbers depend on context, for example,
|
|
1742
|
-
// if they are different for different grammatical genders,
|
|
1743
|
-
// use `options.unit`.
|
|
1744
|
-
//
|
|
1745
|
-
// `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
|
|
1746
|
-
// 'day', 'hour', 'minute', 'second'.
|
|
1747
|
-
const rem100 = number % 100;
|
|
1748
|
-
if (rem100 > 20 || rem100 < 10) {
|
|
1749
|
-
switch(rem100 % 10){
|
|
1750
|
-
case 1:
|
|
1751
|
-
return number + "st";
|
|
1752
|
-
case 2:
|
|
1753
|
-
return number + "nd";
|
|
1754
|
-
case 3:
|
|
1755
|
-
return number + "rd";
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
return number + "th";
|
|
1759
|
-
};
|
|
1760
|
-
const localize = {
|
|
1761
|
-
ordinalNumber,
|
|
1762
|
-
era: buildLocalizeFn({
|
|
1763
|
-
values: eraValues,
|
|
1764
|
-
defaultWidth: "wide"
|
|
1765
|
-
}),
|
|
1766
|
-
quarter: buildLocalizeFn({
|
|
1767
|
-
values: quarterValues,
|
|
1768
|
-
defaultWidth: "wide",
|
|
1769
|
-
argumentCallback: (quarter)=>quarter - 1
|
|
1770
|
-
}),
|
|
1771
|
-
month: buildLocalizeFn({
|
|
1772
|
-
values: monthValues,
|
|
1773
|
-
defaultWidth: "wide"
|
|
1774
|
-
}),
|
|
1775
|
-
day: buildLocalizeFn({
|
|
1776
|
-
values: dayValues,
|
|
1777
|
-
defaultWidth: "wide"
|
|
1778
|
-
}),
|
|
1779
|
-
dayPeriod: buildLocalizeFn({
|
|
1780
|
-
values: dayPeriodValues,
|
|
1781
|
-
defaultWidth: "wide",
|
|
1782
|
-
formattingValues: formattingDayPeriodValues,
|
|
1783
|
-
defaultFormattingWidth: "wide"
|
|
1784
|
-
})
|
|
1785
|
-
};
|
|
1786
|
-
|
|
1787
|
-
function buildMatchFn(args) {
|
|
1788
|
-
return (string, options = {})=>{
|
|
1789
|
-
const width = options.width;
|
|
1790
|
-
const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
|
|
1791
|
-
const matchResult = string.match(matchPattern);
|
|
1792
|
-
if (!matchResult) {
|
|
1793
|
-
return null;
|
|
1794
|
-
}
|
|
1795
|
-
const matchedString = matchResult[0];
|
|
1796
|
-
const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
|
|
1797
|
-
const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern)=>pattern.test(matchedString)) : findKey(parsePatterns, (pattern)=>pattern.test(matchedString));
|
|
1798
|
-
let value;
|
|
1799
|
-
value = args.valueCallback ? args.valueCallback(key) : key;
|
|
1800
|
-
value = options.valueCallback ? options.valueCallback(value) : value;
|
|
1801
|
-
const rest = string.slice(matchedString.length);
|
|
1802
|
-
return {
|
|
1803
|
-
value,
|
|
1804
|
-
rest
|
|
1805
|
-
};
|
|
1806
|
-
};
|
|
1807
|
-
}
|
|
1808
|
-
function findKey(object, predicate) {
|
|
1809
|
-
for(const key in object){
|
|
1810
|
-
if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
|
|
1811
|
-
return key;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
return undefined;
|
|
1815
|
-
}
|
|
1816
|
-
function findIndex(array, predicate) {
|
|
1817
|
-
for(let key = 0; key < array.length; key++){
|
|
1818
|
-
if (predicate(array[key])) {
|
|
1819
|
-
return key;
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
return undefined;
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
function buildMatchPatternFn(args) {
|
|
1826
|
-
return (string, options = {})=>{
|
|
1827
|
-
const matchResult = string.match(args.matchPattern);
|
|
1828
|
-
if (!matchResult) return null;
|
|
1829
|
-
const matchedString = matchResult[0];
|
|
1830
|
-
const parseResult = string.match(args.parsePattern);
|
|
1831
|
-
if (!parseResult) return null;
|
|
1832
|
-
let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
|
|
1833
|
-
// [TODO] I challenge you to fix the type
|
|
1834
|
-
value = options.valueCallback ? options.valueCallback(value) : value;
|
|
1835
|
-
const rest = string.slice(matchedString.length);
|
|
1836
|
-
return {
|
|
1837
|
-
value,
|
|
1838
|
-
rest
|
|
1839
|
-
};
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
|
|
1844
|
-
const parseOrdinalNumberPattern = /\d+/i;
|
|
1845
|
-
const matchEraPatterns = {
|
|
1846
|
-
narrow: /^(b|a)/i,
|
|
1847
|
-
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
|
|
1848
|
-
wide: /^(before christ|before common era|anno domini|common era)/i
|
|
1849
|
-
};
|
|
1850
|
-
const parseEraPatterns = {
|
|
1851
|
-
any: [
|
|
1852
|
-
/^b/i,
|
|
1853
|
-
/^(a|c)/i
|
|
1854
|
-
]
|
|
1855
|
-
};
|
|
1856
|
-
const matchQuarterPatterns = {
|
|
1857
|
-
narrow: /^[1234]/i,
|
|
1858
|
-
abbreviated: /^q[1234]/i,
|
|
1859
|
-
wide: /^[1234](th|st|nd|rd)? quarter/i
|
|
1860
|
-
};
|
|
1861
|
-
const parseQuarterPatterns = {
|
|
1862
|
-
any: [
|
|
1863
|
-
/1/i,
|
|
1864
|
-
/2/i,
|
|
1865
|
-
/3/i,
|
|
1866
|
-
/4/i
|
|
1867
|
-
]
|
|
1868
|
-
};
|
|
1869
|
-
const matchMonthPatterns = {
|
|
1870
|
-
narrow: /^[jfmasond]/i,
|
|
1871
|
-
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
|
|
1872
|
-
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
|
|
1873
|
-
};
|
|
1874
|
-
const parseMonthPatterns = {
|
|
1875
|
-
narrow: [
|
|
1876
|
-
/^j/i,
|
|
1877
|
-
/^f/i,
|
|
1878
|
-
/^m/i,
|
|
1879
|
-
/^a/i,
|
|
1880
|
-
/^m/i,
|
|
1881
|
-
/^j/i,
|
|
1882
|
-
/^j/i,
|
|
1883
|
-
/^a/i,
|
|
1884
|
-
/^s/i,
|
|
1885
|
-
/^o/i,
|
|
1886
|
-
/^n/i,
|
|
1887
|
-
/^d/i
|
|
1888
|
-
],
|
|
1889
|
-
any: [
|
|
1890
|
-
/^ja/i,
|
|
1891
|
-
/^f/i,
|
|
1892
|
-
/^mar/i,
|
|
1893
|
-
/^ap/i,
|
|
1894
|
-
/^may/i,
|
|
1895
|
-
/^jun/i,
|
|
1896
|
-
/^jul/i,
|
|
1897
|
-
/^au/i,
|
|
1898
|
-
/^s/i,
|
|
1899
|
-
/^o/i,
|
|
1900
|
-
/^n/i,
|
|
1901
|
-
/^d/i
|
|
1902
|
-
]
|
|
1903
|
-
};
|
|
1904
|
-
const matchDayPatterns = {
|
|
1905
|
-
narrow: /^[smtwf]/i,
|
|
1906
|
-
short: /^(su|mo|tu|we|th|fr|sa)/i,
|
|
1907
|
-
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
|
|
1908
|
-
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
|
|
1909
|
-
};
|
|
1910
|
-
const parseDayPatterns = {
|
|
1911
|
-
narrow: [
|
|
1912
|
-
/^s/i,
|
|
1913
|
-
/^m/i,
|
|
1914
|
-
/^t/i,
|
|
1915
|
-
/^w/i,
|
|
1916
|
-
/^t/i,
|
|
1917
|
-
/^f/i,
|
|
1918
|
-
/^s/i
|
|
1919
|
-
],
|
|
1920
|
-
any: [
|
|
1921
|
-
/^su/i,
|
|
1922
|
-
/^m/i,
|
|
1923
|
-
/^tu/i,
|
|
1924
|
-
/^w/i,
|
|
1925
|
-
/^th/i,
|
|
1926
|
-
/^f/i,
|
|
1927
|
-
/^sa/i
|
|
1928
|
-
]
|
|
1929
|
-
};
|
|
1930
|
-
const matchDayPeriodPatterns = {
|
|
1931
|
-
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
|
|
1932
|
-
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
|
|
1933
|
-
};
|
|
1934
|
-
const parseDayPeriodPatterns = {
|
|
1935
|
-
any: {
|
|
1936
|
-
am: /^a/i,
|
|
1937
|
-
pm: /^p/i,
|
|
1938
|
-
midnight: /^mi/i,
|
|
1939
|
-
noon: /^no/i,
|
|
1940
|
-
morning: /morning/i,
|
|
1941
|
-
afternoon: /afternoon/i,
|
|
1942
|
-
evening: /evening/i,
|
|
1943
|
-
night: /night/i
|
|
1944
|
-
}
|
|
1945
|
-
};
|
|
1946
|
-
const match = {
|
|
1947
|
-
ordinalNumber: buildMatchPatternFn({
|
|
1948
|
-
matchPattern: matchOrdinalNumberPattern,
|
|
1949
|
-
parsePattern: parseOrdinalNumberPattern,
|
|
1950
|
-
valueCallback: (value)=>parseInt(value, 10)
|
|
1951
|
-
}),
|
|
1952
|
-
era: buildMatchFn({
|
|
1953
|
-
matchPatterns: matchEraPatterns,
|
|
1954
|
-
defaultMatchWidth: "wide",
|
|
1955
|
-
parsePatterns: parseEraPatterns,
|
|
1956
|
-
defaultParseWidth: "any"
|
|
1957
|
-
}),
|
|
1958
|
-
quarter: buildMatchFn({
|
|
1959
|
-
matchPatterns: matchQuarterPatterns,
|
|
1960
|
-
defaultMatchWidth: "wide",
|
|
1961
|
-
parsePatterns: parseQuarterPatterns,
|
|
1962
|
-
defaultParseWidth: "any",
|
|
1963
|
-
valueCallback: (index)=>index + 1
|
|
1964
|
-
}),
|
|
1965
|
-
month: buildMatchFn({
|
|
1966
|
-
matchPatterns: matchMonthPatterns,
|
|
1967
|
-
defaultMatchWidth: "wide",
|
|
1968
|
-
parsePatterns: parseMonthPatterns,
|
|
1969
|
-
defaultParseWidth: "any"
|
|
1970
|
-
}),
|
|
1971
|
-
day: buildMatchFn({
|
|
1972
|
-
matchPatterns: matchDayPatterns,
|
|
1973
|
-
defaultMatchWidth: "wide",
|
|
1974
|
-
parsePatterns: parseDayPatterns,
|
|
1975
|
-
defaultParseWidth: "any"
|
|
1976
|
-
}),
|
|
1977
|
-
dayPeriod: buildMatchFn({
|
|
1978
|
-
matchPatterns: matchDayPeriodPatterns,
|
|
1979
|
-
defaultMatchWidth: "any",
|
|
1980
|
-
parsePatterns: parseDayPeriodPatterns,
|
|
1981
|
-
defaultParseWidth: "any"
|
|
1982
|
-
})
|
|
1983
|
-
};
|
|
1984
|
-
|
|
1985
|
-
/**
|
|
1986
|
-
* @category Locales
|
|
1987
|
-
* @summary English locale (United States).
|
|
1988
|
-
* @language English
|
|
1989
|
-
* @iso-639-2 eng
|
|
1990
|
-
* @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp)
|
|
1991
|
-
* @author Lesha Koss [@leshakoss](https://github.com/leshakoss)
|
|
1992
|
-
*/ const enUS = {
|
|
1993
|
-
code: "en-US",
|
|
1994
|
-
formatDistance: formatDistance,
|
|
1995
|
-
formatLong: formatLong,
|
|
1996
|
-
formatRelative: formatRelative,
|
|
1997
|
-
localize: localize,
|
|
1998
|
-
match: match,
|
|
1999
|
-
options: {
|
|
2000
|
-
weekStartsOn: 0 /* Sunday */ ,
|
|
2001
|
-
firstWeekContainsDate: 1
|
|
2002
|
-
}
|
|
2003
|
-
};
|
|
2004
|
-
|
|
2005
|
-
/**
|
|
2006
|
-
* The {@link getDayOfYear} function options.
|
|
2007
|
-
*/ /**
|
|
2008
|
-
* @name getDayOfYear
|
|
2009
|
-
* @category Day Helpers
|
|
2010
|
-
* @summary Get the day of the year of the given date.
|
|
2011
|
-
*
|
|
2012
|
-
* @description
|
|
2013
|
-
* Get the day of the year of the given date.
|
|
2014
|
-
*
|
|
2015
|
-
* @param date - The given date
|
|
2016
|
-
* @param options - The options
|
|
2017
|
-
*
|
|
2018
|
-
* @returns The day of year
|
|
2019
|
-
*
|
|
2020
|
-
* @example
|
|
2021
|
-
* // Which day of the year is 2 July 2014?
|
|
2022
|
-
* const result = getDayOfYear(new Date(2014, 6, 2))
|
|
2023
|
-
* //=> 183
|
|
2024
|
-
*/ function getDayOfYear(date, options) {
|
|
2025
|
-
const _date = toDate(date, options?.in);
|
|
2026
|
-
const diff = differenceInCalendarDays(_date, startOfYear(_date));
|
|
2027
|
-
const dayOfYear = diff + 1;
|
|
2028
|
-
return dayOfYear;
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
/**
|
|
2032
|
-
* The {@link getISOWeek} function options.
|
|
2033
|
-
*/ /**
|
|
2034
|
-
* @name getISOWeek
|
|
2035
|
-
* @category ISO Week Helpers
|
|
2036
|
-
* @summary Get the ISO week of the given date.
|
|
2037
|
-
*
|
|
2038
|
-
* @description
|
|
2039
|
-
* Get the ISO week of the given date.
|
|
2040
|
-
*
|
|
2041
|
-
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
|
2042
|
-
*
|
|
2043
|
-
* @param date - The given date
|
|
2044
|
-
* @param options - The options
|
|
2045
|
-
*
|
|
2046
|
-
* @returns The ISO week
|
|
2047
|
-
*
|
|
2048
|
-
* @example
|
|
2049
|
-
* // Which week of the ISO-week numbering year is 2 January 2005?
|
|
2050
|
-
* const result = getISOWeek(new Date(2005, 0, 2))
|
|
2051
|
-
* //=> 53
|
|
2052
|
-
*/ function getISOWeek(date, options) {
|
|
2053
|
-
const _date = toDate(date, options?.in);
|
|
2054
|
-
const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
|
|
2055
|
-
// Round the number of weeks to the nearest integer because the number of
|
|
2056
|
-
// milliseconds in a week is not constant (e.g. it's different in the week of
|
|
2057
|
-
// the daylight saving time clock shift).
|
|
2058
|
-
return Math.round(diff / millisecondsInWeek) + 1;
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
/**
|
|
2062
|
-
* The {@link getWeekYear} function options.
|
|
2063
|
-
*/ /**
|
|
2064
|
-
* @name getWeekYear
|
|
2065
|
-
* @category Week-Numbering Year Helpers
|
|
2066
|
-
* @summary Get the local week-numbering year of the given date.
|
|
2067
|
-
*
|
|
2068
|
-
* @description
|
|
2069
|
-
* Get the local week-numbering year of the given date.
|
|
2070
|
-
* The exact calculation depends on the values of
|
|
2071
|
-
* `options.weekStartsOn` (which is the index of the first day of the week)
|
|
2072
|
-
* and `options.firstWeekContainsDate` (which is the day of January, which is always in
|
|
2073
|
-
* the first week of the week-numbering year)
|
|
2074
|
-
*
|
|
2075
|
-
* Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
|
|
2076
|
-
*
|
|
2077
|
-
* @param date - The given date
|
|
2078
|
-
* @param options - An object with options.
|
|
2079
|
-
*
|
|
2080
|
-
* @returns The local week-numbering year
|
|
2081
|
-
*
|
|
2082
|
-
* @example
|
|
2083
|
-
* // Which week numbering year is 26 December 2004 with the default settings?
|
|
2084
|
-
* const result = getWeekYear(new Date(2004, 11, 26))
|
|
2085
|
-
* //=> 2005
|
|
2086
|
-
*
|
|
2087
|
-
* @example
|
|
2088
|
-
* // Which week numbering year is 26 December 2004 if week starts on Saturday?
|
|
2089
|
-
* const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 })
|
|
2090
|
-
* //=> 2004
|
|
2091
|
-
*
|
|
2092
|
-
* @example
|
|
2093
|
-
* // Which week numbering year is 26 December 2004 if the first week contains 4 January?
|
|
2094
|
-
* const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 })
|
|
2095
|
-
* //=> 2004
|
|
2096
|
-
*/ function getWeekYear(date, options) {
|
|
2097
|
-
const _date = toDate(date, options?.in);
|
|
2098
|
-
const year = _date.getFullYear();
|
|
2099
|
-
const defaultOptions = getDefaultOptions();
|
|
2100
|
-
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;
|
|
2101
|
-
const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
|
|
2102
|
-
firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
|
|
2103
|
-
firstWeekOfNextYear.setHours(0, 0, 0, 0);
|
|
2104
|
-
const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
|
|
2105
|
-
const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
|
|
2106
|
-
firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
|
|
2107
|
-
firstWeekOfThisYear.setHours(0, 0, 0, 0);
|
|
2108
|
-
const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
|
|
2109
|
-
if (+_date >= +startOfNextYear) {
|
|
2110
|
-
return year + 1;
|
|
2111
|
-
} else if (+_date >= +startOfThisYear) {
|
|
2112
|
-
return year;
|
|
2113
|
-
} else {
|
|
2114
|
-
return year - 1;
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
/**
|
|
2119
|
-
* The {@link startOfWeekYear} function options.
|
|
2120
|
-
*/ /**
|
|
2121
|
-
* @name startOfWeekYear
|
|
2122
|
-
* @category Week-Numbering Year Helpers
|
|
2123
|
-
* @summary Return the start of a local week-numbering year for the given date.
|
|
2124
|
-
*
|
|
2125
|
-
* @description
|
|
2126
|
-
* Return the start of a local week-numbering year.
|
|
2127
|
-
* The exact calculation depends on the values of
|
|
2128
|
-
* `options.weekStartsOn` (which is the index of the first day of the week)
|
|
2129
|
-
* and `options.firstWeekContainsDate` (which is the day of January, which is always in
|
|
2130
|
-
* the first week of the week-numbering year)
|
|
2131
|
-
*
|
|
2132
|
-
* Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
|
|
2133
|
-
*
|
|
2134
|
-
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
2135
|
-
* @typeParam ResultDate - The result `Date` type.
|
|
2136
|
-
*
|
|
2137
|
-
* @param date - The original date
|
|
2138
|
-
* @param options - An object with options
|
|
2139
|
-
*
|
|
2140
|
-
* @returns The start of a week-numbering year
|
|
2141
|
-
*
|
|
2142
|
-
* @example
|
|
2143
|
-
* // The start of an a week-numbering year for 2 July 2005 with default settings:
|
|
2144
|
-
* const result = startOfWeekYear(new Date(2005, 6, 2))
|
|
2145
|
-
* //=> Sun Dec 26 2004 00:00:00
|
|
2146
|
-
*
|
|
2147
|
-
* @example
|
|
2148
|
-
* // The start of a week-numbering year for 2 July 2005
|
|
2149
|
-
* // if Monday is the first day of week
|
|
2150
|
-
* // and 4 January is always in the first week of the year:
|
|
2151
|
-
* const result = startOfWeekYear(new Date(2005, 6, 2), {
|
|
2152
|
-
* weekStartsOn: 1,
|
|
2153
|
-
* firstWeekContainsDate: 4
|
|
2154
|
-
* })
|
|
2155
|
-
* //=> Mon Jan 03 2005 00:00:00
|
|
2156
|
-
*/ function startOfWeekYear(date, options) {
|
|
2157
|
-
const defaultOptions = getDefaultOptions();
|
|
2158
|
-
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;
|
|
2159
|
-
const year = getWeekYear(date, options);
|
|
2160
|
-
const firstWeek = constructFrom(options?.in || date, 0);
|
|
2161
|
-
firstWeek.setFullYear(year, 0, firstWeekContainsDate);
|
|
2162
|
-
firstWeek.setHours(0, 0, 0, 0);
|
|
2163
|
-
const _date = startOfWeek(firstWeek, options);
|
|
2164
|
-
return _date;
|
|
2165
|
-
}
|
|
2166
|
-
|
|
2167
|
-
/**
|
|
2168
|
-
* The {@link getWeek} function options.
|
|
2169
|
-
*/ /**
|
|
2170
|
-
* @name getWeek
|
|
2171
|
-
* @category Week Helpers
|
|
2172
|
-
* @summary Get the local week index of the given date.
|
|
2173
|
-
*
|
|
2174
|
-
* @description
|
|
2175
|
-
* Get the local week index of the given date.
|
|
2176
|
-
* The exact calculation depends on the values of
|
|
2177
|
-
* `options.weekStartsOn` (which is the index of the first day of the week)
|
|
2178
|
-
* and `options.firstWeekContainsDate` (which is the day of January, which is always in
|
|
2179
|
-
* the first week of the week-numbering year)
|
|
2180
|
-
*
|
|
2181
|
-
* Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
|
|
2182
|
-
*
|
|
2183
|
-
* @param date - The given date
|
|
2184
|
-
* @param options - An object with options
|
|
2185
|
-
*
|
|
2186
|
-
* @returns The week
|
|
2187
|
-
*
|
|
2188
|
-
* @example
|
|
2189
|
-
* // Which week of the local week numbering year is 2 January 2005 with default options?
|
|
2190
|
-
* const result = getWeek(new Date(2005, 0, 2))
|
|
2191
|
-
* //=> 2
|
|
2192
|
-
*
|
|
2193
|
-
* @example
|
|
2194
|
-
* // Which week of the local week numbering year is 2 January 2005,
|
|
2195
|
-
* // if Monday is the first day of the week,
|
|
2196
|
-
* // and the first week of the year always contains 4 January?
|
|
2197
|
-
* const result = getWeek(new Date(2005, 0, 2), {
|
|
2198
|
-
* weekStartsOn: 1,
|
|
2199
|
-
* firstWeekContainsDate: 4
|
|
2200
|
-
* })
|
|
2201
|
-
* //=> 53
|
|
2202
|
-
*/ function getWeek(date, options) {
|
|
2203
|
-
const _date = toDate(date, options?.in);
|
|
2204
|
-
const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
|
|
2205
|
-
// Round the number of weeks to the nearest integer because the number of
|
|
2206
|
-
// milliseconds in a week is not constant (e.g. it's different in the week of
|
|
2207
|
-
// the daylight saving time clock shift).
|
|
2208
|
-
return Math.round(diff / millisecondsInWeek) + 1;
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
function addLeadingZeros(number, targetLength) {
|
|
2212
|
-
const sign = number < 0 ? "-" : "";
|
|
2213
|
-
const output = Math.abs(number).toString().padStart(targetLength, "0");
|
|
2214
|
-
return sign + output;
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
/*
|
|
2218
|
-
* | | Unit | | Unit |
|
|
2219
|
-
* |-----|--------------------------------|-----|--------------------------------|
|
|
2220
|
-
* | a | AM, PM | A* | |
|
|
2221
|
-
* | d | Day of month | D | |
|
|
2222
|
-
* | h | Hour [1-12] | H | Hour [0-23] |
|
|
2223
|
-
* | m | Minute | M | Month |
|
|
2224
|
-
* | s | Second | S | Fraction of second |
|
|
2225
|
-
* | y | Year (abs) | Y | |
|
|
2226
|
-
*
|
|
2227
|
-
* Letters marked by * are not implemented but reserved by Unicode standard.
|
|
2228
|
-
*/ const lightFormatters = {
|
|
2229
|
-
// Year
|
|
2230
|
-
y (date, token) {
|
|
2231
|
-
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
|
|
2232
|
-
// | Year | y | yy | yyy | yyyy | yyyyy |
|
|
2233
|
-
// |----------|-------|----|-------|-------|-------|
|
|
2234
|
-
// | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
|
|
2235
|
-
// | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
|
|
2236
|
-
// | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
|
|
2237
|
-
// | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
|
|
2238
|
-
// | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
|
|
2239
|
-
const signedYear = date.getFullYear();
|
|
2240
|
-
// Returns 1 for 1 BC (which is year 0 in JavaScript)
|
|
2241
|
-
const year = signedYear > 0 ? signedYear : 1 - signedYear;
|
|
2242
|
-
return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
|
|
2243
|
-
},
|
|
2244
|
-
// Month
|
|
2245
|
-
M (date, token) {
|
|
2246
|
-
const month = date.getMonth();
|
|
2247
|
-
return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
|
|
2248
|
-
},
|
|
2249
|
-
// Day of the month
|
|
2250
|
-
d (date, token) {
|
|
2251
|
-
return addLeadingZeros(date.getDate(), token.length);
|
|
2252
|
-
},
|
|
2253
|
-
// AM or PM
|
|
2254
|
-
a (date, token) {
|
|
2255
|
-
const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
|
|
2256
|
-
switch(token){
|
|
2257
|
-
case "a":
|
|
2258
|
-
case "aa":
|
|
2259
|
-
return dayPeriodEnumValue.toUpperCase();
|
|
2260
|
-
case "aaa":
|
|
2261
|
-
return dayPeriodEnumValue;
|
|
2262
|
-
case "aaaaa":
|
|
2263
|
-
return dayPeriodEnumValue[0];
|
|
2264
|
-
case "aaaa":
|
|
2265
|
-
default:
|
|
2266
|
-
return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
|
|
2267
|
-
}
|
|
2268
|
-
},
|
|
2269
|
-
// Hour [1-12]
|
|
2270
|
-
h (date, token) {
|
|
2271
|
-
return addLeadingZeros(date.getHours() % 12 || 12, token.length);
|
|
2272
|
-
},
|
|
2273
|
-
// Hour [0-23]
|
|
2274
|
-
H (date, token) {
|
|
2275
|
-
return addLeadingZeros(date.getHours(), token.length);
|
|
2276
|
-
},
|
|
2277
|
-
// Minute
|
|
2278
|
-
m (date, token) {
|
|
2279
|
-
return addLeadingZeros(date.getMinutes(), token.length);
|
|
2280
|
-
},
|
|
2281
|
-
// Second
|
|
2282
|
-
s (date, token) {
|
|
2283
|
-
return addLeadingZeros(date.getSeconds(), token.length);
|
|
2284
|
-
},
|
|
2285
|
-
// Fraction of second
|
|
2286
|
-
S (date, token) {
|
|
2287
|
-
const numberOfDigits = token.length;
|
|
2288
|
-
const milliseconds = date.getMilliseconds();
|
|
2289
|
-
const fractionalSeconds = Math.trunc(milliseconds * Math.pow(10, numberOfDigits - 3));
|
|
2290
|
-
return addLeadingZeros(fractionalSeconds, token.length);
|
|
2291
|
-
}
|
|
2292
|
-
};
|
|
2293
|
-
|
|
2294
|
-
const dayPeriodEnum = {
|
|
2295
|
-
midnight: "midnight",
|
|
2296
|
-
noon: "noon",
|
|
2297
|
-
morning: "morning",
|
|
2298
|
-
afternoon: "afternoon",
|
|
2299
|
-
evening: "evening",
|
|
2300
|
-
night: "night"
|
|
2301
|
-
};
|
|
2302
|
-
/*
|
|
2303
|
-
* | | Unit | | Unit |
|
|
2304
|
-
* |-----|--------------------------------|-----|--------------------------------|
|
|
2305
|
-
* | a | AM, PM | A* | Milliseconds in day |
|
|
2306
|
-
* | b | AM, PM, noon, midnight | B | Flexible day period |
|
|
2307
|
-
* | c | Stand-alone local day of week | C* | Localized hour w/ day period |
|
|
2308
|
-
* | d | Day of month | D | Day of year |
|
|
2309
|
-
* | e | Local day of week | E | Day of week |
|
|
2310
|
-
* | f | | F* | Day of week in month |
|
|
2311
|
-
* | g* | Modified Julian day | G | Era |
|
|
2312
|
-
* | h | Hour [1-12] | H | Hour [0-23] |
|
|
2313
|
-
* | i! | ISO day of week | I! | ISO week of year |
|
|
2314
|
-
* | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
|
|
2315
|
-
* | k | Hour [1-24] | K | Hour [0-11] |
|
|
2316
|
-
* | l* | (deprecated) | L | Stand-alone month |
|
|
2317
|
-
* | m | Minute | M | Month |
|
|
2318
|
-
* | n | | N | |
|
|
2319
|
-
* | o! | Ordinal number modifier | O | Timezone (GMT) |
|
|
2320
|
-
* | p! | Long localized time | P! | Long localized date |
|
|
2321
|
-
* | q | Stand-alone quarter | Q | Quarter |
|
|
2322
|
-
* | r* | Related Gregorian year | R! | ISO week-numbering year |
|
|
2323
|
-
* | s | Second | S | Fraction of second |
|
|
2324
|
-
* | t! | Seconds timestamp | T! | Milliseconds timestamp |
|
|
2325
|
-
* | u | Extended year | U* | Cyclic year |
|
|
2326
|
-
* | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
|
|
2327
|
-
* | w | Local week of year | W* | Week of month |
|
|
2328
|
-
* | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
|
|
2329
|
-
* | y | Year (abs) | Y | Local week-numbering year |
|
|
2330
|
-
* | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
|
|
2331
|
-
*
|
|
2332
|
-
* Letters marked by * are not implemented but reserved by Unicode standard.
|
|
2333
|
-
*
|
|
2334
|
-
* Letters marked by ! are non-standard, but implemented by date-fns:
|
|
2335
|
-
* - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
|
|
2336
|
-
* - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
|
|
2337
|
-
* i.e. 7 for Sunday, 1 for Monday, etc.
|
|
2338
|
-
* - `I` is ISO week of year, as opposed to `w` which is local week of year.
|
|
2339
|
-
* - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
|
|
2340
|
-
* `R` is supposed to be used in conjunction with `I` and `i`
|
|
2341
|
-
* for universal ISO week-numbering date, whereas
|
|
2342
|
-
* `Y` is supposed to be used in conjunction with `w` and `e`
|
|
2343
|
-
* for week-numbering date specific to the locale.
|
|
2344
|
-
* - `P` is long localized date format
|
|
2345
|
-
* - `p` is long localized time format
|
|
2346
|
-
*/ const formatters = {
|
|
2347
|
-
// Era
|
|
2348
|
-
G: function(date, token, localize) {
|
|
2349
|
-
const era = date.getFullYear() > 0 ? 1 : 0;
|
|
2350
|
-
switch(token){
|
|
2351
|
-
// AD, BC
|
|
2352
|
-
case "G":
|
|
2353
|
-
case "GG":
|
|
2354
|
-
case "GGG":
|
|
2355
|
-
return localize.era(era, {
|
|
2356
|
-
width: "abbreviated"
|
|
2357
|
-
});
|
|
2358
|
-
// A, B
|
|
2359
|
-
case "GGGGG":
|
|
2360
|
-
return localize.era(era, {
|
|
2361
|
-
width: "narrow"
|
|
2362
|
-
});
|
|
2363
|
-
// Anno Domini, Before Christ
|
|
2364
|
-
case "GGGG":
|
|
2365
|
-
default:
|
|
2366
|
-
return localize.era(era, {
|
|
2367
|
-
width: "wide"
|
|
2368
|
-
});
|
|
2369
|
-
}
|
|
2370
|
-
},
|
|
2371
|
-
// Year
|
|
2372
|
-
y: function(date, token, localize) {
|
|
2373
|
-
// Ordinal number
|
|
2374
|
-
if (token === "yo") {
|
|
2375
|
-
const signedYear = date.getFullYear();
|
|
2376
|
-
// Returns 1 for 1 BC (which is year 0 in JavaScript)
|
|
2377
|
-
const year = signedYear > 0 ? signedYear : 1 - signedYear;
|
|
2378
|
-
return localize.ordinalNumber(year, {
|
|
2379
|
-
unit: "year"
|
|
2380
|
-
});
|
|
2381
|
-
}
|
|
2382
|
-
return lightFormatters.y(date, token);
|
|
2383
|
-
},
|
|
2384
|
-
// Local week-numbering year
|
|
2385
|
-
Y: function(date, token, localize, options) {
|
|
2386
|
-
const signedWeekYear = getWeekYear(date, options);
|
|
2387
|
-
// Returns 1 for 1 BC (which is year 0 in JavaScript)
|
|
2388
|
-
const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
|
|
2389
|
-
// Two digit year
|
|
2390
|
-
if (token === "YY") {
|
|
2391
|
-
const twoDigitYear = weekYear % 100;
|
|
2392
|
-
return addLeadingZeros(twoDigitYear, 2);
|
|
2393
|
-
}
|
|
2394
|
-
// Ordinal number
|
|
2395
|
-
if (token === "Yo") {
|
|
2396
|
-
return localize.ordinalNumber(weekYear, {
|
|
2397
|
-
unit: "year"
|
|
2398
|
-
});
|
|
2399
|
-
}
|
|
2400
|
-
// Padding
|
|
2401
|
-
return addLeadingZeros(weekYear, token.length);
|
|
2402
|
-
},
|
|
2403
|
-
// ISO week-numbering year
|
|
2404
|
-
R: function(date, token) {
|
|
2405
|
-
const isoWeekYear = getISOWeekYear(date);
|
|
2406
|
-
// Padding
|
|
2407
|
-
return addLeadingZeros(isoWeekYear, token.length);
|
|
2408
|
-
},
|
|
2409
|
-
// Extended year. This is a single number designating the year of this calendar system.
|
|
2410
|
-
// The main difference between `y` and `u` localizers are B.C. years:
|
|
2411
|
-
// | Year | `y` | `u` |
|
|
2412
|
-
// |------|-----|-----|
|
|
2413
|
-
// | AC 1 | 1 | 1 |
|
|
2414
|
-
// | BC 1 | 1 | 0 |
|
|
2415
|
-
// | BC 2 | 2 | -1 |
|
|
2416
|
-
// Also `yy` always returns the last two digits of a year,
|
|
2417
|
-
// while `uu` pads single digit years to 2 characters and returns other years unchanged.
|
|
2418
|
-
u: function(date, token) {
|
|
2419
|
-
const year = date.getFullYear();
|
|
2420
|
-
return addLeadingZeros(year, token.length);
|
|
2421
|
-
},
|
|
2422
|
-
// Quarter
|
|
2423
|
-
Q: function(date, token, localize) {
|
|
2424
|
-
const quarter = Math.ceil((date.getMonth() + 1) / 3);
|
|
2425
|
-
switch(token){
|
|
2426
|
-
// 1, 2, 3, 4
|
|
2427
|
-
case "Q":
|
|
2428
|
-
return String(quarter);
|
|
2429
|
-
// 01, 02, 03, 04
|
|
2430
|
-
case "QQ":
|
|
2431
|
-
return addLeadingZeros(quarter, 2);
|
|
2432
|
-
// 1st, 2nd, 3rd, 4th
|
|
2433
|
-
case "Qo":
|
|
2434
|
-
return localize.ordinalNumber(quarter, {
|
|
2435
|
-
unit: "quarter"
|
|
2436
|
-
});
|
|
2437
|
-
// Q1, Q2, Q3, Q4
|
|
2438
|
-
case "QQQ":
|
|
2439
|
-
return localize.quarter(quarter, {
|
|
2440
|
-
width: "abbreviated",
|
|
2441
|
-
context: "formatting"
|
|
2442
|
-
});
|
|
2443
|
-
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
2444
|
-
case "QQQQQ":
|
|
2445
|
-
return localize.quarter(quarter, {
|
|
2446
|
-
width: "narrow",
|
|
2447
|
-
context: "formatting"
|
|
2448
|
-
});
|
|
2449
|
-
// 1st quarter, 2nd quarter, ...
|
|
2450
|
-
case "QQQQ":
|
|
2451
|
-
default:
|
|
2452
|
-
return localize.quarter(quarter, {
|
|
2453
|
-
width: "wide",
|
|
2454
|
-
context: "formatting"
|
|
2455
|
-
});
|
|
2456
|
-
}
|
|
2457
|
-
},
|
|
2458
|
-
// Stand-alone quarter
|
|
2459
|
-
q: function(date, token, localize) {
|
|
2460
|
-
const quarter = Math.ceil((date.getMonth() + 1) / 3);
|
|
2461
|
-
switch(token){
|
|
2462
|
-
// 1, 2, 3, 4
|
|
2463
|
-
case "q":
|
|
2464
|
-
return String(quarter);
|
|
2465
|
-
// 01, 02, 03, 04
|
|
2466
|
-
case "qq":
|
|
2467
|
-
return addLeadingZeros(quarter, 2);
|
|
2468
|
-
// 1st, 2nd, 3rd, 4th
|
|
2469
|
-
case "qo":
|
|
2470
|
-
return localize.ordinalNumber(quarter, {
|
|
2471
|
-
unit: "quarter"
|
|
2472
|
-
});
|
|
2473
|
-
// Q1, Q2, Q3, Q4
|
|
2474
|
-
case "qqq":
|
|
2475
|
-
return localize.quarter(quarter, {
|
|
2476
|
-
width: "abbreviated",
|
|
2477
|
-
context: "standalone"
|
|
2478
|
-
});
|
|
2479
|
-
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
2480
|
-
case "qqqqq":
|
|
2481
|
-
return localize.quarter(quarter, {
|
|
2482
|
-
width: "narrow",
|
|
2483
|
-
context: "standalone"
|
|
2484
|
-
});
|
|
2485
|
-
// 1st quarter, 2nd quarter, ...
|
|
2486
|
-
case "qqqq":
|
|
2487
|
-
default:
|
|
2488
|
-
return localize.quarter(quarter, {
|
|
2489
|
-
width: "wide",
|
|
2490
|
-
context: "standalone"
|
|
2491
|
-
});
|
|
2492
|
-
}
|
|
2493
|
-
},
|
|
2494
|
-
// Month
|
|
2495
|
-
M: function(date, token, localize) {
|
|
2496
|
-
const month = date.getMonth();
|
|
2497
|
-
switch(token){
|
|
2498
|
-
case "M":
|
|
2499
|
-
case "MM":
|
|
2500
|
-
return lightFormatters.M(date, token);
|
|
2501
|
-
// 1st, 2nd, ..., 12th
|
|
2502
|
-
case "Mo":
|
|
2503
|
-
return localize.ordinalNumber(month + 1, {
|
|
2504
|
-
unit: "month"
|
|
2505
|
-
});
|
|
2506
|
-
// Jan, Feb, ..., Dec
|
|
2507
|
-
case "MMM":
|
|
2508
|
-
return localize.month(month, {
|
|
2509
|
-
width: "abbreviated",
|
|
2510
|
-
context: "formatting"
|
|
2511
|
-
});
|
|
2512
|
-
// J, F, ..., D
|
|
2513
|
-
case "MMMMM":
|
|
2514
|
-
return localize.month(month, {
|
|
2515
|
-
width: "narrow",
|
|
2516
|
-
context: "formatting"
|
|
2517
|
-
});
|
|
2518
|
-
// January, February, ..., December
|
|
2519
|
-
case "MMMM":
|
|
2520
|
-
default:
|
|
2521
|
-
return localize.month(month, {
|
|
2522
|
-
width: "wide",
|
|
2523
|
-
context: "formatting"
|
|
2524
|
-
});
|
|
2525
|
-
}
|
|
2526
|
-
},
|
|
2527
|
-
// Stand-alone month
|
|
2528
|
-
L: function(date, token, localize) {
|
|
2529
|
-
const month = date.getMonth();
|
|
2530
|
-
switch(token){
|
|
2531
|
-
// 1, 2, ..., 12
|
|
2532
|
-
case "L":
|
|
2533
|
-
return String(month + 1);
|
|
2534
|
-
// 01, 02, ..., 12
|
|
2535
|
-
case "LL":
|
|
2536
|
-
return addLeadingZeros(month + 1, 2);
|
|
2537
|
-
// 1st, 2nd, ..., 12th
|
|
2538
|
-
case "Lo":
|
|
2539
|
-
return localize.ordinalNumber(month + 1, {
|
|
2540
|
-
unit: "month"
|
|
2541
|
-
});
|
|
2542
|
-
// Jan, Feb, ..., Dec
|
|
2543
|
-
case "LLL":
|
|
2544
|
-
return localize.month(month, {
|
|
2545
|
-
width: "abbreviated",
|
|
2546
|
-
context: "standalone"
|
|
2547
|
-
});
|
|
2548
|
-
// J, F, ..., D
|
|
2549
|
-
case "LLLLL":
|
|
2550
|
-
return localize.month(month, {
|
|
2551
|
-
width: "narrow",
|
|
2552
|
-
context: "standalone"
|
|
2553
|
-
});
|
|
2554
|
-
// January, February, ..., December
|
|
2555
|
-
case "LLLL":
|
|
2556
|
-
default:
|
|
2557
|
-
return localize.month(month, {
|
|
2558
|
-
width: "wide",
|
|
2559
|
-
context: "standalone"
|
|
2560
|
-
});
|
|
2561
|
-
}
|
|
2562
|
-
},
|
|
2563
|
-
// Local week of year
|
|
2564
|
-
w: function(date, token, localize, options) {
|
|
2565
|
-
const week = getWeek(date, options);
|
|
2566
|
-
if (token === "wo") {
|
|
2567
|
-
return localize.ordinalNumber(week, {
|
|
2568
|
-
unit: "week"
|
|
2569
|
-
});
|
|
2570
|
-
}
|
|
2571
|
-
return addLeadingZeros(week, token.length);
|
|
2572
|
-
},
|
|
2573
|
-
// ISO week of year
|
|
2574
|
-
I: function(date, token, localize) {
|
|
2575
|
-
const isoWeek = getISOWeek(date);
|
|
2576
|
-
if (token === "Io") {
|
|
2577
|
-
return localize.ordinalNumber(isoWeek, {
|
|
2578
|
-
unit: "week"
|
|
2579
|
-
});
|
|
2580
|
-
}
|
|
2581
|
-
return addLeadingZeros(isoWeek, token.length);
|
|
2582
|
-
},
|
|
2583
|
-
// Day of the month
|
|
2584
|
-
d: function(date, token, localize) {
|
|
2585
|
-
if (token === "do") {
|
|
2586
|
-
return localize.ordinalNumber(date.getDate(), {
|
|
2587
|
-
unit: "date"
|
|
2588
|
-
});
|
|
2589
|
-
}
|
|
2590
|
-
return lightFormatters.d(date, token);
|
|
2591
|
-
},
|
|
2592
|
-
// Day of year
|
|
2593
|
-
D: function(date, token, localize) {
|
|
2594
|
-
const dayOfYear = getDayOfYear(date);
|
|
2595
|
-
if (token === "Do") {
|
|
2596
|
-
return localize.ordinalNumber(dayOfYear, {
|
|
2597
|
-
unit: "dayOfYear"
|
|
2598
|
-
});
|
|
2599
|
-
}
|
|
2600
|
-
return addLeadingZeros(dayOfYear, token.length);
|
|
2601
|
-
},
|
|
2602
|
-
// Day of week
|
|
2603
|
-
E: function(date, token, localize) {
|
|
2604
|
-
const dayOfWeek = date.getDay();
|
|
2605
|
-
switch(token){
|
|
2606
|
-
// Tue
|
|
2607
|
-
case "E":
|
|
2608
|
-
case "EE":
|
|
2609
|
-
case "EEE":
|
|
2610
|
-
return localize.day(dayOfWeek, {
|
|
2611
|
-
width: "abbreviated",
|
|
2612
|
-
context: "formatting"
|
|
2613
|
-
});
|
|
2614
|
-
// T
|
|
2615
|
-
case "EEEEE":
|
|
2616
|
-
return localize.day(dayOfWeek, {
|
|
2617
|
-
width: "narrow",
|
|
2618
|
-
context: "formatting"
|
|
2619
|
-
});
|
|
2620
|
-
// Tu
|
|
2621
|
-
case "EEEEEE":
|
|
2622
|
-
return localize.day(dayOfWeek, {
|
|
2623
|
-
width: "short",
|
|
2624
|
-
context: "formatting"
|
|
2625
|
-
});
|
|
2626
|
-
// Tuesday
|
|
2627
|
-
case "EEEE":
|
|
2628
|
-
default:
|
|
2629
|
-
return localize.day(dayOfWeek, {
|
|
2630
|
-
width: "wide",
|
|
2631
|
-
context: "formatting"
|
|
2632
|
-
});
|
|
2633
|
-
}
|
|
2634
|
-
},
|
|
2635
|
-
// Local day of week
|
|
2636
|
-
e: function(date, token, localize, options) {
|
|
2637
|
-
const dayOfWeek = date.getDay();
|
|
2638
|
-
const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
|
2639
|
-
switch(token){
|
|
2640
|
-
// Numerical value (Nth day of week with current locale or weekStartsOn)
|
|
2641
|
-
case "e":
|
|
2642
|
-
return String(localDayOfWeek);
|
|
2643
|
-
// Padded numerical value
|
|
2644
|
-
case "ee":
|
|
2645
|
-
return addLeadingZeros(localDayOfWeek, 2);
|
|
2646
|
-
// 1st, 2nd, ..., 7th
|
|
2647
|
-
case "eo":
|
|
2648
|
-
return localize.ordinalNumber(localDayOfWeek, {
|
|
2649
|
-
unit: "day"
|
|
2650
|
-
});
|
|
2651
|
-
case "eee":
|
|
2652
|
-
return localize.day(dayOfWeek, {
|
|
2653
|
-
width: "abbreviated",
|
|
2654
|
-
context: "formatting"
|
|
2655
|
-
});
|
|
2656
|
-
// T
|
|
2657
|
-
case "eeeee":
|
|
2658
|
-
return localize.day(dayOfWeek, {
|
|
2659
|
-
width: "narrow",
|
|
2660
|
-
context: "formatting"
|
|
2661
|
-
});
|
|
2662
|
-
// Tu
|
|
2663
|
-
case "eeeeee":
|
|
2664
|
-
return localize.day(dayOfWeek, {
|
|
2665
|
-
width: "short",
|
|
2666
|
-
context: "formatting"
|
|
2667
|
-
});
|
|
2668
|
-
// Tuesday
|
|
2669
|
-
case "eeee":
|
|
2670
|
-
default:
|
|
2671
|
-
return localize.day(dayOfWeek, {
|
|
2672
|
-
width: "wide",
|
|
2673
|
-
context: "formatting"
|
|
2674
|
-
});
|
|
2675
|
-
}
|
|
2676
|
-
},
|
|
2677
|
-
// Stand-alone local day of week
|
|
2678
|
-
c: function(date, token, localize, options) {
|
|
2679
|
-
const dayOfWeek = date.getDay();
|
|
2680
|
-
const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
|
2681
|
-
switch(token){
|
|
2682
|
-
// Numerical value (same as in `e`)
|
|
2683
|
-
case "c":
|
|
2684
|
-
return String(localDayOfWeek);
|
|
2685
|
-
// Padded numerical value
|
|
2686
|
-
case "cc":
|
|
2687
|
-
return addLeadingZeros(localDayOfWeek, token.length);
|
|
2688
|
-
// 1st, 2nd, ..., 7th
|
|
2689
|
-
case "co":
|
|
2690
|
-
return localize.ordinalNumber(localDayOfWeek, {
|
|
2691
|
-
unit: "day"
|
|
2692
|
-
});
|
|
2693
|
-
case "ccc":
|
|
2694
|
-
return localize.day(dayOfWeek, {
|
|
2695
|
-
width: "abbreviated",
|
|
2696
|
-
context: "standalone"
|
|
2697
|
-
});
|
|
2698
|
-
// T
|
|
2699
|
-
case "ccccc":
|
|
2700
|
-
return localize.day(dayOfWeek, {
|
|
2701
|
-
width: "narrow",
|
|
2702
|
-
context: "standalone"
|
|
2703
|
-
});
|
|
2704
|
-
// Tu
|
|
2705
|
-
case "cccccc":
|
|
2706
|
-
return localize.day(dayOfWeek, {
|
|
2707
|
-
width: "short",
|
|
2708
|
-
context: "standalone"
|
|
2709
|
-
});
|
|
2710
|
-
// Tuesday
|
|
2711
|
-
case "cccc":
|
|
2712
|
-
default:
|
|
2713
|
-
return localize.day(dayOfWeek, {
|
|
2714
|
-
width: "wide",
|
|
2715
|
-
context: "standalone"
|
|
2716
|
-
});
|
|
2717
|
-
}
|
|
2718
|
-
},
|
|
2719
|
-
// ISO day of week
|
|
2720
|
-
i: function(date, token, localize) {
|
|
2721
|
-
const dayOfWeek = date.getDay();
|
|
2722
|
-
const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
|
|
2723
|
-
switch(token){
|
|
2724
|
-
// 2
|
|
2725
|
-
case "i":
|
|
2726
|
-
return String(isoDayOfWeek);
|
|
2727
|
-
// 02
|
|
2728
|
-
case "ii":
|
|
2729
|
-
return addLeadingZeros(isoDayOfWeek, token.length);
|
|
2730
|
-
// 2nd
|
|
2731
|
-
case "io":
|
|
2732
|
-
return localize.ordinalNumber(isoDayOfWeek, {
|
|
2733
|
-
unit: "day"
|
|
2734
|
-
});
|
|
2735
|
-
// Tue
|
|
2736
|
-
case "iii":
|
|
2737
|
-
return localize.day(dayOfWeek, {
|
|
2738
|
-
width: "abbreviated",
|
|
2739
|
-
context: "formatting"
|
|
2740
|
-
});
|
|
2741
|
-
// T
|
|
2742
|
-
case "iiiii":
|
|
2743
|
-
return localize.day(dayOfWeek, {
|
|
2744
|
-
width: "narrow",
|
|
2745
|
-
context: "formatting"
|
|
2746
|
-
});
|
|
2747
|
-
// Tu
|
|
2748
|
-
case "iiiiii":
|
|
2749
|
-
return localize.day(dayOfWeek, {
|
|
2750
|
-
width: "short",
|
|
2751
|
-
context: "formatting"
|
|
2752
|
-
});
|
|
2753
|
-
// Tuesday
|
|
2754
|
-
case "iiii":
|
|
2755
|
-
default:
|
|
2756
|
-
return localize.day(dayOfWeek, {
|
|
2757
|
-
width: "wide",
|
|
2758
|
-
context: "formatting"
|
|
2759
|
-
});
|
|
2760
|
-
}
|
|
2761
|
-
},
|
|
2762
|
-
// AM or PM
|
|
2763
|
-
a: function(date, token, localize) {
|
|
2764
|
-
const hours = date.getHours();
|
|
2765
|
-
const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
|
|
2766
|
-
switch(token){
|
|
2767
|
-
case "a":
|
|
2768
|
-
case "aa":
|
|
2769
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2770
|
-
width: "abbreviated",
|
|
2771
|
-
context: "formatting"
|
|
2772
|
-
});
|
|
2773
|
-
case "aaa":
|
|
2774
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2775
|
-
width: "abbreviated",
|
|
2776
|
-
context: "formatting"
|
|
2777
|
-
}).toLowerCase();
|
|
2778
|
-
case "aaaaa":
|
|
2779
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2780
|
-
width: "narrow",
|
|
2781
|
-
context: "formatting"
|
|
2782
|
-
});
|
|
2783
|
-
case "aaaa":
|
|
2784
|
-
default:
|
|
2785
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2786
|
-
width: "wide",
|
|
2787
|
-
context: "formatting"
|
|
2788
|
-
});
|
|
2789
|
-
}
|
|
2790
|
-
},
|
|
2791
|
-
// AM, PM, midnight, noon
|
|
2792
|
-
b: function(date, token, localize) {
|
|
2793
|
-
const hours = date.getHours();
|
|
2794
|
-
let dayPeriodEnumValue;
|
|
2795
|
-
if (hours === 12) {
|
|
2796
|
-
dayPeriodEnumValue = dayPeriodEnum.noon;
|
|
2797
|
-
} else if (hours === 0) {
|
|
2798
|
-
dayPeriodEnumValue = dayPeriodEnum.midnight;
|
|
2799
|
-
} else {
|
|
2800
|
-
dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
|
|
2801
|
-
}
|
|
2802
|
-
switch(token){
|
|
2803
|
-
case "b":
|
|
2804
|
-
case "bb":
|
|
2805
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2806
|
-
width: "abbreviated",
|
|
2807
|
-
context: "formatting"
|
|
2808
|
-
});
|
|
2809
|
-
case "bbb":
|
|
2810
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2811
|
-
width: "abbreviated",
|
|
2812
|
-
context: "formatting"
|
|
2813
|
-
}).toLowerCase();
|
|
2814
|
-
case "bbbbb":
|
|
2815
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2816
|
-
width: "narrow",
|
|
2817
|
-
context: "formatting"
|
|
2818
|
-
});
|
|
2819
|
-
case "bbbb":
|
|
2820
|
-
default:
|
|
2821
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2822
|
-
width: "wide",
|
|
2823
|
-
context: "formatting"
|
|
2824
|
-
});
|
|
2825
|
-
}
|
|
2826
|
-
},
|
|
2827
|
-
// in the morning, in the afternoon, in the evening, at night
|
|
2828
|
-
B: function(date, token, localize) {
|
|
2829
|
-
const hours = date.getHours();
|
|
2830
|
-
let dayPeriodEnumValue;
|
|
2831
|
-
if (hours >= 17) {
|
|
2832
|
-
dayPeriodEnumValue = dayPeriodEnum.evening;
|
|
2833
|
-
} else if (hours >= 12) {
|
|
2834
|
-
dayPeriodEnumValue = dayPeriodEnum.afternoon;
|
|
2835
|
-
} else if (hours >= 4) {
|
|
2836
|
-
dayPeriodEnumValue = dayPeriodEnum.morning;
|
|
2837
|
-
} else {
|
|
2838
|
-
dayPeriodEnumValue = dayPeriodEnum.night;
|
|
2839
|
-
}
|
|
2840
|
-
switch(token){
|
|
2841
|
-
case "B":
|
|
2842
|
-
case "BB":
|
|
2843
|
-
case "BBB":
|
|
2844
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2845
|
-
width: "abbreviated",
|
|
2846
|
-
context: "formatting"
|
|
2847
|
-
});
|
|
2848
|
-
case "BBBBB":
|
|
2849
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2850
|
-
width: "narrow",
|
|
2851
|
-
context: "formatting"
|
|
2852
|
-
});
|
|
2853
|
-
case "BBBB":
|
|
2854
|
-
default:
|
|
2855
|
-
return localize.dayPeriod(dayPeriodEnumValue, {
|
|
2856
|
-
width: "wide",
|
|
2857
|
-
context: "formatting"
|
|
2858
|
-
});
|
|
2859
|
-
}
|
|
2860
|
-
},
|
|
2861
|
-
// Hour [1-12]
|
|
2862
|
-
h: function(date, token, localize) {
|
|
2863
|
-
if (token === "ho") {
|
|
2864
|
-
let hours = date.getHours() % 12;
|
|
2865
|
-
if (hours === 0) hours = 12;
|
|
2866
|
-
return localize.ordinalNumber(hours, {
|
|
2867
|
-
unit: "hour"
|
|
2868
|
-
});
|
|
2869
|
-
}
|
|
2870
|
-
return lightFormatters.h(date, token);
|
|
2871
|
-
},
|
|
2872
|
-
// Hour [0-23]
|
|
2873
|
-
H: function(date, token, localize) {
|
|
2874
|
-
if (token === "Ho") {
|
|
2875
|
-
return localize.ordinalNumber(date.getHours(), {
|
|
2876
|
-
unit: "hour"
|
|
2877
|
-
});
|
|
2878
|
-
}
|
|
2879
|
-
return lightFormatters.H(date, token);
|
|
2880
|
-
},
|
|
2881
|
-
// Hour [0-11]
|
|
2882
|
-
K: function(date, token, localize) {
|
|
2883
|
-
const hours = date.getHours() % 12;
|
|
2884
|
-
if (token === "Ko") {
|
|
2885
|
-
return localize.ordinalNumber(hours, {
|
|
2886
|
-
unit: "hour"
|
|
2887
|
-
});
|
|
2888
|
-
}
|
|
2889
|
-
return addLeadingZeros(hours, token.length);
|
|
2890
|
-
},
|
|
2891
|
-
// Hour [1-24]
|
|
2892
|
-
k: function(date, token, localize) {
|
|
2893
|
-
let hours = date.getHours();
|
|
2894
|
-
if (hours === 0) hours = 24;
|
|
2895
|
-
if (token === "ko") {
|
|
2896
|
-
return localize.ordinalNumber(hours, {
|
|
2897
|
-
unit: "hour"
|
|
2898
|
-
});
|
|
2899
|
-
}
|
|
2900
|
-
return addLeadingZeros(hours, token.length);
|
|
2901
|
-
},
|
|
2902
|
-
// Minute
|
|
2903
|
-
m: function(date, token, localize) {
|
|
2904
|
-
if (token === "mo") {
|
|
2905
|
-
return localize.ordinalNumber(date.getMinutes(), {
|
|
2906
|
-
unit: "minute"
|
|
2907
|
-
});
|
|
2908
|
-
}
|
|
2909
|
-
return lightFormatters.m(date, token);
|
|
2910
|
-
},
|
|
2911
|
-
// Second
|
|
2912
|
-
s: function(date, token, localize) {
|
|
2913
|
-
if (token === "so") {
|
|
2914
|
-
return localize.ordinalNumber(date.getSeconds(), {
|
|
2915
|
-
unit: "second"
|
|
2916
|
-
});
|
|
2917
|
-
}
|
|
2918
|
-
return lightFormatters.s(date, token);
|
|
2919
|
-
},
|
|
2920
|
-
// Fraction of second
|
|
2921
|
-
S: function(date, token) {
|
|
2922
|
-
return lightFormatters.S(date, token);
|
|
2923
|
-
},
|
|
2924
|
-
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
|
|
2925
|
-
X: function(date, token, _localize) {
|
|
2926
|
-
const timezoneOffset = date.getTimezoneOffset();
|
|
2927
|
-
if (timezoneOffset === 0) {
|
|
2928
|
-
return "Z";
|
|
2929
|
-
}
|
|
2930
|
-
switch(token){
|
|
2931
|
-
// Hours and optional minutes
|
|
2932
|
-
case "X":
|
|
2933
|
-
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
|
2934
|
-
// Hours, minutes and optional seconds without `:` delimiter
|
|
2935
|
-
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
2936
|
-
// so this token always has the same output as `XX`
|
|
2937
|
-
case "XXXX":
|
|
2938
|
-
case "XX":
|
|
2939
|
-
return formatTimezone(timezoneOffset);
|
|
2940
|
-
// Hours, minutes and optional seconds with `:` delimiter
|
|
2941
|
-
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
2942
|
-
// so this token always has the same output as `XXX`
|
|
2943
|
-
case "XXXXX":
|
|
2944
|
-
case "XXX":
|
|
2945
|
-
default:
|
|
2946
|
-
return formatTimezone(timezoneOffset, ":");
|
|
2947
|
-
}
|
|
2948
|
-
},
|
|
2949
|
-
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
|
|
2950
|
-
x: function(date, token, _localize) {
|
|
2951
|
-
const timezoneOffset = date.getTimezoneOffset();
|
|
2952
|
-
switch(token){
|
|
2953
|
-
// Hours and optional minutes
|
|
2954
|
-
case "x":
|
|
2955
|
-
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
|
2956
|
-
// Hours, minutes and optional seconds without `:` delimiter
|
|
2957
|
-
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
2958
|
-
// so this token always has the same output as `xx`
|
|
2959
|
-
case "xxxx":
|
|
2960
|
-
case "xx":
|
|
2961
|
-
return formatTimezone(timezoneOffset);
|
|
2962
|
-
// Hours, minutes and optional seconds with `:` delimiter
|
|
2963
|
-
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
2964
|
-
// so this token always has the same output as `xxx`
|
|
2965
|
-
case "xxxxx":
|
|
2966
|
-
case "xxx":
|
|
2967
|
-
default:
|
|
2968
|
-
return formatTimezone(timezoneOffset, ":");
|
|
2969
|
-
}
|
|
2970
|
-
},
|
|
2971
|
-
// Timezone (GMT)
|
|
2972
|
-
O: function(date, token, _localize) {
|
|
2973
|
-
const timezoneOffset = date.getTimezoneOffset();
|
|
2974
|
-
switch(token){
|
|
2975
|
-
// Short
|
|
2976
|
-
case "O":
|
|
2977
|
-
case "OO":
|
|
2978
|
-
case "OOO":
|
|
2979
|
-
return "GMT" + formatTimezoneShort(timezoneOffset, ":");
|
|
2980
|
-
// Long
|
|
2981
|
-
case "OOOO":
|
|
2982
|
-
default:
|
|
2983
|
-
return "GMT" + formatTimezone(timezoneOffset, ":");
|
|
2984
|
-
}
|
|
2985
|
-
},
|
|
2986
|
-
// Timezone (specific non-location)
|
|
2987
|
-
z: function(date, token, _localize) {
|
|
2988
|
-
const timezoneOffset = date.getTimezoneOffset();
|
|
2989
|
-
switch(token){
|
|
2990
|
-
// Short
|
|
2991
|
-
case "z":
|
|
2992
|
-
case "zz":
|
|
2993
|
-
case "zzz":
|
|
2994
|
-
return "GMT" + formatTimezoneShort(timezoneOffset, ":");
|
|
2995
|
-
// Long
|
|
2996
|
-
case "zzzz":
|
|
2997
|
-
default:
|
|
2998
|
-
return "GMT" + formatTimezone(timezoneOffset, ":");
|
|
2999
|
-
}
|
|
3000
|
-
},
|
|
3001
|
-
// Seconds timestamp
|
|
3002
|
-
t: function(date, token, _localize) {
|
|
3003
|
-
const timestamp = Math.trunc(+date / 1000);
|
|
3004
|
-
return addLeadingZeros(timestamp, token.length);
|
|
3005
|
-
},
|
|
3006
|
-
// Milliseconds timestamp
|
|
3007
|
-
T: function(date, token, _localize) {
|
|
3008
|
-
return addLeadingZeros(+date, token.length);
|
|
3009
|
-
}
|
|
3010
|
-
};
|
|
3011
|
-
function formatTimezoneShort(offset, delimiter = "") {
|
|
3012
|
-
const sign = offset > 0 ? "-" : "+";
|
|
3013
|
-
const absOffset = Math.abs(offset);
|
|
3014
|
-
const hours = Math.trunc(absOffset / 60);
|
|
3015
|
-
const minutes = absOffset % 60;
|
|
3016
|
-
if (minutes === 0) {
|
|
3017
|
-
return sign + String(hours);
|
|
3018
|
-
}
|
|
3019
|
-
return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
|
|
3020
|
-
}
|
|
3021
|
-
function formatTimezoneWithOptionalMinutes(offset, delimiter) {
|
|
3022
|
-
if (offset % 60 === 0) {
|
|
3023
|
-
const sign = offset > 0 ? "-" : "+";
|
|
3024
|
-
return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
|
|
3025
|
-
}
|
|
3026
|
-
return formatTimezone(offset, delimiter);
|
|
3027
|
-
}
|
|
3028
|
-
function formatTimezone(offset, delimiter = "") {
|
|
3029
|
-
const sign = offset > 0 ? "-" : "+";
|
|
3030
|
-
const absOffset = Math.abs(offset);
|
|
3031
|
-
const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
|
|
3032
|
-
const minutes = addLeadingZeros(absOffset % 60, 2);
|
|
3033
|
-
return sign + hours + delimiter + minutes;
|
|
3034
|
-
}
|
|
3035
|
-
|
|
3036
|
-
const dateLongFormatter = (pattern, formatLong)=>{
|
|
3037
|
-
switch(pattern){
|
|
3038
|
-
case "P":
|
|
3039
|
-
return formatLong.date({
|
|
3040
|
-
width: "short"
|
|
3041
|
-
});
|
|
3042
|
-
case "PP":
|
|
3043
|
-
return formatLong.date({
|
|
3044
|
-
width: "medium"
|
|
3045
|
-
});
|
|
3046
|
-
case "PPP":
|
|
3047
|
-
return formatLong.date({
|
|
3048
|
-
width: "long"
|
|
3049
|
-
});
|
|
3050
|
-
case "PPPP":
|
|
3051
|
-
default:
|
|
3052
|
-
return formatLong.date({
|
|
3053
|
-
width: "full"
|
|
3054
|
-
});
|
|
3055
|
-
}
|
|
3056
|
-
};
|
|
3057
|
-
const timeLongFormatter = (pattern, formatLong)=>{
|
|
3058
|
-
switch(pattern){
|
|
3059
|
-
case "p":
|
|
3060
|
-
return formatLong.time({
|
|
3061
|
-
width: "short"
|
|
3062
|
-
});
|
|
3063
|
-
case "pp":
|
|
3064
|
-
return formatLong.time({
|
|
3065
|
-
width: "medium"
|
|
3066
|
-
});
|
|
3067
|
-
case "ppp":
|
|
3068
|
-
return formatLong.time({
|
|
3069
|
-
width: "long"
|
|
3070
|
-
});
|
|
3071
|
-
case "pppp":
|
|
3072
|
-
default:
|
|
3073
|
-
return formatLong.time({
|
|
3074
|
-
width: "full"
|
|
3075
|
-
});
|
|
3076
|
-
}
|
|
3077
|
-
};
|
|
3078
|
-
const dateTimeLongFormatter = (pattern, formatLong)=>{
|
|
3079
|
-
const matchResult = pattern.match(/(P+)(p+)?/) || [];
|
|
3080
|
-
const datePattern = matchResult[1];
|
|
3081
|
-
const timePattern = matchResult[2];
|
|
3082
|
-
if (!timePattern) {
|
|
3083
|
-
return dateLongFormatter(pattern, formatLong);
|
|
3084
|
-
}
|
|
3085
|
-
let dateTimeFormat;
|
|
3086
|
-
switch(datePattern){
|
|
3087
|
-
case "P":
|
|
3088
|
-
dateTimeFormat = formatLong.dateTime({
|
|
3089
|
-
width: "short"
|
|
3090
|
-
});
|
|
3091
|
-
break;
|
|
3092
|
-
case "PP":
|
|
3093
|
-
dateTimeFormat = formatLong.dateTime({
|
|
3094
|
-
width: "medium"
|
|
3095
|
-
});
|
|
3096
|
-
break;
|
|
3097
|
-
case "PPP":
|
|
3098
|
-
dateTimeFormat = formatLong.dateTime({
|
|
3099
|
-
width: "long"
|
|
3100
|
-
});
|
|
3101
|
-
break;
|
|
3102
|
-
case "PPPP":
|
|
3103
|
-
default:
|
|
3104
|
-
dateTimeFormat = formatLong.dateTime({
|
|
3105
|
-
width: "full"
|
|
3106
|
-
});
|
|
3107
|
-
break;
|
|
3108
|
-
}
|
|
3109
|
-
return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong)).replace("{{time}}", timeLongFormatter(timePattern, formatLong));
|
|
3110
|
-
};
|
|
3111
|
-
const longFormatters = {
|
|
3112
|
-
p: timeLongFormatter,
|
|
3113
|
-
P: dateTimeLongFormatter
|
|
3114
|
-
};
|
|
3115
|
-
|
|
3116
|
-
const dayOfYearTokenRE = /^D+$/;
|
|
3117
|
-
const weekYearTokenRE = /^Y+$/;
|
|
3118
|
-
const throwTokens = [
|
|
3119
|
-
"D",
|
|
3120
|
-
"DD",
|
|
3121
|
-
"YY",
|
|
3122
|
-
"YYYY"
|
|
3123
|
-
];
|
|
3124
|
-
function isProtectedDayOfYearToken(token) {
|
|
3125
|
-
return dayOfYearTokenRE.test(token);
|
|
3126
|
-
}
|
|
3127
|
-
function isProtectedWeekYearToken(token) {
|
|
3128
|
-
return weekYearTokenRE.test(token);
|
|
3129
|
-
}
|
|
3130
|
-
function warnOrThrowProtectedError(token, format, input) {
|
|
3131
|
-
const _message = message(token, format, input);
|
|
3132
|
-
console.warn(_message);
|
|
3133
|
-
if (throwTokens.includes(token)) throw new RangeError(_message);
|
|
3134
|
-
}
|
|
3135
|
-
function message(token, format, input) {
|
|
3136
|
-
const subject = token[0] === "Y" ? "years" : "days of the month";
|
|
3137
|
-
return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
|
|
3138
|
-
}
|
|
3139
|
-
|
|
3140
|
-
// This RegExp consists of three parts separated by `|`:
|
|
3141
|
-
// - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
|
|
3142
|
-
// (one of the certain letters followed by `o`)
|
|
3143
|
-
// - (\w)\1* matches any sequences of the same letter
|
|
3144
|
-
// - '' matches two quote characters in a row
|
|
3145
|
-
// - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
|
|
3146
|
-
// except a single quote symbol, which ends the sequence.
|
|
3147
|
-
// Two quote characters do not end the sequence.
|
|
3148
|
-
// If there is no matching single quote
|
|
3149
|
-
// then the sequence will continue until the end of the string.
|
|
3150
|
-
// - . matches any single character unmatched by previous parts of the RegExps
|
|
3151
|
-
const formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
|
|
3152
|
-
// This RegExp catches symbols escaped by quotes, and also
|
|
3153
|
-
// sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
|
|
3154
|
-
const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
3155
|
-
const escapedStringRegExp = /^'([^]*?)'?$/;
|
|
3156
|
-
const doubleQuoteRegExp = /''/g;
|
|
3157
|
-
const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
|
|
3158
|
-
/**
|
|
3159
|
-
* The {@link format} function options.
|
|
3160
|
-
*/ /**
|
|
3161
|
-
* @name format
|
|
3162
|
-
* @alias formatDate
|
|
3163
|
-
* @category Common Helpers
|
|
3164
|
-
* @summary Format the date.
|
|
3165
|
-
*
|
|
3166
|
-
* @description
|
|
3167
|
-
* Return the formatted date string in the given format. The result may vary by locale.
|
|
3168
|
-
*
|
|
3169
|
-
* > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
|
|
3170
|
-
* > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
3171
|
-
*
|
|
3172
|
-
* The characters wrapped between two single quotes characters (') are escaped.
|
|
3173
|
-
* Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
|
|
3174
|
-
* (see the last example)
|
|
3175
|
-
*
|
|
3176
|
-
* Format of the string is based on Unicode Technical Standard #35:
|
|
3177
|
-
* https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
3178
|
-
* with a few additions (see note 7 below the table).
|
|
3179
|
-
*
|
|
3180
|
-
* Accepted patterns:
|
|
3181
|
-
* | Unit | Pattern | Result examples | Notes |
|
|
3182
|
-
* |---------------------------------|---------|-----------------------------------|-------|
|
|
3183
|
-
* | Era | G..GGG | AD, BC | |
|
|
3184
|
-
* | | GGGG | Anno Domini, Before Christ | 2 |
|
|
3185
|
-
* | | GGGGG | A, B | |
|
|
3186
|
-
* | Calendar year | y | 44, 1, 1900, 2017 | 5 |
|
|
3187
|
-
* | | yo | 44th, 1st, 0th, 17th | 5,7 |
|
|
3188
|
-
* | | yy | 44, 01, 00, 17 | 5 |
|
|
3189
|
-
* | | yyy | 044, 001, 1900, 2017 | 5 |
|
|
3190
|
-
* | | yyyy | 0044, 0001, 1900, 2017 | 5 |
|
|
3191
|
-
* | | yyyyy | ... | 3,5 |
|
|
3192
|
-
* | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
|
|
3193
|
-
* | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
|
|
3194
|
-
* | | YY | 44, 01, 00, 17 | 5,8 |
|
|
3195
|
-
* | | YYY | 044, 001, 1900, 2017 | 5 |
|
|
3196
|
-
* | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
|
|
3197
|
-
* | | YYYYY | ... | 3,5 |
|
|
3198
|
-
* | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
|
|
3199
|
-
* | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
|
|
3200
|
-
* | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
|
|
3201
|
-
* | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
|
|
3202
|
-
* | | RRRRR | ... | 3,5,7 |
|
|
3203
|
-
* | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
|
|
3204
|
-
* | | uu | -43, 01, 1900, 2017 | 5 |
|
|
3205
|
-
* | | uuu | -043, 001, 1900, 2017 | 5 |
|
|
3206
|
-
* | | uuuu | -0043, 0001, 1900, 2017 | 5 |
|
|
3207
|
-
* | | uuuuu | ... | 3,5 |
|
|
3208
|
-
* | Quarter (formatting) | Q | 1, 2, 3, 4 | |
|
|
3209
|
-
* | | Qo | 1st, 2nd, 3rd, 4th | 7 |
|
|
3210
|
-
* | | QQ | 01, 02, 03, 04 | |
|
|
3211
|
-
* | | QQQ | Q1, Q2, Q3, Q4 | |
|
|
3212
|
-
* | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
|
|
3213
|
-
* | | QQQQQ | 1, 2, 3, 4 | 4 |
|
|
3214
|
-
* | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
|
|
3215
|
-
* | | qo | 1st, 2nd, 3rd, 4th | 7 |
|
|
3216
|
-
* | | qq | 01, 02, 03, 04 | |
|
|
3217
|
-
* | | qqq | Q1, Q2, Q3, Q4 | |
|
|
3218
|
-
* | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
|
|
3219
|
-
* | | qqqqq | 1, 2, 3, 4 | 4 |
|
|
3220
|
-
* | Month (formatting) | M | 1, 2, ..., 12 | |
|
|
3221
|
-
* | | Mo | 1st, 2nd, ..., 12th | 7 |
|
|
3222
|
-
* | | MM | 01, 02, ..., 12 | |
|
|
3223
|
-
* | | MMM | Jan, Feb, ..., Dec | |
|
|
3224
|
-
* | | MMMM | January, February, ..., December | 2 |
|
|
3225
|
-
* | | MMMMM | J, F, ..., D | |
|
|
3226
|
-
* | Month (stand-alone) | L | 1, 2, ..., 12 | |
|
|
3227
|
-
* | | Lo | 1st, 2nd, ..., 12th | 7 |
|
|
3228
|
-
* | | LL | 01, 02, ..., 12 | |
|
|
3229
|
-
* | | LLL | Jan, Feb, ..., Dec | |
|
|
3230
|
-
* | | LLLL | January, February, ..., December | 2 |
|
|
3231
|
-
* | | LLLLL | J, F, ..., D | |
|
|
3232
|
-
* | Local week of year | w | 1, 2, ..., 53 | |
|
|
3233
|
-
* | | wo | 1st, 2nd, ..., 53th | 7 |
|
|
3234
|
-
* | | ww | 01, 02, ..., 53 | |
|
|
3235
|
-
* | ISO week of year | I | 1, 2, ..., 53 | 7 |
|
|
3236
|
-
* | | Io | 1st, 2nd, ..., 53th | 7 |
|
|
3237
|
-
* | | II | 01, 02, ..., 53 | 7 |
|
|
3238
|
-
* | Day of month | d | 1, 2, ..., 31 | |
|
|
3239
|
-
* | | do | 1st, 2nd, ..., 31st | 7 |
|
|
3240
|
-
* | | dd | 01, 02, ..., 31 | |
|
|
3241
|
-
* | Day of year | D | 1, 2, ..., 365, 366 | 9 |
|
|
3242
|
-
* | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
|
|
3243
|
-
* | | DD | 01, 02, ..., 365, 366 | 9 |
|
|
3244
|
-
* | | DDD | 001, 002, ..., 365, 366 | |
|
|
3245
|
-
* | | DDDD | ... | 3 |
|
|
3246
|
-
* | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
|
|
3247
|
-
* | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
|
|
3248
|
-
* | | EEEEE | M, T, W, T, F, S, S | |
|
|
3249
|
-
* | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
3250
|
-
* | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
|
|
3251
|
-
* | | io | 1st, 2nd, ..., 7th | 7 |
|
|
3252
|
-
* | | ii | 01, 02, ..., 07 | 7 |
|
|
3253
|
-
* | | iii | Mon, Tue, Wed, ..., Sun | 7 |
|
|
3254
|
-
* | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
|
|
3255
|
-
* | | iiiii | M, T, W, T, F, S, S | 7 |
|
|
3256
|
-
* | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
|
|
3257
|
-
* | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
|
|
3258
|
-
* | | eo | 2nd, 3rd, ..., 1st | 7 |
|
|
3259
|
-
* | | ee | 02, 03, ..., 01 | |
|
|
3260
|
-
* | | eee | Mon, Tue, Wed, ..., Sun | |
|
|
3261
|
-
* | | eeee | Monday, Tuesday, ..., Sunday | 2 |
|
|
3262
|
-
* | | eeeee | M, T, W, T, F, S, S | |
|
|
3263
|
-
* | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
3264
|
-
* | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
|
|
3265
|
-
* | | co | 2nd, 3rd, ..., 1st | 7 |
|
|
3266
|
-
* | | cc | 02, 03, ..., 01 | |
|
|
3267
|
-
* | | ccc | Mon, Tue, Wed, ..., Sun | |
|
|
3268
|
-
* | | cccc | Monday, Tuesday, ..., Sunday | 2 |
|
|
3269
|
-
* | | ccccc | M, T, W, T, F, S, S | |
|
|
3270
|
-
* | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
|
|
3271
|
-
* | AM, PM | a..aa | AM, PM | |
|
|
3272
|
-
* | | aaa | am, pm | |
|
|
3273
|
-
* | | aaaa | a.m., p.m. | 2 |
|
|
3274
|
-
* | | aaaaa | a, p | |
|
|
3275
|
-
* | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
|
|
3276
|
-
* | | bbb | am, pm, noon, midnight | |
|
|
3277
|
-
* | | bbbb | a.m., p.m., noon, midnight | 2 |
|
|
3278
|
-
* | | bbbbb | a, p, n, mi | |
|
|
3279
|
-
* | Flexible day period | B..BBB | at night, in the morning, ... | |
|
|
3280
|
-
* | | BBBB | at night, in the morning, ... | 2 |
|
|
3281
|
-
* | | BBBBB | at night, in the morning, ... | |
|
|
3282
|
-
* | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
|
|
3283
|
-
* | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
|
|
3284
|
-
* | | hh | 01, 02, ..., 11, 12 | |
|
|
3285
|
-
* | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
|
|
3286
|
-
* | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
|
|
3287
|
-
* | | HH | 00, 01, 02, ..., 23 | |
|
|
3288
|
-
* | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
|
|
3289
|
-
* | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
|
|
3290
|
-
* | | KK | 01, 02, ..., 11, 00 | |
|
|
3291
|
-
* | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
|
|
3292
|
-
* | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
|
|
3293
|
-
* | | kk | 24, 01, 02, ..., 23 | |
|
|
3294
|
-
* | Minute | m | 0, 1, ..., 59 | |
|
|
3295
|
-
* | | mo | 0th, 1st, ..., 59th | 7 |
|
|
3296
|
-
* | | mm | 00, 01, ..., 59 | |
|
|
3297
|
-
* | Second | s | 0, 1, ..., 59 | |
|
|
3298
|
-
* | | so | 0th, 1st, ..., 59th | 7 |
|
|
3299
|
-
* | | ss | 00, 01, ..., 59 | |
|
|
3300
|
-
* | Fraction of second | S | 0, 1, ..., 9 | |
|
|
3301
|
-
* | | SS | 00, 01, ..., 99 | |
|
|
3302
|
-
* | | SSS | 000, 001, ..., 999 | |
|
|
3303
|
-
* | | SSSS | ... | 3 |
|
|
3304
|
-
* | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
|
|
3305
|
-
* | | XX | -0800, +0530, Z | |
|
|
3306
|
-
* | | XXX | -08:00, +05:30, Z | |
|
|
3307
|
-
* | | XXXX | -0800, +0530, Z, +123456 | 2 |
|
|
3308
|
-
* | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
|
|
3309
|
-
* | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
|
|
3310
|
-
* | | xx | -0800, +0530, +0000 | |
|
|
3311
|
-
* | | xxx | -08:00, +05:30, +00:00 | 2 |
|
|
3312
|
-
* | | xxxx | -0800, +0530, +0000, +123456 | |
|
|
3313
|
-
* | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
|
|
3314
|
-
* | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
|
|
3315
|
-
* | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
|
|
3316
|
-
* | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
|
|
3317
|
-
* | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
|
|
3318
|
-
* | Seconds timestamp | t | 512969520 | 7 |
|
|
3319
|
-
* | | tt | ... | 3,7 |
|
|
3320
|
-
* | Milliseconds timestamp | T | 512969520900 | 7 |
|
|
3321
|
-
* | | TT | ... | 3,7 |
|
|
3322
|
-
* | Long localized date | P | 04/29/1453 | 7 |
|
|
3323
|
-
* | | PP | Apr 29, 1453 | 7 |
|
|
3324
|
-
* | | PPP | April 29th, 1453 | 7 |
|
|
3325
|
-
* | | PPPP | Friday, April 29th, 1453 | 2,7 |
|
|
3326
|
-
* | Long localized time | p | 12:00 AM | 7 |
|
|
3327
|
-
* | | pp | 12:00:00 AM | 7 |
|
|
3328
|
-
* | | ppp | 12:00:00 AM GMT+2 | 7 |
|
|
3329
|
-
* | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
|
|
3330
|
-
* | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
|
|
3331
|
-
* | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
|
|
3332
|
-
* | | PPPppp | April 29th, 1453 at ... | 7 |
|
|
3333
|
-
* | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
|
|
3334
|
-
* Notes:
|
|
3335
|
-
* 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
|
|
3336
|
-
* are the same as "stand-alone" units, but are different in some languages.
|
|
3337
|
-
* "Formatting" units are declined according to the rules of the language
|
|
3338
|
-
* in the context of a date. "Stand-alone" units are always nominative singular:
|
|
3339
|
-
*
|
|
3340
|
-
* `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
|
|
3341
|
-
*
|
|
3342
|
-
* `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
|
|
3343
|
-
*
|
|
3344
|
-
* 2. Any sequence of the identical letters is a pattern, unless it is escaped by
|
|
3345
|
-
* the single quote characters (see below).
|
|
3346
|
-
* If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
|
|
3347
|
-
* the output will be the same as default pattern for this unit, usually
|
|
3348
|
-
* the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
|
|
3349
|
-
* are marked with "2" in the last column of the table.
|
|
3350
|
-
*
|
|
3351
|
-
* `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
|
|
3352
|
-
*
|
|
3353
|
-
* `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
|
|
3354
|
-
*
|
|
3355
|
-
* `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
|
|
3356
|
-
*
|
|
3357
|
-
* `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
|
|
3358
|
-
*
|
|
3359
|
-
* `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
|
|
3360
|
-
*
|
|
3361
|
-
* 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
|
|
3362
|
-
* The output will be padded with zeros to match the length of the pattern.
|
|
3363
|
-
*
|
|
3364
|
-
* `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
|
|
3365
|
-
*
|
|
3366
|
-
* 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
|
|
3367
|
-
* These tokens represent the shortest form of the quarter.
|
|
3368
|
-
*
|
|
3369
|
-
* 5. The main difference between `y` and `u` patterns are B.C. years:
|
|
3370
|
-
*
|
|
3371
|
-
* | Year | `y` | `u` |
|
|
3372
|
-
* |------|-----|-----|
|
|
3373
|
-
* | AC 1 | 1 | 1 |
|
|
3374
|
-
* | BC 1 | 1 | 0 |
|
|
3375
|
-
* | BC 2 | 2 | -1 |
|
|
3376
|
-
*
|
|
3377
|
-
* Also `yy` always returns the last two digits of a year,
|
|
3378
|
-
* while `uu` pads single digit years to 2 characters and returns other years unchanged:
|
|
3379
|
-
*
|
|
3380
|
-
* | Year | `yy` | `uu` |
|
|
3381
|
-
* |------|------|------|
|
|
3382
|
-
* | 1 | 01 | 01 |
|
|
3383
|
-
* | 14 | 14 | 14 |
|
|
3384
|
-
* | 376 | 76 | 376 |
|
|
3385
|
-
* | 1453 | 53 | 1453 |
|
|
3386
|
-
*
|
|
3387
|
-
* The same difference is true for local and ISO week-numbering years (`Y` and `R`),
|
|
3388
|
-
* except local week-numbering years are dependent on `options.weekStartsOn`
|
|
3389
|
-
* and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear)
|
|
3390
|
-
* and [getWeekYear](https://date-fns.org/docs/getWeekYear)).
|
|
3391
|
-
*
|
|
3392
|
-
* 6. Specific non-location timezones are currently unavailable in `date-fns`,
|
|
3393
|
-
* so right now these tokens fall back to GMT timezones.
|
|
3394
|
-
*
|
|
3395
|
-
* 7. These patterns are not in the Unicode Technical Standard #35:
|
|
3396
|
-
* - `i`: ISO day of week
|
|
3397
|
-
* - `I`: ISO week of year
|
|
3398
|
-
* - `R`: ISO week-numbering year
|
|
3399
|
-
* - `t`: seconds timestamp
|
|
3400
|
-
* - `T`: milliseconds timestamp
|
|
3401
|
-
* - `o`: ordinal number modifier
|
|
3402
|
-
* - `P`: long localized date
|
|
3403
|
-
* - `p`: long localized time
|
|
3404
|
-
*
|
|
3405
|
-
* 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
|
|
3406
|
-
* You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
3407
|
-
*
|
|
3408
|
-
* 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
|
|
3409
|
-
* You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
3410
|
-
*
|
|
3411
|
-
* @param date - The original date
|
|
3412
|
-
* @param format - The string of tokens
|
|
3413
|
-
* @param options - An object with options
|
|
3414
|
-
*
|
|
3415
|
-
* @returns The formatted date string
|
|
3416
|
-
*
|
|
3417
|
-
* @throws `date` must not be Invalid Date
|
|
3418
|
-
* @throws `options.locale` must contain `localize` property
|
|
3419
|
-
* @throws `options.locale` must contain `formatLong` property
|
|
3420
|
-
* @throws use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
3421
|
-
* @throws use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
3422
|
-
* @throws use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
3423
|
-
* @throws use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
|
|
3424
|
-
* @throws format string contains an unescaped latin alphabet character
|
|
3425
|
-
*
|
|
3426
|
-
* @example
|
|
3427
|
-
* // Represent 11 February 2014 in middle-endian format:
|
|
3428
|
-
* const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
|
|
3429
|
-
* //=> '02/11/2014'
|
|
3430
|
-
*
|
|
3431
|
-
* @example
|
|
3432
|
-
* // Represent 2 July 2014 in Esperanto:
|
|
3433
|
-
* import { eoLocale } from 'date-fns/locale/eo'
|
|
3434
|
-
* const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
|
|
3435
|
-
* locale: eoLocale
|
|
3436
|
-
* })
|
|
3437
|
-
* //=> '2-a de julio 2014'
|
|
3438
|
-
*
|
|
3439
|
-
* @example
|
|
3440
|
-
* // Escape string by single quote characters:
|
|
3441
|
-
* const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
|
|
3442
|
-
* //=> "3 o'clock"
|
|
3443
|
-
*/ function format(date, formatStr, options) {
|
|
3444
|
-
const defaultOptions = getDefaultOptions();
|
|
3445
|
-
const locale = options?.locale ?? defaultOptions.locale ?? enUS;
|
|
3446
|
-
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;
|
|
3447
|
-
const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions.weekStartsOn ?? defaultOptions.locale?.options?.weekStartsOn ?? 0;
|
|
3448
|
-
const originalDate = toDate(date, options?.in);
|
|
3449
|
-
if (!isValid(originalDate)) {
|
|
3450
|
-
throw new RangeError("Invalid time value");
|
|
3451
|
-
}
|
|
3452
|
-
let parts = formatStr.match(longFormattingTokensRegExp).map((substring)=>{
|
|
3453
|
-
const firstCharacter = substring[0];
|
|
3454
|
-
if (firstCharacter === "p" || firstCharacter === "P") {
|
|
3455
|
-
const longFormatter = longFormatters[firstCharacter];
|
|
3456
|
-
return longFormatter(substring, locale.formatLong);
|
|
3457
|
-
}
|
|
3458
|
-
return substring;
|
|
3459
|
-
}).join("").match(formattingTokensRegExp).map((substring)=>{
|
|
3460
|
-
// Replace two single quote characters with one single quote character
|
|
3461
|
-
if (substring === "''") {
|
|
3462
|
-
return {
|
|
3463
|
-
isToken: false,
|
|
3464
|
-
value: "'"
|
|
3465
|
-
};
|
|
3466
|
-
}
|
|
3467
|
-
const firstCharacter = substring[0];
|
|
3468
|
-
if (firstCharacter === "'") {
|
|
3469
|
-
return {
|
|
3470
|
-
isToken: false,
|
|
3471
|
-
value: cleanEscapedString(substring)
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
if (formatters[firstCharacter]) {
|
|
3475
|
-
return {
|
|
3476
|
-
isToken: true,
|
|
3477
|
-
value: substring
|
|
3478
|
-
};
|
|
3479
|
-
}
|
|
3480
|
-
if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
|
|
3481
|
-
throw new RangeError("Format string contains an unescaped latin alphabet character `" + firstCharacter + "`");
|
|
3482
|
-
}
|
|
3483
|
-
return {
|
|
3484
|
-
isToken: false,
|
|
3485
|
-
value: substring
|
|
3486
|
-
};
|
|
3487
|
-
});
|
|
3488
|
-
// invoke localize preprocessor (only for french locales at the moment)
|
|
3489
|
-
if (locale.localize.preprocessor) {
|
|
3490
|
-
parts = locale.localize.preprocessor(originalDate, parts);
|
|
3491
|
-
}
|
|
3492
|
-
const formatterOptions = {
|
|
3493
|
-
firstWeekContainsDate,
|
|
3494
|
-
weekStartsOn,
|
|
3495
|
-
locale
|
|
3496
|
-
};
|
|
3497
|
-
return parts.map((part)=>{
|
|
3498
|
-
if (!part.isToken) return part.value;
|
|
3499
|
-
const token = part.value;
|
|
3500
|
-
if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token) || !options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) {
|
|
3501
|
-
warnOrThrowProtectedError(token, formatStr, String(date));
|
|
3502
|
-
}
|
|
3503
|
-
const formatter = formatters[token[0]];
|
|
3504
|
-
return formatter(originalDate, token, locale.localize, formatterOptions);
|
|
3505
|
-
}).join("");
|
|
3506
|
-
}
|
|
3507
|
-
function cleanEscapedString(input) {
|
|
3508
|
-
const matched = input.match(escapedStringRegExp);
|
|
3509
|
-
if (!matched) {
|
|
3510
|
-
return input;
|
|
3511
|
-
}
|
|
3512
|
-
return matched[1].replace(doubleQuoteRegExp, "'");
|
|
3513
|
-
}
|
|
3514
|
-
|
|
3515
882
|
/**
|
|
3516
883
|
* The {@link getDaysInMonth} function options.
|
|
3517
884
|
*/ /**
|
|
@@ -7267,5 +4634,5 @@ function CalendarDayButton({ className, day, modifiers, ...props }) {
|
|
|
7267
4634
|
});
|
|
7268
4635
|
}
|
|
7269
4636
|
|
|
7270
|
-
export { Calendar as C, CalendarDayButton as a
|
|
7271
|
-
//# sourceMappingURL=calendar-
|
|
4637
|
+
export { Calendar as C, CalendarDayButton as a };
|
|
4638
|
+
//# sourceMappingURL=calendar-BQgywKTj.mjs.map
|