wedux-ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +184 -0
- package/miniprogram_dist/behaviors/formField.js +35 -0
- package/miniprogram_dist/components/avatar/avatar.js +70 -0
- package/miniprogram_dist/components/avatar/avatar.json +4 -0
- package/miniprogram_dist/components/avatar/avatar.scss +68 -0
- package/miniprogram_dist/components/avatar/avatar.wxml +15 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.js +45 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.json +7 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.scss +4 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.wxml +3 -0
- package/miniprogram_dist/components/back-top/back-top.js +68 -0
- package/miniprogram_dist/components/back-top/back-top.json +4 -0
- package/miniprogram_dist/components/back-top/back-top.scss +43 -0
- package/miniprogram_dist/components/back-top/back-top.wxml +10 -0
- package/miniprogram_dist/components/badge/badge.js +100 -0
- package/miniprogram_dist/components/badge/badge.json +4 -0
- package/miniprogram_dist/components/badge/badge.scss +98 -0
- package/miniprogram_dist/components/badge/badge.wxml +11 -0
- package/miniprogram_dist/components/button/button.js +152 -0
- package/miniprogram_dist/components/button/button.json +4 -0
- package/miniprogram_dist/components/button/button.scss +499 -0
- package/miniprogram_dist/components/button/button.wxml +21 -0
- package/miniprogram_dist/components/button-group/button-group.js +51 -0
- package/miniprogram_dist/components/button-group/button-group.json +4 -0
- package/miniprogram_dist/components/button-group/button-group.scss +8 -0
- package/miniprogram_dist/components/button-group/button-group.wxml +3 -0
- package/miniprogram_dist/components/calendar/calendar.js +308 -0
- package/miniprogram_dist/components/calendar/calendar.json +4 -0
- package/miniprogram_dist/components/calendar/calendar.scss +141 -0
- package/miniprogram_dist/components/calendar/calendar.wxml +47 -0
- package/miniprogram_dist/components/card/card.js +44 -0
- package/miniprogram_dist/components/card/card.json +4 -0
- package/miniprogram_dist/components/card/card.scss +143 -0
- package/miniprogram_dist/components/card/card.wxml +31 -0
- package/miniprogram_dist/components/checkbox/checkbox.js +43 -0
- package/miniprogram_dist/components/checkbox/checkbox.json +4 -0
- package/miniprogram_dist/components/checkbox/checkbox.scss +77 -0
- package/miniprogram_dist/components/checkbox/checkbox.wxml +13 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.js +43 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.json +4 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.scss +39 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.wxml +8 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.js +84 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.json +4 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.scss +9 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.wxml +3 -0
- package/miniprogram_dist/components/color-picker/color-picker.js +348 -0
- package/miniprogram_dist/components/color-picker/color-picker.json +7 -0
- package/miniprogram_dist/components/color-picker/color-picker.scss +383 -0
- package/miniprogram_dist/components/color-picker/color-picker.wxml +232 -0
- package/miniprogram_dist/components/date-picker/date-picker.js +1289 -0
- package/miniprogram_dist/components/date-picker/date-picker.json +7 -0
- package/miniprogram_dist/components/date-picker/date-picker.scss +468 -0
- package/miniprogram_dist/components/date-picker/date-picker.wxml +214 -0
- package/miniprogram_dist/components/divider/divider.js +34 -0
- package/miniprogram_dist/components/divider/divider.json +4 -0
- package/miniprogram_dist/components/divider/divider.scss +75 -0
- package/miniprogram_dist/components/divider/divider.wxml +8 -0
- package/miniprogram_dist/components/drawer/drawer.js +104 -0
- package/miniprogram_dist/components/drawer/drawer.json +4 -0
- package/miniprogram_dist/components/drawer/drawer.scss +171 -0
- package/miniprogram_dist/components/drawer/drawer.wxml +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.js +38 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.json +4 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.scss +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.wxml +7 -0
- package/miniprogram_dist/components/flex/flex.js +81 -0
- package/miniprogram_dist/components/flex/flex.json +4 -0
- package/miniprogram_dist/components/flex/flex.scss +4 -0
- package/miniprogram_dist/components/flex/flex.wxml +3 -0
- package/miniprogram_dist/components/float-button/float-button.js +78 -0
- package/miniprogram_dist/components/float-button/float-button.json +4 -0
- package/miniprogram_dist/components/float-button/float-button.scss +54 -0
- package/miniprogram_dist/components/float-button/float-button.wxml +9 -0
- package/miniprogram_dist/components/form/form.js +142 -0
- package/miniprogram_dist/components/form/form.json +4 -0
- package/miniprogram_dist/components/form/form.scss +11 -0
- package/miniprogram_dist/components/form/form.wxml +3 -0
- package/miniprogram_dist/components/form/validator.js +220 -0
- package/miniprogram_dist/components/form-item/form-item.js +240 -0
- package/miniprogram_dist/components/form-item/form-item.json +4 -0
- package/miniprogram_dist/components/form-item/form-item.scss +59 -0
- package/miniprogram_dist/components/form-item/form-item.wxml +33 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.js +54 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.json +4 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.scss +7 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.wxml +1 -0
- package/miniprogram_dist/components/h/h.js +60 -0
- package/miniprogram_dist/components/h/h.json +4 -0
- package/miniprogram_dist/components/h/h.scss +53 -0
- package/miniprogram_dist/components/h/h.wxml +1 -0
- package/miniprogram_dist/components/highlight/highlight.js +77 -0
- package/miniprogram_dist/components/highlight/highlight.json +4 -0
- package/miniprogram_dist/components/highlight/highlight.scss +8 -0
- package/miniprogram_dist/components/highlight/highlight.wxml +12 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.js +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.json +4 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.scss +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.wxml +12 -0
- package/miniprogram_dist/components/input/input.js +59 -0
- package/miniprogram_dist/components/input/input.json +4 -0
- package/miniprogram_dist/components/input/input.scss +96 -0
- package/miniprogram_dist/components/input/input.wxml +34 -0
- package/miniprogram_dist/components/input-otp/input-otp.js +106 -0
- package/miniprogram_dist/components/input-otp/input-otp.json +4 -0
- package/miniprogram_dist/components/input-otp/input-otp.scss +122 -0
- package/miniprogram_dist/components/input-otp/input-otp.wxml +38 -0
- package/miniprogram_dist/components/layout/layout.js +50 -0
- package/miniprogram_dist/components/layout/layout.json +4 -0
- package/miniprogram_dist/components/layout/layout.scss +10 -0
- package/miniprogram_dist/components/layout/layout.wxml +3 -0
- package/miniprogram_dist/components/layout-content/layout-content.js +47 -0
- package/miniprogram_dist/components/layout-content/layout-content.json +4 -0
- package/miniprogram_dist/components/layout-content/layout-content.scss +5 -0
- package/miniprogram_dist/components/layout-content/layout-content.wxml +13 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.js +59 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.json +4 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.scss +23 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.wxml +16 -0
- package/miniprogram_dist/components/layout-header/layout-header.js +59 -0
- package/miniprogram_dist/components/layout-header/layout-header.json +4 -0
- package/miniprogram_dist/components/layout-header/layout-header.scss +23 -0
- package/miniprogram_dist/components/layout-header/layout-header.wxml +16 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.js +48 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.json +4 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.scss +13 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.wxml +5 -0
- package/miniprogram_dist/components/list/list.js +55 -0
- package/miniprogram_dist/components/list/list.json +4 -0
- package/miniprogram_dist/components/list/list.scss +51 -0
- package/miniprogram_dist/components/list/list.wxml +9 -0
- package/miniprogram_dist/components/list-item/list-item.js +24 -0
- package/miniprogram_dist/components/list-item/list-item.json +4 -0
- package/miniprogram_dist/components/list-item/list-item.scss +51 -0
- package/miniprogram_dist/components/list-item/list-item.wxml +14 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.js +77 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.json +4 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.scss +63 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.wxml +35 -0
- package/miniprogram_dist/components/number-animation/number-animation.js +124 -0
- package/miniprogram_dist/components/number-animation/number-animation.json +4 -0
- package/miniprogram_dist/components/number-animation/number-animation.scss +3 -0
- package/miniprogram_dist/components/number-animation/number-animation.wxml +1 -0
- package/miniprogram_dist/components/popover/popover.js +183 -0
- package/miniprogram_dist/components/popover/popover.json +4 -0
- package/miniprogram_dist/components/popover/popover.scss +69 -0
- package/miniprogram_dist/components/popover/popover.wxml +19 -0
- package/miniprogram_dist/components/qr-code/qr-code.js +216 -0
- package/miniprogram_dist/components/qr-code/qr-code.json +4 -0
- package/miniprogram_dist/components/qr-code/qr-code.scss +8 -0
- package/miniprogram_dist/components/qr-code/qr-code.wxml +16 -0
- package/miniprogram_dist/components/radio/radio.js +38 -0
- package/miniprogram_dist/components/radio/radio.json +4 -0
- package/miniprogram_dist/components/radio/radio.scss +50 -0
- package/miniprogram_dist/components/radio/radio.wxml +12 -0
- package/miniprogram_dist/components/radio-button/radio-button.js +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.json +4 -0
- package/miniprogram_dist/components/radio-button/radio-button.scss +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.wxml +8 -0
- package/miniprogram_dist/components/radio-group/radio-group.js +72 -0
- package/miniprogram_dist/components/radio-group/radio-group.json +4 -0
- package/miniprogram_dist/components/radio-group/radio-group.scss +9 -0
- package/miniprogram_dist/components/radio-group/radio-group.wxml +3 -0
- package/miniprogram_dist/components/rate/rate.js +90 -0
- package/miniprogram_dist/components/rate/rate.json +4 -0
- package/miniprogram_dist/components/rate/rate.scss +59 -0
- package/miniprogram_dist/components/rate/rate.wxml +16 -0
- package/miniprogram_dist/components/select/select.js +201 -0
- package/miniprogram_dist/components/select/select.json +7 -0
- package/miniprogram_dist/components/select/select.scss +235 -0
- package/miniprogram_dist/components/select/select.wxml +79 -0
- package/miniprogram_dist/components/stepper/stepper.js +113 -0
- package/miniprogram_dist/components/stepper/stepper.json +4 -0
- package/miniprogram_dist/components/stepper/stepper.scss +73 -0
- package/miniprogram_dist/components/stepper/stepper.wxml +23 -0
- package/miniprogram_dist/components/switch/switch.js +42 -0
- package/miniprogram_dist/components/switch/switch.json +4 -0
- package/miniprogram_dist/components/switch/switch.scss +77 -0
- package/miniprogram_dist/components/switch/switch.wxml +10 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.js +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.json +4 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.scss +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.wxml +12 -0
- package/miniprogram_dist/components/tag/tag.js +87 -0
- package/miniprogram_dist/components/tag/tag.json +4 -0
- package/miniprogram_dist/components/tag/tag.scss +138 -0
- package/miniprogram_dist/components/tag/tag.wxml +12 -0
- package/miniprogram_dist/components/textarea/textarea.js +46 -0
- package/miniprogram_dist/components/textarea/textarea.json +4 -0
- package/miniprogram_dist/components/textarea/textarea.scss +51 -0
- package/miniprogram_dist/components/textarea/textarea.wxml +20 -0
- package/miniprogram_dist/components/theme-provider/presets.js +101 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.js +34 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.json +4 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.scss +3 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.wxml +3 -0
- package/miniprogram_dist/components/time-picker/time-picker.js +136 -0
- package/miniprogram_dist/components/time-picker/time-picker.json +7 -0
- package/miniprogram_dist/components/time-picker/time-picker.scss +135 -0
- package/miniprogram_dist/components/time-picker/time-picker.wxml +47 -0
- package/miniprogram_dist/components/tooltip/tooltip.js +179 -0
- package/miniprogram_dist/components/tooltip/tooltip.json +4 -0
- package/miniprogram_dist/components/tooltip/tooltip.scss +66 -0
- package/miniprogram_dist/components/tooltip/tooltip.wxml +17 -0
- package/miniprogram_dist/components/tree/tree.js +647 -0
- package/miniprogram_dist/components/tree/tree.json +4 -0
- package/miniprogram_dist/components/tree/tree.scss +178 -0
- package/miniprogram_dist/components/tree/tree.wxml +59 -0
- package/miniprogram_dist/components/tree-select/tree-select.js +260 -0
- package/miniprogram_dist/components/tree-select/tree-select.json +8 -0
- package/miniprogram_dist/components/tree-select/tree-select.scss +250 -0
- package/miniprogram_dist/components/tree-select/tree-select.wxml +118 -0
- package/miniprogram_dist/components/upload/upload.js +387 -0
- package/miniprogram_dist/components/upload/upload.json +4 -0
- package/miniprogram_dist/components/upload/upload.scss +258 -0
- package/miniprogram_dist/components/upload/upload.wxml +142 -0
- package/miniprogram_dist/components/watermark/watermark.js +260 -0
- package/miniprogram_dist/components/watermark/watermark.json +4 -0
- package/miniprogram_dist/components/watermark/watermark.scss +35 -0
- package/miniprogram_dist/components/watermark/watermark.wxml +13 -0
- package/miniprogram_dist/libs/qrcodegen.js +714 -0
- package/miniprogram_dist/libs/seemly.min.js +547 -0
- package/miniprogram_dist/libs/tempo_1_0_0.js +1264 -0
- package/miniprogram_dist/libs/validator_13_56_26.min.js +5282 -0
- package/miniprogram_dist/styles/demo.scss +96 -0
- package/miniprogram_dist/styles/iconfont.scss +91 -0
- package/miniprogram_dist/styles/theme.scss +126 -0
- package/miniprogram_dist/styles/tokens.scss +292 -0
- package/miniprogram_dist/utils/relations.js +21 -0
- package/package.json +25 -0
|
@@ -0,0 +1,1264 @@
|
|
|
1
|
+
// src/iso8601.ts
|
|
2
|
+
var iso8601Match =
|
|
3
|
+
/^([0-9]{4})-([0-1][0-9])(?:-([0-3][0-9]))?(?:[T ]?([0-2][0-9])(?::([0-5][0-9]))?(?::([0-5][0-9]))?)?(?:\.[0-9]+)?(Z|(?:\+|\-)[0-9]{2}:?[0-9]{2}(?::?[0-9]{2})?)?$/;
|
|
4
|
+
function iso8601(date2) {
|
|
5
|
+
const matches = date2.match(iso8601Match);
|
|
6
|
+
if (matches) {
|
|
7
|
+
const month = Number(matches[2]);
|
|
8
|
+
if (month < 1 || month > 12) return false;
|
|
9
|
+
if (typeof matches[3] !== void 0) {
|
|
10
|
+
const date3 = Number(matches[3]);
|
|
11
|
+
if (date3 < 1 || date3 > 31) return false;
|
|
12
|
+
}
|
|
13
|
+
if (typeof matches[4] !== void 0) {
|
|
14
|
+
const hours = Number(matches[4]);
|
|
15
|
+
if (hours < 0 || hours > 23) return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/date.ts
|
|
23
|
+
function normalize(date2) {
|
|
24
|
+
const matches = date2.match(iso8601Match);
|
|
25
|
+
if (matches && typeof matches[4] === 'undefined') {
|
|
26
|
+
return (date2 += 'T00:00:00');
|
|
27
|
+
}
|
|
28
|
+
return date2;
|
|
29
|
+
}
|
|
30
|
+
function date(date2) {
|
|
31
|
+
if (!date2) {
|
|
32
|
+
date2 = /* @__PURE__ */ new Date();
|
|
33
|
+
}
|
|
34
|
+
if (date2 instanceof Date) {
|
|
35
|
+
return new Date(date2);
|
|
36
|
+
}
|
|
37
|
+
date2 = date2.trim();
|
|
38
|
+
if (iso8601(date2)) {
|
|
39
|
+
return new Date(normalize(date2));
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Non ISO 8601 compliant date (${date2}).`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/addDay.ts
|
|
45
|
+
function addDay(inputDate, count = 1) {
|
|
46
|
+
const d = date(inputDate);
|
|
47
|
+
d.setDate(d.getDate() + count);
|
|
48
|
+
return d;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/monthEnd.ts
|
|
52
|
+
function monthEnd(inputDate) {
|
|
53
|
+
const d = date(inputDate);
|
|
54
|
+
d.setDate(1);
|
|
55
|
+
d.setMonth(d.getMonth() + 1);
|
|
56
|
+
d.setDate(0);
|
|
57
|
+
return d;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/monthDays.ts
|
|
61
|
+
function monthDays(inputDate) {
|
|
62
|
+
const d = monthEnd(inputDate);
|
|
63
|
+
return d.getDate();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/addMonth.ts
|
|
67
|
+
function addMonth(inputDate, count = 1, dateOverflow = false) {
|
|
68
|
+
const d = date(inputDate);
|
|
69
|
+
const dayOfMonth = d.getDate();
|
|
70
|
+
if (!dateOverflow) d.setDate(1);
|
|
71
|
+
d.setMonth(d.getMonth() + count);
|
|
72
|
+
if (!dateOverflow) {
|
|
73
|
+
const daysInMonth = monthDays(d);
|
|
74
|
+
d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth);
|
|
75
|
+
}
|
|
76
|
+
return d;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/addYear.ts
|
|
80
|
+
function addYear(inputDate, count = 1, dateOverflow = false) {
|
|
81
|
+
const d = date(inputDate);
|
|
82
|
+
const dayOfMonth = d.getDate();
|
|
83
|
+
if (!dateOverflow) d.setDate(1);
|
|
84
|
+
d.setFullYear(d.getFullYear() + count);
|
|
85
|
+
if (!dateOverflow) {
|
|
86
|
+
const daysInMonth = monthDays(d);
|
|
87
|
+
d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth);
|
|
88
|
+
}
|
|
89
|
+
return d;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/addHour.ts
|
|
93
|
+
function addHour(inputDate, count = 1) {
|
|
94
|
+
const d = date(inputDate);
|
|
95
|
+
d.setHours(d.getHours() + count);
|
|
96
|
+
return d;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/addMinute.ts
|
|
100
|
+
function addMinute(inputDate, count = 1) {
|
|
101
|
+
const d = date(inputDate);
|
|
102
|
+
d.setMinutes(d.getMinutes() + count);
|
|
103
|
+
return d;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/addSecond.ts
|
|
107
|
+
function addSecond(inputDate, count = 1) {
|
|
108
|
+
const d = date(inputDate);
|
|
109
|
+
d.setSeconds(d.getSeconds() + count);
|
|
110
|
+
return d;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/addMillisecond.ts
|
|
114
|
+
function addMillisecond(inputDate, count = 1) {
|
|
115
|
+
const d = date(inputDate);
|
|
116
|
+
d.setMilliseconds(d.getMilliseconds() + count);
|
|
117
|
+
return d;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/common.ts
|
|
121
|
+
var specDate = '1999-03-04T02:05:01.000Z';
|
|
122
|
+
var memoParts = /* @__PURE__ */ new Map();
|
|
123
|
+
var clockAgnostic = [
|
|
124
|
+
['YYYY', { year: 'numeric' }],
|
|
125
|
+
['YY', { year: '2-digit' }],
|
|
126
|
+
['MMMM', { month: 'long' }],
|
|
127
|
+
['MMM', { month: 'short' }],
|
|
128
|
+
['MM', { month: '2-digit' }],
|
|
129
|
+
['M', { month: 'numeric' }],
|
|
130
|
+
['DD', { day: '2-digit' }],
|
|
131
|
+
['D', { day: 'numeric' }],
|
|
132
|
+
['dddd', { weekday: 'long' }],
|
|
133
|
+
['ddd', { weekday: 'short' }],
|
|
134
|
+
['d', { weekday: 'narrow' }],
|
|
135
|
+
['mm', { minute: '2-digit' }],
|
|
136
|
+
['m', { minute: 'numeric' }],
|
|
137
|
+
['ss', { second: '2-digit' }],
|
|
138
|
+
['s', { second: 'numeric' }],
|
|
139
|
+
['ZZ', { timeZoneName: 'long' }],
|
|
140
|
+
['Z', { timeZoneName: 'short' }],
|
|
141
|
+
];
|
|
142
|
+
var clock24 = [
|
|
143
|
+
['HH', { hour: '2-digit' }],
|
|
144
|
+
['H', { hour: 'numeric' }],
|
|
145
|
+
];
|
|
146
|
+
var clock12 = [
|
|
147
|
+
['hh', { hour: '2-digit' }],
|
|
148
|
+
['h', { hour: 'numeric' }],
|
|
149
|
+
['a', { dayPeriod: 'narrow' }],
|
|
150
|
+
['A', { dayPeriod: 'narrow' }],
|
|
151
|
+
];
|
|
152
|
+
var fractionalSeconds = [['SSS', { fractionalSecond: '3-digit' }]];
|
|
153
|
+
var fixedLength = {
|
|
154
|
+
DD: 2,
|
|
155
|
+
HH: 2,
|
|
156
|
+
MM: 2,
|
|
157
|
+
YY: 2,
|
|
158
|
+
YYYY: 4,
|
|
159
|
+
hh: 2,
|
|
160
|
+
mm: 2,
|
|
161
|
+
ss: 2,
|
|
162
|
+
};
|
|
163
|
+
function fixedLengthByOffset(offsetString) {
|
|
164
|
+
if (/^[+-]\d{2}:\d{2}:\d{2}/.test(offsetString)) {
|
|
165
|
+
return 9;
|
|
166
|
+
}
|
|
167
|
+
if (/^[+-]\d{6}/.test(offsetString)) {
|
|
168
|
+
return 8;
|
|
169
|
+
}
|
|
170
|
+
if (/^[+-]\d{2}:\d{2}/.test(offsetString)) {
|
|
171
|
+
return 6;
|
|
172
|
+
}
|
|
173
|
+
if (/^[+-]\d{4}/.test(offsetString)) {
|
|
174
|
+
return 5;
|
|
175
|
+
}
|
|
176
|
+
throw new Error('Invalid offset format');
|
|
177
|
+
}
|
|
178
|
+
var genitiveTokens = ['MMMM', 'MMM', 'dddd', 'ddd'];
|
|
179
|
+
var tokens = /* @__PURE__ */ new Map(
|
|
180
|
+
/* @__PURE__ */ [...clockAgnostic, ...clock24, ...clock12, ...fractionalSeconds].map(
|
|
181
|
+
(format2) => {
|
|
182
|
+
return [format2[0], format2];
|
|
183
|
+
},
|
|
184
|
+
),
|
|
185
|
+
);
|
|
186
|
+
var dayPeriodMap = /* @__PURE__ */ new Map();
|
|
187
|
+
var styles = ['full', 'long', 'medium', 'short'];
|
|
188
|
+
var two = (n) => String(n).padStart(2, '0');
|
|
189
|
+
var four = (n) => String(n).padStart(2, '0');
|
|
190
|
+
function normStr(part) {
|
|
191
|
+
if (part.type === 'literal') {
|
|
192
|
+
part.value = part.value.normalize('NFKC');
|
|
193
|
+
}
|
|
194
|
+
return part;
|
|
195
|
+
}
|
|
196
|
+
function fill(inputDate, parts2, locale, genitive = false, offset2 = null) {
|
|
197
|
+
const partMap = createPartMap(inputDate, parts2, locale, genitive);
|
|
198
|
+
const d = date(inputDate);
|
|
199
|
+
function value({ partName, partValue, token }) {
|
|
200
|
+
if (partName === 'literal') return partValue;
|
|
201
|
+
const value2 = partMap[partName];
|
|
202
|
+
if (partName === 'hour' && token === 'H') {
|
|
203
|
+
return value2.replace(/^0/, '') || '0';
|
|
204
|
+
}
|
|
205
|
+
if (['mm', 'ss', 'MM'].includes(token) && value2.length === 1) {
|
|
206
|
+
return `0${value2}`;
|
|
207
|
+
}
|
|
208
|
+
if (partName === 'dayPeriod') {
|
|
209
|
+
const p = ap(d.getUTCHours() < 12 ? 'am' : 'pm', locale);
|
|
210
|
+
return token === 'A' ? p.toUpperCase() : p.toLowerCase();
|
|
211
|
+
}
|
|
212
|
+
if (partName === 'fractionalSecond') {
|
|
213
|
+
return String(d.getUTCMilliseconds()).padStart(3, '0');
|
|
214
|
+
}
|
|
215
|
+
if (partName === 'timeZoneName') {
|
|
216
|
+
return offset2 != null ? offset2 : minsToOffset(-1 * d.getTimezoneOffset(), token);
|
|
217
|
+
}
|
|
218
|
+
return value2;
|
|
219
|
+
}
|
|
220
|
+
return parts2.map((part) => {
|
|
221
|
+
return {
|
|
222
|
+
...part,
|
|
223
|
+
value: value(part),
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function createPartMap(inputDate, parts2, locale, genitive = false) {
|
|
228
|
+
const d = date(inputDate);
|
|
229
|
+
const hour12 = parts2.filter((part) => part.hour12);
|
|
230
|
+
const hour24 = parts2.filter((part) => !part.hour12);
|
|
231
|
+
const valueParts = [];
|
|
232
|
+
const genitiveParts = [];
|
|
233
|
+
function addValues(requestedParts, hour122 = false) {
|
|
234
|
+
const preciseLocale = `${locale}-u-hc-${hour122 ? 'h12' : 'h23'}`;
|
|
235
|
+
valueParts.push(
|
|
236
|
+
...new Intl.DateTimeFormat(
|
|
237
|
+
preciseLocale,
|
|
238
|
+
requestedParts.reduce(
|
|
239
|
+
(options, part) => {
|
|
240
|
+
if (part.partName === 'literal') return options;
|
|
241
|
+
if (genitive && genitiveTokens.includes(part.token)) {
|
|
242
|
+
genitiveParts.push(part);
|
|
243
|
+
}
|
|
244
|
+
return Object.assign(options, part.option);
|
|
245
|
+
},
|
|
246
|
+
{ timeZone: 'UTC' },
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
.formatToParts(d)
|
|
250
|
+
.map(normStr),
|
|
251
|
+
);
|
|
252
|
+
if (genitive && genitiveParts.length) {
|
|
253
|
+
for (const part of genitiveParts) {
|
|
254
|
+
let formattedParts = [];
|
|
255
|
+
switch (part.token) {
|
|
256
|
+
case 'MMMM':
|
|
257
|
+
formattedParts = new Intl.DateTimeFormat(preciseLocale, {
|
|
258
|
+
dateStyle: 'long',
|
|
259
|
+
timeZone: 'UTC',
|
|
260
|
+
})
|
|
261
|
+
.formatToParts(d)
|
|
262
|
+
.map(normStr);
|
|
263
|
+
break;
|
|
264
|
+
case 'MMM':
|
|
265
|
+
formattedParts = new Intl.DateTimeFormat(preciseLocale, {
|
|
266
|
+
dateStyle: 'medium',
|
|
267
|
+
timeZone: 'UTC',
|
|
268
|
+
})
|
|
269
|
+
.formatToParts(d)
|
|
270
|
+
.map(normStr);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
const genitiveFormattedPart = formattedParts.find((p) => p.type === part.partName);
|
|
274
|
+
const index = valueParts.findIndex((p) => p.type === part.partName);
|
|
275
|
+
if (genitiveFormattedPart && index > -1) {
|
|
276
|
+
valueParts[index] = genitiveFormattedPart;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (hour12.length) addValues(hour12, true);
|
|
282
|
+
if (hour24.length) addValues(hour24);
|
|
283
|
+
return valueParts.reduce((map, part) => {
|
|
284
|
+
map[part.type] = part.value;
|
|
285
|
+
return map;
|
|
286
|
+
}, {});
|
|
287
|
+
}
|
|
288
|
+
function secsToOffset(totalSecs, token = 'Z') {
|
|
289
|
+
const sign = totalSecs < 0 ? '-' : '+';
|
|
290
|
+
const absSecs = Math.abs(totalSecs);
|
|
291
|
+
const hours = String(Math.floor(absSecs / 3600)).padStart(2, '0');
|
|
292
|
+
const mins = String(Math.floor((absSecs % 3600) / 60)).padStart(2, '0');
|
|
293
|
+
const secs = Math.round(absSecs % 60);
|
|
294
|
+
if (token === 'ZZ') {
|
|
295
|
+
return secs === 0
|
|
296
|
+
? `${sign}${hours}${mins}`
|
|
297
|
+
: `${sign}${hours}${mins}${String(secs).padStart(2, '0')}`;
|
|
298
|
+
}
|
|
299
|
+
return secs === 0
|
|
300
|
+
? `${sign}${hours}:${mins}`
|
|
301
|
+
: `${sign}${hours}:${mins}:${String(secs).padStart(2, '0')}`;
|
|
302
|
+
}
|
|
303
|
+
function minsToOffset(timeDiffInMins, token = 'Z') {
|
|
304
|
+
return secsToOffset(timeDiffInMins * 60, token);
|
|
305
|
+
}
|
|
306
|
+
function offsetToSecs(offset2, token) {
|
|
307
|
+
validOffset(offset2, token);
|
|
308
|
+
const match = offset2.match(/([+-])([0-3][0-9]):?([0-5][0-9])(?::?([0-5][0-9]))?/);
|
|
309
|
+
const [_, sign, hours, mins, secs = '0'] = match;
|
|
310
|
+
const totalSecs = Number(hours) * 3600 + Number(mins) * 60 + Number(secs);
|
|
311
|
+
return sign === '+' ? totalSecs : -totalSecs;
|
|
312
|
+
}
|
|
313
|
+
function validOffset(offset2, token = 'Z') {
|
|
314
|
+
const valid = ((token2) => {
|
|
315
|
+
switch (token2) {
|
|
316
|
+
case 'Z':
|
|
317
|
+
return /^([+-])[0-3][0-9]:[0-5][0-9](?::[0-5][0-9])?$/.test(offset2);
|
|
318
|
+
case 'ZZ':
|
|
319
|
+
return /^([+-])[0-3][0-9][0-5][0-9](?:[0-5][0-9])?$/.test(offset2);
|
|
320
|
+
}
|
|
321
|
+
})(token);
|
|
322
|
+
if (!valid) throw new Error(`Invalid offset: ${offset2}`);
|
|
323
|
+
return offset2;
|
|
324
|
+
}
|
|
325
|
+
function escapeTokens(str) {
|
|
326
|
+
return clockAgnostic
|
|
327
|
+
.concat(clock24)
|
|
328
|
+
.concat(clock12)
|
|
329
|
+
.concat(fractionalSeconds)
|
|
330
|
+
.sort((a, b) => (a[0].length > b[0].length ? 1 : -1))
|
|
331
|
+
.reduce((target, part) => {
|
|
332
|
+
return target.replace(part[0], `\\${part[0]}`);
|
|
333
|
+
}, str);
|
|
334
|
+
}
|
|
335
|
+
function isNumeric(part) {
|
|
336
|
+
return ['numeric', '2-digit'].includes(part.partValue);
|
|
337
|
+
}
|
|
338
|
+
function validate(parts2) {
|
|
339
|
+
let lastPart = void 0;
|
|
340
|
+
for (const part of parts2) {
|
|
341
|
+
if (part.partName === 'literal' && !isNaN(parseFloat(part.partValue))) {
|
|
342
|
+
throw new Error(`Numbers in format (${part.partValue}).`);
|
|
343
|
+
}
|
|
344
|
+
if (lastPart && lastPart.partName !== 'literal' && part.partName !== 'literal') {
|
|
345
|
+
if (
|
|
346
|
+
!(lastPart.token in fixedLength) &&
|
|
347
|
+
!(part.token in fixedLength) &&
|
|
348
|
+
!(isNumeric(lastPart) && part.token.toLowerCase() === 'a') &&
|
|
349
|
+
lastPart.token !== 'SSS'
|
|
350
|
+
) {
|
|
351
|
+
throw new Error(`Illegal adjacent tokens (${lastPart.token}, ${part.token})`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
lastPart = part;
|
|
355
|
+
}
|
|
356
|
+
return parts2;
|
|
357
|
+
}
|
|
358
|
+
function getOffsetFormat(format2) {
|
|
359
|
+
if (typeof format2 === 'string') {
|
|
360
|
+
return format2.includes('ZZ') ? 'ZZ' : 'Z';
|
|
361
|
+
}
|
|
362
|
+
return 'time' in format2 && format2.time === 'full' ? 'Z' : 'ZZ';
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/ap.ts
|
|
366
|
+
function ap(ampm, locale) {
|
|
367
|
+
const l = dayPeriodMap.get(locale);
|
|
368
|
+
if (l && l[ampm]) return l[ampm];
|
|
369
|
+
const specimen = new Date(specDate);
|
|
370
|
+
specimen.setUTCHours(ampm === 'am' ? 5 : 20);
|
|
371
|
+
const subparts = new Intl.DateTimeFormat(locale, {
|
|
372
|
+
timeStyle: 'full',
|
|
373
|
+
timeZone: 'UTC',
|
|
374
|
+
hour12: true,
|
|
375
|
+
})
|
|
376
|
+
.formatToParts(specimen)
|
|
377
|
+
.map(normStr);
|
|
378
|
+
const period = subparts.find((part) => part.type === 'dayPeriod');
|
|
379
|
+
if (period) {
|
|
380
|
+
const localePeriods = l || {};
|
|
381
|
+
dayPeriodMap.set(locale, Object.assign(localePeriods, { [ampm]: period.value }));
|
|
382
|
+
return period.value;
|
|
383
|
+
}
|
|
384
|
+
return ampm;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/applyOffset.ts
|
|
388
|
+
function applyOffset(dateInput, offset2 = '+00:00') {
|
|
389
|
+
const d = date(dateInput);
|
|
390
|
+
const len = fixedLengthByOffset(offset2);
|
|
391
|
+
const token = len === 5 || len === 8 ? 'ZZ' : 'Z';
|
|
392
|
+
const timeDiffInSecs = offsetToSecs(offset2, token);
|
|
393
|
+
return new Date(d.getTime() + timeDiffInSecs * 1e3);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/deviceTZ.ts
|
|
397
|
+
function deviceTZ() {
|
|
398
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/offset.ts
|
|
402
|
+
function relativeTime(d, timeZone) {
|
|
403
|
+
const utcParts = new Intl.DateTimeFormat('en-US', {
|
|
404
|
+
year: 'numeric',
|
|
405
|
+
month: '2-digit',
|
|
406
|
+
day: '2-digit',
|
|
407
|
+
hour: '2-digit',
|
|
408
|
+
minute: '2-digit',
|
|
409
|
+
second: '2-digit',
|
|
410
|
+
timeZone,
|
|
411
|
+
hourCycle: 'h23',
|
|
412
|
+
})
|
|
413
|
+
.formatToParts(d)
|
|
414
|
+
.map(normStr);
|
|
415
|
+
const parts2 = {};
|
|
416
|
+
utcParts.forEach((part) => {
|
|
417
|
+
parts2[part.type] = part.value;
|
|
418
|
+
});
|
|
419
|
+
return /* @__PURE__ */ new Date(
|
|
420
|
+
`${parts2.year}-${parts2.month}-${parts2.day}T${parts2.hour}:${parts2.minute}:${parts2.second}Z`,
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
function offset(utcTime, tzA = 'UTC', tzB = 'device', timeZoneToken = 'Z') {
|
|
424
|
+
var _a;
|
|
425
|
+
tzB = tzB === 'device' ? ((_a = deviceTZ()) != null ? _a : 'utc') : tzB;
|
|
426
|
+
const d = date(utcTime);
|
|
427
|
+
const timeA = relativeTime(d, tzA);
|
|
428
|
+
const timeB = relativeTime(d, tzB);
|
|
429
|
+
const timeDiffInSecs = Math.round((timeB.getTime() - timeA.getTime()) / 1e3);
|
|
430
|
+
return secsToOffset(timeDiffInSecs, timeZoneToken);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/tzDate.ts
|
|
434
|
+
function tzDate(inputDate, tz) {
|
|
435
|
+
const d = date(inputDate);
|
|
436
|
+
return applyOffset(d, offset(d, tz));
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/dayOfYear.ts
|
|
440
|
+
function dayOfYear(inputDate) {
|
|
441
|
+
const d = date(inputDate);
|
|
442
|
+
return Math.round(
|
|
443
|
+
(new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0).getTime() -
|
|
444
|
+
new Date(d.getFullYear(), 0, 0).getTime()) /
|
|
445
|
+
864e5,
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/dayEnd.ts
|
|
450
|
+
function dayEnd(inputDate) {
|
|
451
|
+
const d = date(inputDate);
|
|
452
|
+
d.setHours(23, 59, 59, 999);
|
|
453
|
+
return d;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/dayStart.ts
|
|
457
|
+
function dayStart(inputDate) {
|
|
458
|
+
const d = date(inputDate);
|
|
459
|
+
d.setHours(0, 0, 0, 0);
|
|
460
|
+
return d;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// src/parts.ts
|
|
464
|
+
function parts(format2, locale) {
|
|
465
|
+
if (styles.includes(format2) || typeof format2 === 'object') {
|
|
466
|
+
return styleParts(format2, locale);
|
|
467
|
+
}
|
|
468
|
+
let f = format2;
|
|
469
|
+
let match = 0;
|
|
470
|
+
const testPattern = (pattern) => {
|
|
471
|
+
if (!pattern[2]) pattern[2] = new RegExp(`(.)?(${pattern[0]})`, 'g');
|
|
472
|
+
if (pattern[2].test(f)) {
|
|
473
|
+
let didAdd = 0;
|
|
474
|
+
f = f.replace(pattern[2], (_, prefix, actualMatch) => {
|
|
475
|
+
if (prefix === '\\') return actualMatch;
|
|
476
|
+
return `${typeof prefix === 'string' ? prefix : ''}{!${didAdd++ ? match : match++}!}`;
|
|
477
|
+
});
|
|
478
|
+
return !!didAdd;
|
|
479
|
+
}
|
|
480
|
+
return false;
|
|
481
|
+
};
|
|
482
|
+
function validate2(patterns) {
|
|
483
|
+
const parts3 = patterns.map((part) => part.partName);
|
|
484
|
+
const deduped = new Set(parts3);
|
|
485
|
+
if (parts3.length > deduped.size) {
|
|
486
|
+
throw new Error(`Cannot reuse format tokens.`);
|
|
487
|
+
}
|
|
488
|
+
return patterns;
|
|
489
|
+
}
|
|
490
|
+
function createPart(hour12, [token, option, exp]) {
|
|
491
|
+
const partName = Object.keys(option)[0];
|
|
492
|
+
const partValue = option[partName];
|
|
493
|
+
return {
|
|
494
|
+
option,
|
|
495
|
+
partName,
|
|
496
|
+
partValue,
|
|
497
|
+
token,
|
|
498
|
+
pattern: exp,
|
|
499
|
+
hour12,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
const found24Patterns = clockAgnostic
|
|
503
|
+
.filter(testPattern)
|
|
504
|
+
.concat(clock24.filter(testPattern))
|
|
505
|
+
.concat(fractionalSeconds.filter(testPattern))
|
|
506
|
+
.map(createPart.bind(null, false));
|
|
507
|
+
const parts2 = validate2(
|
|
508
|
+
found24Patterns.concat(clock12.filter(testPattern).map(createPart.bind(null, true))),
|
|
509
|
+
);
|
|
510
|
+
const extractIndex = /^\{!(\d+)!\}$/;
|
|
511
|
+
return f
|
|
512
|
+
.split(/(\{!\d+!\})/)
|
|
513
|
+
.map((match2) => {
|
|
514
|
+
const hasIndex = match2.match(extractIndex);
|
|
515
|
+
if (hasIndex) {
|
|
516
|
+
return parts2[Number(hasIndex[1])];
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
option: { literal: match2 },
|
|
520
|
+
partName: 'literal',
|
|
521
|
+
partValue: match2,
|
|
522
|
+
token: match2,
|
|
523
|
+
pattern: new RegExp(''),
|
|
524
|
+
hour12: false,
|
|
525
|
+
};
|
|
526
|
+
})
|
|
527
|
+
.filter((part) => !(part.partName === 'literal' && part.partValue === ''));
|
|
528
|
+
}
|
|
529
|
+
function styleParts(format2, locale) {
|
|
530
|
+
const options = {
|
|
531
|
+
timeZone: 'UTC',
|
|
532
|
+
};
|
|
533
|
+
if (typeof format2 === 'string') {
|
|
534
|
+
options.dateStyle = format2;
|
|
535
|
+
} else {
|
|
536
|
+
if ('date' in format2) options.dateStyle = format2.date;
|
|
537
|
+
if ('time' in format2) options.timeStyle = format2.time;
|
|
538
|
+
}
|
|
539
|
+
const formatter = new Intl.DateTimeFormat(locale, options);
|
|
540
|
+
const segments = formatter.formatToParts(new Date(specDate)).map(normStr);
|
|
541
|
+
const hourTypeSegments = formatter
|
|
542
|
+
.formatToParts(/* @__PURE__ */ new Date('1999-04-05T23:05:01.000Z'))
|
|
543
|
+
.map(normStr);
|
|
544
|
+
const hourPart = hourTypeSegments.find((segment) => segment.type === 'hour');
|
|
545
|
+
const hourType = hourPart && hourPart.value === '23' ? 24 : 12;
|
|
546
|
+
return segments
|
|
547
|
+
.map((part) => {
|
|
548
|
+
const partName = part.type;
|
|
549
|
+
const formatPattern = guessPattern(
|
|
550
|
+
part.type,
|
|
551
|
+
part.value,
|
|
552
|
+
locale,
|
|
553
|
+
part.type === 'hour' ? hourType : void 0,
|
|
554
|
+
options,
|
|
555
|
+
);
|
|
556
|
+
if (formatPattern === void 0) return;
|
|
557
|
+
const partValue = formatPattern[1][partName];
|
|
558
|
+
if (!partValue) return;
|
|
559
|
+
if (!formatPattern[2]) formatPattern[2] = new RegExp(`${formatPattern[0]}`, 'g');
|
|
560
|
+
return {
|
|
561
|
+
option: { [partName]: partValue },
|
|
562
|
+
partName,
|
|
563
|
+
partValue,
|
|
564
|
+
token: formatPattern[0],
|
|
565
|
+
pattern: formatPattern[2],
|
|
566
|
+
hour12: hourType === 12,
|
|
567
|
+
};
|
|
568
|
+
})
|
|
569
|
+
.filter((part) => !!part);
|
|
570
|
+
}
|
|
571
|
+
function guessPattern(partName, partValue, locale, hour, options) {
|
|
572
|
+
const l = partValue.length;
|
|
573
|
+
const n = !isNaN(Number(partValue));
|
|
574
|
+
let style;
|
|
575
|
+
switch (partName) {
|
|
576
|
+
case 'year':
|
|
577
|
+
return l === 2 ? tokens.get('YY') : tokens.get('YYYY');
|
|
578
|
+
case 'month':
|
|
579
|
+
if (n) return l === 1 ? tokens.get('M') : tokens.get('MM');
|
|
580
|
+
style = partStyle(locale, partName, partValue);
|
|
581
|
+
switch (style) {
|
|
582
|
+
case 'long':
|
|
583
|
+
return tokens.get('MMMM');
|
|
584
|
+
default:
|
|
585
|
+
return tokens.get('MMM');
|
|
586
|
+
}
|
|
587
|
+
case 'day':
|
|
588
|
+
return l === 1 ? tokens.get('D') : tokens.get('DD');
|
|
589
|
+
case 'weekday':
|
|
590
|
+
style = partStyle(locale, partName, partValue);
|
|
591
|
+
switch (style) {
|
|
592
|
+
case 'narrow':
|
|
593
|
+
return tokens.get('d');
|
|
594
|
+
case 'short':
|
|
595
|
+
return tokens.get('ddd');
|
|
596
|
+
default:
|
|
597
|
+
return tokens.get('dddd');
|
|
598
|
+
}
|
|
599
|
+
case 'hour':
|
|
600
|
+
if (hour === 12) return l === 1 ? tokens.get('h') : tokens.get('hh');
|
|
601
|
+
return l === 1 ? tokens.get('H') : tokens.get('HH');
|
|
602
|
+
case 'minute':
|
|
603
|
+
return l === 1 ? tokens.get('m') : tokens.get('mm');
|
|
604
|
+
case 'second':
|
|
605
|
+
return l === 1 ? tokens.get('s') : tokens.get('ss');
|
|
606
|
+
case 'dayPeriod':
|
|
607
|
+
return /^[A-Z]+$/u.test(partValue) ? tokens.get('A') : tokens.get('a');
|
|
608
|
+
case 'literal':
|
|
609
|
+
return [partValue, { literal: partValue }, new RegExp('')];
|
|
610
|
+
case 'timeZoneName':
|
|
611
|
+
return options.timeStyle === 'full' ? tokens.get('Z') : tokens.get('ZZ');
|
|
612
|
+
default:
|
|
613
|
+
return void 0;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function partStyle(locale, part, value) {
|
|
617
|
+
if (!memoParts.has(locale)) {
|
|
618
|
+
const date2 = new Date(specDate);
|
|
619
|
+
const weekdays = [3, 8, 9, 7, 6, 4, 3];
|
|
620
|
+
const parts2 = ['weekday', 'month', 'dayPeriod'];
|
|
621
|
+
const partStyles = ['long', 'short', 'narrow'];
|
|
622
|
+
const formats2 = {};
|
|
623
|
+
for (let i = 0; i < 12; i++) {
|
|
624
|
+
date2.setMonth(0 + i);
|
|
625
|
+
if (i in weekdays) date2.setDate(weekdays[i]);
|
|
626
|
+
date2.setUTCHours(8 + i);
|
|
627
|
+
for (const style of partStyles) {
|
|
628
|
+
const segments = new Intl.DateTimeFormat(
|
|
629
|
+
locale,
|
|
630
|
+
parts2.reduce((options, part2) => Object.assign(options, { [part2]: style }), {
|
|
631
|
+
hour12: true,
|
|
632
|
+
timeZone: 'UTC',
|
|
633
|
+
}),
|
|
634
|
+
)
|
|
635
|
+
.formatToParts(date2)
|
|
636
|
+
.map(normStr);
|
|
637
|
+
if (style === 'long' || style === 'short') {
|
|
638
|
+
const genitiveFormattedParts = new Intl.DateTimeFormat(locale, {
|
|
639
|
+
dateStyle: style === 'short' ? 'medium' : 'long',
|
|
640
|
+
timeZone: 'UTC',
|
|
641
|
+
})
|
|
642
|
+
.formatToParts(date2)
|
|
643
|
+
.map(normStr);
|
|
644
|
+
const genitiveMonth = genitiveFormattedParts.find((part2) => part2.type === 'month');
|
|
645
|
+
const index = segments.findIndex((part2) => part2.type === 'month');
|
|
646
|
+
if (index > -1 && genitiveMonth) segments[index] = genitiveMonth;
|
|
647
|
+
}
|
|
648
|
+
segments.forEach((part2) => {
|
|
649
|
+
if (part2.type === 'literal') return;
|
|
650
|
+
const type = part2.type;
|
|
651
|
+
formats2[type] = Object.assign(formats2[type] || {}, {
|
|
652
|
+
[part2.value]: style,
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
memoParts.set(locale, formats2);
|
|
658
|
+
}
|
|
659
|
+
const formats = memoParts.get(locale);
|
|
660
|
+
return formats ? formats[part][value] : void 0;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// src/removeOffset.ts
|
|
664
|
+
function removeOffset(dateInput, offset2 = '+00:00') {
|
|
665
|
+
const positive = offset2.slice(0, 1) === '+';
|
|
666
|
+
return applyOffset(dateInput, offset2.replace(positive ? '+' : '-', positive ? '-' : '+'));
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// src/deviceLocale.ts
|
|
670
|
+
function deviceLocale() {
|
|
671
|
+
return Intl.DateTimeFormat().resolvedOptions().locale;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// src/format.ts
|
|
675
|
+
function format(
|
|
676
|
+
inputDateOrOptions,
|
|
677
|
+
format2 = 'long',
|
|
678
|
+
locale = 'device',
|
|
679
|
+
genitive = false,
|
|
680
|
+
partFilter,
|
|
681
|
+
) {
|
|
682
|
+
let tz, forceOffset;
|
|
683
|
+
if (typeof inputDateOrOptions === 'object' && !(inputDateOrOptions instanceof Date)) {
|
|
684
|
+
({
|
|
685
|
+
date: inputDateOrOptions,
|
|
686
|
+
format: format2,
|
|
687
|
+
locale,
|
|
688
|
+
genitive,
|
|
689
|
+
partFilter,
|
|
690
|
+
tz,
|
|
691
|
+
} = inputDateOrOptions);
|
|
692
|
+
}
|
|
693
|
+
if (format2 === 'ISO8601') return date(inputDateOrOptions).toISOString();
|
|
694
|
+
if (tz) {
|
|
695
|
+
forceOffset = offset(inputDateOrOptions, 'utc', tz, getOffsetFormat(format2));
|
|
696
|
+
}
|
|
697
|
+
tz != null ? tz : (tz = deviceTZ());
|
|
698
|
+
if ((tz == null ? void 0 : tz.toLowerCase()) !== 'utc') {
|
|
699
|
+
inputDateOrOptions = removeOffset(inputDateOrOptions, offset(inputDateOrOptions, tz, 'utc'));
|
|
700
|
+
}
|
|
701
|
+
if (!locale || locale === 'device') {
|
|
702
|
+
locale = deviceLocale();
|
|
703
|
+
}
|
|
704
|
+
return fill(
|
|
705
|
+
inputDateOrOptions,
|
|
706
|
+
parts(format2, locale).filter(partFilter != null ? partFilter : () => true),
|
|
707
|
+
locale,
|
|
708
|
+
genitive,
|
|
709
|
+
forceOffset,
|
|
710
|
+
)
|
|
711
|
+
.map((p) => p.value)
|
|
712
|
+
.join('');
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// src/formatStr.ts
|
|
716
|
+
function formatStr(format2, locale = 'en', escapeLiterals = false, filterParts = () => true) {
|
|
717
|
+
return parts(format2, locale)
|
|
718
|
+
.filter(filterParts)
|
|
719
|
+
.reduce(
|
|
720
|
+
(f, p) => (f += escapeLiterals && p.partName === 'literal' ? escapeTokens(p.token) : p.token),
|
|
721
|
+
'',
|
|
722
|
+
)
|
|
723
|
+
.normalize('NFKC');
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// src/fourDigitYear.ts
|
|
727
|
+
function fourDigitYear(value) {
|
|
728
|
+
const y = /* @__PURE__ */ new Date().getFullYear();
|
|
729
|
+
const currentYear = y % 100;
|
|
730
|
+
const century = Math.floor(y / 100);
|
|
731
|
+
const parsedYear = Number(value);
|
|
732
|
+
return (century + (parsedYear > currentYear + 20 ? -1 : 0)) * 100 + parsedYear;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// src/hourEnd.ts
|
|
736
|
+
function hourEnd(inputDate) {
|
|
737
|
+
const d = date(inputDate);
|
|
738
|
+
d.setMinutes(59, 59, 999);
|
|
739
|
+
return d;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// src/hourStart.ts
|
|
743
|
+
function hourStart(inputDate) {
|
|
744
|
+
const d = date(inputDate);
|
|
745
|
+
d.setMinutes(0, 0, 0);
|
|
746
|
+
return d;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// src/minuteEnd.ts
|
|
750
|
+
function minuteEnd(inputDate) {
|
|
751
|
+
const d = date(inputDate);
|
|
752
|
+
d.setSeconds(59, 999);
|
|
753
|
+
return d;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// src/minuteStart.ts
|
|
757
|
+
function minuteStart(inputDate) {
|
|
758
|
+
const d = date(inputDate);
|
|
759
|
+
d.setSeconds(0, 0);
|
|
760
|
+
return d;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// src/monthStart.ts
|
|
764
|
+
function monthStart(inputDate) {
|
|
765
|
+
const d = date(inputDate);
|
|
766
|
+
d.setDate(1);
|
|
767
|
+
d.setHours(0, 0, 0, 0);
|
|
768
|
+
return d;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// src/yearDays.ts
|
|
772
|
+
function yearDays(inputDate) {
|
|
773
|
+
const d = date(inputDate);
|
|
774
|
+
return (
|
|
775
|
+
(new Date(d.getFullYear() + 1, 0, 0).getTime() - new Date(d.getFullYear(), 0, 0).getTime()) /
|
|
776
|
+
864e5
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// src/nearestDay.ts
|
|
781
|
+
function nearestDay(inputDate, search, constraint = 7) {
|
|
782
|
+
let increments;
|
|
783
|
+
let decrements;
|
|
784
|
+
const d = date(inputDate);
|
|
785
|
+
switch (constraint) {
|
|
786
|
+
case 'month':
|
|
787
|
+
decrements = d.getDate();
|
|
788
|
+
increments = monthDays(d) - d.getDate();
|
|
789
|
+
break;
|
|
790
|
+
case 'week':
|
|
791
|
+
decrements = d.getDay() + 1;
|
|
792
|
+
increments = 6 - d.getDay();
|
|
793
|
+
break;
|
|
794
|
+
case 'year':
|
|
795
|
+
const total = yearDays(d);
|
|
796
|
+
const day = dayOfYear(d);
|
|
797
|
+
decrements = day;
|
|
798
|
+
increments = total - day;
|
|
799
|
+
break;
|
|
800
|
+
default:
|
|
801
|
+
increments = decrements = constraint;
|
|
802
|
+
}
|
|
803
|
+
for (let i = 0; i <= increments || i < decrements; i++) {
|
|
804
|
+
if (i <= increments) {
|
|
805
|
+
const next = addDay(d, i);
|
|
806
|
+
if (search(next)) return next;
|
|
807
|
+
}
|
|
808
|
+
if (i && i <= decrements) {
|
|
809
|
+
const prev = addDay(d, -i);
|
|
810
|
+
if (search(prev)) return prev;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/range.ts
|
|
817
|
+
function range(token, locale = 'en', genitive = false) {
|
|
818
|
+
const r = (n, c) =>
|
|
819
|
+
Array(n)
|
|
820
|
+
.fill('')
|
|
821
|
+
.map((_, i) => `${c(i)}`);
|
|
822
|
+
if (token === 'M') return r(12, (i) => i + 1);
|
|
823
|
+
if (token === 'MM')
|
|
824
|
+
return r(12, (i) => {
|
|
825
|
+
const m = i + 1;
|
|
826
|
+
return m < 10 ? `0${m}` : m;
|
|
827
|
+
});
|
|
828
|
+
if (token.startsWith('M'))
|
|
829
|
+
return range('MM').map((m) => format(`2000-${m}-05`, token, locale, genitive));
|
|
830
|
+
if (token.startsWith('d'))
|
|
831
|
+
return r(7, (i) => `0${i + 2}`).map((d) => format(`2022-10-${d}`, token, locale));
|
|
832
|
+
if (token === 'a') return [ap('am', locale).toLowerCase(), ap('pm', locale).toLowerCase()];
|
|
833
|
+
if (token === 'A') return [ap('am', locale).toUpperCase(), ap('pm', locale).toUpperCase()];
|
|
834
|
+
if (token.startsWith('Y')) {
|
|
835
|
+
const year = /* @__PURE__ */ new Date().getFullYear();
|
|
836
|
+
return r(120, (i) => i + 1).reduce(
|
|
837
|
+
(ranges, i) => {
|
|
838
|
+
if (i !== '120') ranges.push(format(`${year + Number(i)}-06-06`, token, locale));
|
|
839
|
+
ranges.unshift(format(`${year - Number(i)}-06-06`, token, locale));
|
|
840
|
+
return ranges;
|
|
841
|
+
},
|
|
842
|
+
[format(`${year}-06-06`, token, locale)],
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
if (token.startsWith('D')) return r(31, (i) => `${token === 'DD' && i < 9 ? '0' : ''}${i + 1}`);
|
|
846
|
+
if (token.startsWith('H')) return r(24, (i) => `${token === 'HH' && i < 10 ? '0' : ''}${i}`);
|
|
847
|
+
if (token.startsWith('h')) return r(12, (i) => `${token === 'hh' && i < 9 ? '0' : ''}${i + 1}`);
|
|
848
|
+
if (token.startsWith('m') || token.startsWith('s'))
|
|
849
|
+
return r(60, (i) => `${token.length > 1 && i < 10 ? '0' : ''}${i}`);
|
|
850
|
+
return [];
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// src/parse.ts
|
|
854
|
+
function parse(dateStrOrOptions, format2 = 'ISO8601', locale = 'device') {
|
|
855
|
+
let partFilter = () => true;
|
|
856
|
+
let dateStr;
|
|
857
|
+
let dateOverflow = 'backward';
|
|
858
|
+
if (typeof dateStrOrOptions === 'object') {
|
|
859
|
+
({
|
|
860
|
+
date: dateStr,
|
|
861
|
+
format: format2 = 'ISO8601',
|
|
862
|
+
locale = 'device',
|
|
863
|
+
dateOverflow = 'backward',
|
|
864
|
+
partFilter = () => true,
|
|
865
|
+
} = dateStrOrOptions);
|
|
866
|
+
} else {
|
|
867
|
+
dateStr = dateStrOrOptions;
|
|
868
|
+
}
|
|
869
|
+
if (!dateStr) throw new Error('parse() requires a date string.');
|
|
870
|
+
const invalid = () => {
|
|
871
|
+
throw new Error(`Date (${dateStr}) does not match format (${formatStr(format2, locale)})`);
|
|
872
|
+
};
|
|
873
|
+
if (format2 === 'ISO8601') return date(dateStr);
|
|
874
|
+
const genitive = styles.includes(format2) || typeof format2 === 'object';
|
|
875
|
+
const formatParts = validate(parts(format2, locale).filter(partFilter));
|
|
876
|
+
if (!formatParts.length) throw new Error('parse() requires a pattern.');
|
|
877
|
+
let parsedParts;
|
|
878
|
+
try {
|
|
879
|
+
parsedParts = parseParts(dateStr, formatParts);
|
|
880
|
+
} catch {
|
|
881
|
+
return invalid();
|
|
882
|
+
}
|
|
883
|
+
const now = /* @__PURE__ */ new Date();
|
|
884
|
+
const parsed = /* @__PURE__ */ new Map([
|
|
885
|
+
['YYYY', now.getFullYear()],
|
|
886
|
+
['MM', now.getMonth() + 1],
|
|
887
|
+
['DD', now.getDate()],
|
|
888
|
+
['HH', 0],
|
|
889
|
+
['mm', 0],
|
|
890
|
+
['ss', 0],
|
|
891
|
+
['SSS', 0],
|
|
892
|
+
]);
|
|
893
|
+
let a = null;
|
|
894
|
+
let offset2 = '';
|
|
895
|
+
parsedParts.forEach((part) => {
|
|
896
|
+
if (part.partName === 'literal') return;
|
|
897
|
+
if (part.token === part.value) return invalid();
|
|
898
|
+
const v = Number(part.value);
|
|
899
|
+
if (part.token === 'SSS') {
|
|
900
|
+
const digits = part.value.padEnd(3, '0').slice(0, 3);
|
|
901
|
+
parsed.set('SSS', Number(digits));
|
|
902
|
+
} else if (parsed.has(part.token)) {
|
|
903
|
+
parsed.set(part.token, v);
|
|
904
|
+
} else if (part.token === 'YY') {
|
|
905
|
+
parsed.set('YYYY', fourDigitYear(part.value));
|
|
906
|
+
} else {
|
|
907
|
+
const t = part.token;
|
|
908
|
+
if (t.startsWith('d')) {
|
|
909
|
+
return;
|
|
910
|
+
} else if (t === 'D') {
|
|
911
|
+
parsed.set('DD', v);
|
|
912
|
+
} else if (t === 'H' || t.startsWith('h')) {
|
|
913
|
+
parsed.set('HH', v);
|
|
914
|
+
} else if (t === 'M') {
|
|
915
|
+
parsed.set('MM', v);
|
|
916
|
+
} else if (t === 'a' || t === 'A') {
|
|
917
|
+
a = part.value.toLowerCase() === ap('am', locale).toLowerCase();
|
|
918
|
+
} else if (t === 'Z' || t === 'ZZ') {
|
|
919
|
+
offset2 = validOffset(part.value, t);
|
|
920
|
+
} else {
|
|
921
|
+
const values = range(t, locale, genitive);
|
|
922
|
+
const index = values.indexOf(part.value);
|
|
923
|
+
if (index !== -1) {
|
|
924
|
+
switch (t) {
|
|
925
|
+
case 'MMM':
|
|
926
|
+
case 'MMMM':
|
|
927
|
+
parsed.set('MM', index + 1);
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
let hours = parsed.get('HH') || 0;
|
|
935
|
+
if (a === false) {
|
|
936
|
+
hours += hours === 12 ? 0 : 12;
|
|
937
|
+
parsed.set('HH', hours === 24 ? 0 : hours);
|
|
938
|
+
} else if (a === true && hours === 12) {
|
|
939
|
+
parsed.set('HH', 0);
|
|
940
|
+
}
|
|
941
|
+
parsed.set('MM', (parsed.get('MM') || 1) - 1);
|
|
942
|
+
let [Y, M, D, h, m, s, ms] = Array.from(parsed.values());
|
|
943
|
+
const maxDaysInMonth = monthDays(/* @__PURE__ */ new Date(`${four(Y)}-${two(M + 1)}-10`));
|
|
944
|
+
if (maxDaysInMonth < D && dateOverflow === 'throw')
|
|
945
|
+
throw new Error(`Invalid date ${four(Y)}-${two(M + 1)}-${two(D)}`);
|
|
946
|
+
D = dateOverflow === 'backward' ? Math.min(D, maxDaysInMonth) : D;
|
|
947
|
+
const msStr = String(ms).padStart(3, '0');
|
|
948
|
+
if (offset2) {
|
|
949
|
+
const isoStringUtc = `${four(Y)}-${two(M + 1)}-${two(D)}T${two(h)}:${two(m)}:${two(s)}.${msStr}Z`;
|
|
950
|
+
const d2 = new Date(isoStringUtc);
|
|
951
|
+
if (!isFinite(+d2)) return invalid();
|
|
952
|
+
const len = fixedLengthByOffset(offset2);
|
|
953
|
+
const token = len === 5 || len === 8 ? 'ZZ' : 'Z';
|
|
954
|
+
const offsetSecs = offsetToSecs(offset2, token);
|
|
955
|
+
return new Date(d2.getTime() - offsetSecs * 1e3);
|
|
956
|
+
}
|
|
957
|
+
const isoString = `${four(Y)}-${two(M + 1)}-${two(D)}T${two(h)}:${two(m)}:${two(s)}.${msStr}`;
|
|
958
|
+
const d = new Date(isoString);
|
|
959
|
+
if (isFinite(+d)) return d;
|
|
960
|
+
return invalid();
|
|
961
|
+
}
|
|
962
|
+
function parseParts(dateStr, formatParts) {
|
|
963
|
+
let i = 0;
|
|
964
|
+
const advance = (parts2) => [parts2[i++], parts2[i]];
|
|
965
|
+
let pos = 0;
|
|
966
|
+
const parsed = [];
|
|
967
|
+
let n = void 0;
|
|
968
|
+
do {
|
|
969
|
+
const [current, next] = advance(formatParts);
|
|
970
|
+
n = next;
|
|
971
|
+
let len = 1;
|
|
972
|
+
if (current.partName === 'literal') {
|
|
973
|
+
len = current.partValue.length;
|
|
974
|
+
} else if (current.partName === 'timeZoneName') {
|
|
975
|
+
len = fixedLengthByOffset(dateStr.substring(pos));
|
|
976
|
+
} else if (current.token === 'SSS') {
|
|
977
|
+
let end = pos;
|
|
978
|
+
while (end < dateStr.length && /\d/.test(dateStr.charAt(end))) {
|
|
979
|
+
end++;
|
|
980
|
+
}
|
|
981
|
+
len = end - pos;
|
|
982
|
+
} else if (current.token in fixedLength) {
|
|
983
|
+
len = fixedLength[current.token];
|
|
984
|
+
} else if (next) {
|
|
985
|
+
if (next.partName === 'literal') {
|
|
986
|
+
len = dateStr.indexOf(next.partValue, pos) - pos;
|
|
987
|
+
if (len < 0) throw new Error();
|
|
988
|
+
} else if (next.partName === 'dayPeriod') {
|
|
989
|
+
for (let i2 = 1; i2 <= 4; i2++) {
|
|
990
|
+
if (isNaN(Number(dateStr.charAt(pos + i2)))) {
|
|
991
|
+
len = i2;
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
} else {
|
|
996
|
+
const nextChar = dateStr.substring(pos).search(/\d/);
|
|
997
|
+
if (nextChar !== -1) len = pos + nextChar;
|
|
998
|
+
}
|
|
999
|
+
} else {
|
|
1000
|
+
len = dateStr.length;
|
|
1001
|
+
}
|
|
1002
|
+
parsed.push({ ...current, value: dateStr.substring(pos, pos + len) });
|
|
1003
|
+
pos += len;
|
|
1004
|
+
} while (n);
|
|
1005
|
+
return parsed;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/sameDay.ts
|
|
1009
|
+
function sameDay(inputDateA, inputDateB) {
|
|
1010
|
+
const a = date(inputDateA);
|
|
1011
|
+
const b = date(inputDateB);
|
|
1012
|
+
return (
|
|
1013
|
+
a.getDate() === b.getDate() &&
|
|
1014
|
+
a.getMonth() === b.getMonth() &&
|
|
1015
|
+
a.getFullYear() === b.getFullYear()
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
// src/sameSecond.ts
|
|
1020
|
+
function sameSecond(inputDateA, inputDateB) {
|
|
1021
|
+
const a = date(inputDateA);
|
|
1022
|
+
const b = date(inputDateB);
|
|
1023
|
+
return a.getSeconds() === b.getSeconds();
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// src/sameMillisecond.ts
|
|
1027
|
+
function sameMillisecond(inputDateA, inputDateB) {
|
|
1028
|
+
const a = date(inputDateA);
|
|
1029
|
+
const b = date(inputDateB);
|
|
1030
|
+
return a.getMilliseconds() === b.getMilliseconds();
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// src/sameMinute.ts
|
|
1034
|
+
function sameMinute(inputDateA, inputDateB) {
|
|
1035
|
+
const a = date(inputDateA);
|
|
1036
|
+
const b = date(inputDateB);
|
|
1037
|
+
return a.getMinutes() === b.getMinutes();
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// src/sameHour.ts
|
|
1041
|
+
function sameHour(inputDateA, inputDateB) {
|
|
1042
|
+
const a = date(inputDateA);
|
|
1043
|
+
const b = date(inputDateB);
|
|
1044
|
+
return a.getHours() === b.getHours();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// src/sameYear.ts
|
|
1048
|
+
function sameYear(inputDateA, inputDateB) {
|
|
1049
|
+
const a = date(inputDateA);
|
|
1050
|
+
const b = date(inputDateB);
|
|
1051
|
+
return a.getFullYear() === b.getFullYear();
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// src/weekStart.ts
|
|
1055
|
+
function weekStart(inputDate, startOfWeekDay = 0) {
|
|
1056
|
+
const d = date(inputDate);
|
|
1057
|
+
let diff = startOfWeekDay - d.getDay();
|
|
1058
|
+
if (diff > 0) diff = diff - 7;
|
|
1059
|
+
d.setDate(d.getDate() + diff);
|
|
1060
|
+
d.setHours(0, 0, 0, 0);
|
|
1061
|
+
return d;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// src/weekEnd.ts
|
|
1065
|
+
function weekEnd(inputDate, startOfWeekDay = 0) {
|
|
1066
|
+
const d = weekStart(inputDate, startOfWeekDay);
|
|
1067
|
+
d.setDate(d.getDate() + 6);
|
|
1068
|
+
d.setHours(23, 59, 59, 999);
|
|
1069
|
+
return d;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// src/yearStart.ts
|
|
1073
|
+
function yearStart(inputDate) {
|
|
1074
|
+
const d = date(inputDate);
|
|
1075
|
+
d.setMonth(0, 1);
|
|
1076
|
+
d.setHours(0, 0, 0, 0);
|
|
1077
|
+
return d;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// src/yearEnd.ts
|
|
1081
|
+
function yearEnd(inputDate) {
|
|
1082
|
+
const d = date(inputDate);
|
|
1083
|
+
d.setMonth(11, 31);
|
|
1084
|
+
d.setHours(23, 59, 59, 999);
|
|
1085
|
+
return d;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// src/isBefore.ts
|
|
1089
|
+
function isBefore(inputDate, dateToCompare) {
|
|
1090
|
+
const _date = date(inputDate);
|
|
1091
|
+
const _dateToCompare = date(dateToCompare);
|
|
1092
|
+
return +_date < +_dateToCompare;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// src/isAfter.ts
|
|
1096
|
+
function isAfter(inputDate, dateToCompare) {
|
|
1097
|
+
const _date = date(inputDate);
|
|
1098
|
+
const _dateToCompare = date(dateToCompare);
|
|
1099
|
+
return +_date > +_dateToCompare;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/isEqual.ts
|
|
1103
|
+
function isEqual(dateLeft, dateRight) {
|
|
1104
|
+
const _dateLeft = date(dateLeft);
|
|
1105
|
+
const _dateRight = date(dateRight);
|
|
1106
|
+
return +_dateLeft === +_dateRight;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// src/isPast.ts
|
|
1110
|
+
function isPast(inputDate) {
|
|
1111
|
+
return isBefore(inputDate);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// src/isFuture.ts
|
|
1115
|
+
function isFuture(inputDate) {
|
|
1116
|
+
return isAfter(inputDate);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/diffMilliseconds.ts
|
|
1120
|
+
function diffMilliseconds(dateA, dateB) {
|
|
1121
|
+
const left = date(dateA);
|
|
1122
|
+
const right = date(dateB);
|
|
1123
|
+
return +left - +right;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// src/diffRound.ts
|
|
1127
|
+
function diffRound(value, method = 'trunc') {
|
|
1128
|
+
const r = Math[method](value);
|
|
1129
|
+
return r == 0 ? 0 : r;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// src/diffSeconds.ts
|
|
1133
|
+
function diffSeconds(dateA, dateB, roundingMethod) {
|
|
1134
|
+
return diffRound(
|
|
1135
|
+
// @ts-ignore
|
|
1136
|
+
diffMilliseconds(dateA, dateB) / 1e3,
|
|
1137
|
+
roundingMethod,
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// src/diffMinutes.ts
|
|
1142
|
+
function diffMinutes(dateA, dateB, roundingMethod) {
|
|
1143
|
+
return diffRound(
|
|
1144
|
+
//@ts-ignore
|
|
1145
|
+
diffMilliseconds(dateA, dateB) / 6e4,
|
|
1146
|
+
roundingMethod,
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// src/diffHours.ts
|
|
1151
|
+
function diffHours(dateA, dateB, roundingMethod) {
|
|
1152
|
+
return diffRound(
|
|
1153
|
+
//@ts-ignore
|
|
1154
|
+
diffMilliseconds(dateA, dateB) / 36e5,
|
|
1155
|
+
// 1000 * 60 * 60
|
|
1156
|
+
roundingMethod,
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// src/diffDays.ts
|
|
1161
|
+
function diffDays(dateA, dateB, roundingMethod) {
|
|
1162
|
+
return diffRound(
|
|
1163
|
+
// @ts-ignore
|
|
1164
|
+
diffMilliseconds(dateA, dateB) / 864e5,
|
|
1165
|
+
// hour * 24
|
|
1166
|
+
roundingMethod,
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// src/diffWeeks.ts
|
|
1171
|
+
function diffWeeks(dateA, dateB, roundingMethod) {
|
|
1172
|
+
return diffRound(
|
|
1173
|
+
diffMilliseconds(dateA, dateB) / 6048e5,
|
|
1174
|
+
// day * 7
|
|
1175
|
+
roundingMethod,
|
|
1176
|
+
);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// src/diffMonths.ts
|
|
1180
|
+
function diffMonths(dateA, dateB) {
|
|
1181
|
+
const l = date(dateA);
|
|
1182
|
+
const r = date(dateB);
|
|
1183
|
+
if (l < r) {
|
|
1184
|
+
const rs = diffMonths(r, l);
|
|
1185
|
+
return rs == 0 ? 0 : -rs;
|
|
1186
|
+
}
|
|
1187
|
+
let months = (l.getFullYear() - r.getFullYear()) * 12 + (l.getMonth() - r.getMonth());
|
|
1188
|
+
const ld = l.getDate();
|
|
1189
|
+
const rd = r.getDate();
|
|
1190
|
+
if (ld < rd) {
|
|
1191
|
+
const lm = monthDays(l);
|
|
1192
|
+
if (!(lm == ld && lm < rd)) {
|
|
1193
|
+
months--;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
return months == 0 ? 0 : months;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// src/diffYears.ts
|
|
1200
|
+
function diffYears(dateA, dateB) {
|
|
1201
|
+
const r = Math.trunc(
|
|
1202
|
+
//@ts-ignore
|
|
1203
|
+
diffMonths(dateA, dateB) / 12,
|
|
1204
|
+
);
|
|
1205
|
+
return r == 0 ? 0 : r;
|
|
1206
|
+
}
|
|
1207
|
+
export {
|
|
1208
|
+
addDay,
|
|
1209
|
+
addHour,
|
|
1210
|
+
addMillisecond,
|
|
1211
|
+
addMinute,
|
|
1212
|
+
addMonth,
|
|
1213
|
+
addSecond,
|
|
1214
|
+
addYear,
|
|
1215
|
+
ap,
|
|
1216
|
+
applyOffset,
|
|
1217
|
+
date,
|
|
1218
|
+
dayEnd,
|
|
1219
|
+
dayOfYear,
|
|
1220
|
+
dayStart,
|
|
1221
|
+
diffDays,
|
|
1222
|
+
diffHours,
|
|
1223
|
+
diffMilliseconds,
|
|
1224
|
+
diffMinutes,
|
|
1225
|
+
diffMonths,
|
|
1226
|
+
diffSeconds,
|
|
1227
|
+
diffWeeks,
|
|
1228
|
+
diffYears,
|
|
1229
|
+
format,
|
|
1230
|
+
formatStr,
|
|
1231
|
+
fourDigitYear,
|
|
1232
|
+
hourEnd,
|
|
1233
|
+
hourStart,
|
|
1234
|
+
isAfter,
|
|
1235
|
+
isBefore,
|
|
1236
|
+
isEqual,
|
|
1237
|
+
isFuture,
|
|
1238
|
+
isPast,
|
|
1239
|
+
iso8601,
|
|
1240
|
+
minuteEnd,
|
|
1241
|
+
minuteStart,
|
|
1242
|
+
monthDays,
|
|
1243
|
+
monthEnd,
|
|
1244
|
+
monthStart,
|
|
1245
|
+
nearestDay,
|
|
1246
|
+
offset,
|
|
1247
|
+
parse,
|
|
1248
|
+
parseParts,
|
|
1249
|
+
parts,
|
|
1250
|
+
range,
|
|
1251
|
+
removeOffset,
|
|
1252
|
+
sameDay,
|
|
1253
|
+
sameHour,
|
|
1254
|
+
sameMillisecond,
|
|
1255
|
+
sameMinute,
|
|
1256
|
+
sameSecond,
|
|
1257
|
+
sameYear,
|
|
1258
|
+
tzDate,
|
|
1259
|
+
weekEnd,
|
|
1260
|
+
weekStart,
|
|
1261
|
+
yearDays,
|
|
1262
|
+
yearEnd,
|
|
1263
|
+
yearStart,
|
|
1264
|
+
};
|