quasar 2.5.0 → 2.5.1
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/icon-set/bootstrap-icons.umd.prod.js +1 -1
- package/dist/icon-set/eva-icons.umd.prod.js +1 -1
- package/dist/icon-set/fontawesome-v5-pro.umd.prod.js +1 -1
- package/dist/icon-set/fontawesome-v5.umd.prod.js +1 -1
- package/dist/icon-set/ionicons-v4.umd.prod.js +1 -1
- package/dist/icon-set/line-awesome.umd.prod.js +1 -1
- package/dist/icon-set/material-icons-outlined.umd.prod.js +1 -1
- package/dist/icon-set/material-icons-round.umd.prod.js +1 -1
- package/dist/icon-set/material-icons-sharp.umd.prod.js +1 -1
- package/dist/icon-set/material-icons.umd.prod.js +1 -1
- package/dist/icon-set/mdi-v3.umd.prod.js +1 -1
- package/dist/icon-set/mdi-v4.umd.prod.js +1 -1
- package/dist/icon-set/mdi-v5.umd.prod.js +1 -1
- package/dist/icon-set/mdi-v6.umd.prod.js +1 -1
- package/dist/icon-set/svg-bootstrap-icons.umd.prod.js +1 -1
- package/dist/icon-set/svg-eva-icons.umd.prod.js +1 -1
- package/dist/icon-set/svg-fontawesome-v5.umd.prod.js +1 -1
- package/dist/icon-set/svg-ionicons-v4.umd.prod.js +1 -1
- package/dist/icon-set/svg-ionicons-v5.umd.prod.js +1 -1
- package/dist/icon-set/svg-ionicons-v6.umd.prod.js +1 -1
- package/dist/icon-set/svg-line-awesome.umd.prod.js +1 -1
- package/dist/icon-set/svg-material-icons-outlined.umd.prod.js +1 -1
- package/dist/icon-set/svg-material-icons-round.umd.prod.js +1 -1
- package/dist/icon-set/svg-material-icons-sharp.umd.prod.js +1 -1
- package/dist/icon-set/svg-material-icons.umd.prod.js +1 -1
- package/dist/icon-set/svg-mdi-v4.umd.prod.js +1 -1
- package/dist/icon-set/svg-mdi-v5.umd.prod.js +1 -1
- package/dist/icon-set/svg-mdi-v6.umd.prod.js +1 -1
- package/dist/icon-set/svg-themify.umd.prod.js +1 -1
- package/dist/icon-set/themify.umd.prod.js +1 -1
- package/dist/lang/ar.umd.prod.js +1 -1
- package/dist/lang/az-Latn.umd.prod.js +1 -1
- package/dist/lang/bg.umd.prod.js +1 -1
- package/dist/lang/bn.umd.prod.js +1 -1
- package/dist/lang/ca.umd.prod.js +1 -1
- package/dist/lang/cs.umd.prod.js +1 -1
- package/dist/lang/da.umd.prod.js +1 -1
- package/dist/lang/de.umd.prod.js +1 -1
- package/dist/lang/el.umd.prod.js +1 -1
- package/dist/lang/en-GB.umd.prod.js +1 -1
- package/dist/lang/en-US.umd.prod.js +1 -1
- package/dist/lang/eo.umd.prod.js +1 -1
- package/dist/lang/es.umd.prod.js +1 -1
- package/dist/lang/et.umd.prod.js +1 -1
- package/dist/lang/fa-IR.umd.prod.js +1 -1
- package/dist/lang/fa.umd.prod.js +1 -1
- package/dist/lang/fi.umd.prod.js +1 -1
- package/dist/lang/fr.umd.prod.js +1 -1
- package/dist/lang/gn.umd.prod.js +1 -1
- package/dist/lang/he.umd.prod.js +1 -1
- package/dist/lang/hr.umd.prod.js +1 -1
- package/dist/lang/hu.umd.prod.js +1 -1
- package/dist/lang/id.umd.prod.js +1 -1
- package/dist/lang/is.umd.prod.js +1 -1
- package/dist/lang/it.umd.prod.js +1 -1
- package/dist/lang/ja.umd.prod.js +1 -1
- package/dist/lang/km.umd.prod.js +1 -1
- package/dist/lang/ko-KR.umd.prod.js +1 -1
- package/dist/lang/kur-CKB.umd.prod.js +1 -1
- package/dist/lang/lt.umd.prod.js +1 -1
- package/dist/lang/lu.umd.prod.js +1 -1
- package/dist/lang/lv.umd.prod.js +1 -1
- package/dist/lang/ml.umd.prod.js +1 -1
- package/dist/lang/ms.umd.prod.js +1 -1
- package/dist/lang/my.umd.prod.js +1 -1
- package/dist/lang/nb-NO.umd.prod.js +1 -1
- package/dist/lang/nl.umd.prod.js +1 -1
- package/dist/lang/pl.umd.prod.js +1 -1
- package/dist/lang/pt-BR.umd.prod.js +1 -1
- package/dist/lang/pt.umd.prod.js +1 -1
- package/dist/lang/ro.umd.prod.js +1 -1
- package/dist/lang/ru.umd.prod.js +1 -1
- package/dist/lang/sk.umd.prod.js +1 -1
- package/dist/lang/sl.umd.prod.js +1 -1
- package/dist/lang/sr-CYR.umd.prod.js +1 -1
- package/dist/lang/sr.umd.prod.js +1 -1
- package/dist/lang/sv.umd.prod.js +1 -1
- package/dist/lang/ta.umd.prod.js +1 -1
- package/dist/lang/th.umd.prod.js +1 -1
- package/dist/lang/tr.umd.prod.js +1 -1
- package/dist/lang/ug.umd.prod.js +1 -1
- package/dist/lang/uk.umd.prod.js +1 -1
- package/dist/lang/vi.umd.prod.js +1 -1
- package/dist/lang/zh-CN.umd.prod.js +1 -1
- package/dist/lang/zh-TW.umd.prod.js +1 -1
- package/dist/quasar.cjs.prod.js +2 -2
- package/dist/quasar.css +4 -0
- package/dist/quasar.esm.prod.js +2 -2
- package/dist/quasar.prod.css +1 -1
- package/dist/quasar.rtl.css +4 -0
- package/dist/quasar.rtl.prod.css +1 -1
- package/dist/quasar.sass +3 -1
- package/dist/quasar.umd.js +153 -76
- package/dist/quasar.umd.prod.js +2 -2
- package/dist/ssr-directives/Morph.js +1 -1
- package/dist/types/utils/date.d.ts +25 -13
- package/dist/web-types/web-types.json +1 -1
- package/package.json +1 -1
- package/src/components/field/QField.sass +2 -0
- package/src/components/form/QForm.js +26 -24
- package/src/composables/private/use-validate.js +14 -18
- package/src/utils/date.js +110 -31
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
interface DateOptions {
|
|
2
2
|
milliseconds?: number;
|
|
3
|
+
millisecond?: number;
|
|
3
4
|
seconds?: number;
|
|
5
|
+
second?: number;
|
|
4
6
|
minutes?: number;
|
|
7
|
+
minute?: number;
|
|
5
8
|
hours?: number;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
hour?: number;
|
|
10
|
+
days?: number;
|
|
11
|
+
day?: number;
|
|
9
12
|
date?: number;
|
|
13
|
+
months?: number;
|
|
10
14
|
month?: number;
|
|
11
15
|
year?: number;
|
|
12
|
-
}
|
|
13
|
-
export interface ModifyDateOptions extends DateOptions {
|
|
14
|
-
days?: number;
|
|
15
|
-
months?: number;
|
|
16
16
|
years?: number;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -23,23 +23,35 @@ export interface DateLocale {
|
|
|
23
23
|
monthsShort?: string[];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export type DateUnitOptions =
|
|
26
|
+
export type DateUnitOptions =
|
|
27
|
+
| "second"
|
|
28
|
+
| "seconds"
|
|
29
|
+
| "minute"
|
|
30
|
+
| "minutes"
|
|
31
|
+
| "hour"
|
|
32
|
+
| "hours"
|
|
33
|
+
| "day"
|
|
34
|
+
| "days"
|
|
35
|
+
| "date"
|
|
36
|
+
| "month"
|
|
37
|
+
| "months"
|
|
38
|
+
| "year"
|
|
39
|
+
| "years";
|
|
27
40
|
|
|
28
41
|
export namespace date {
|
|
29
42
|
function isValid(date: number | string): boolean;
|
|
30
43
|
function extractDate(str: string, mask: string, locale?: DateLocale): Date;
|
|
31
|
-
function buildDate(options:
|
|
44
|
+
function buildDate(options: DateOptions, utc?: boolean): Date;
|
|
32
45
|
function getDayOfWeek(date: Date): number;
|
|
33
46
|
function getWeekOfYear(date: Date | number | string): number;
|
|
34
47
|
function isBetweenDates(date: Date | number | string, from: Date | number | string, to: Date | number | string, opts?: { inclusiveFrom: boolean; inclusiveTo: boolean; onlyDate: boolean }): boolean;
|
|
35
|
-
function addToDate(date: Date | number | string, options:
|
|
36
|
-
function subtractFromDate(date: Date | number | string, options:
|
|
37
|
-
function adjustDate(date: Date | number | string, options:
|
|
48
|
+
function addToDate(date: Date | number | string, options: DateOptions): Date;
|
|
49
|
+
function subtractFromDate(date: Date | number | string, options: DateOptions): Date;
|
|
50
|
+
function adjustDate(date: Date | number | string, options: DateOptions, utc?: boolean): Date;
|
|
38
51
|
function startOfDate(date: Date | number | string, option: DateUnitOptions, utc?: boolean): Date;
|
|
39
52
|
function endOfDate(date: Date | number | string, option: DateUnitOptions, utc?: boolean): Date;
|
|
40
53
|
function getMaxDate(date: Date | number | string, ...args: (Date | number | string)[]): Date;
|
|
41
54
|
function getMinDate(date: Date | number | string, ...args: (Date | number | string)[]): Date;
|
|
42
|
-
// TODO: (Qv3) uniform "unit" to `DateUnitOptions` interface
|
|
43
55
|
function getDateDiff(date: Date | number | string, subtract: Date | number | string, unit?: `${DateUnitOptions}s`): number;
|
|
44
56
|
function getDayOfYear(date: Date | number | string): number;
|
|
45
57
|
function inferDateFormat(date: Date | number | string): "date" | "number" | "string";
|
package/package.json
CHANGED
|
@@ -45,6 +45,7 @@ $field-transition-label-right-up: .324s cubic-bezier(.4,0,.2,1)
|
|
|
45
45
|
line-height: 1
|
|
46
46
|
color: rgba(0,0,0,.54)
|
|
47
47
|
padding: 8px 12px 0
|
|
48
|
+
backface-visibility: hidden
|
|
48
49
|
|
|
49
50
|
&--animated
|
|
50
51
|
transform: translateY(100%)
|
|
@@ -190,6 +191,7 @@ $field-transition-label-right-up: .324s cubic-bezier(.4,0,.2,1)
|
|
|
190
191
|
text-transform: inherit
|
|
191
192
|
transform-origin: left top
|
|
192
193
|
transition: transform $field-transition, max-width $field-transition-label-right-up
|
|
194
|
+
backface-visibility: hidden
|
|
193
195
|
|
|
194
196
|
&--float .q-field__label
|
|
195
197
|
max-width: 133%
|
|
@@ -33,7 +33,7 @@ export default createComponent({
|
|
|
33
33
|
? shouldFocus
|
|
34
34
|
: props.noErrorFocus !== true
|
|
35
35
|
|
|
36
|
-
validateIndex
|
|
36
|
+
const index = ++validateIndex
|
|
37
37
|
|
|
38
38
|
const emitEvent = (res, ref) => {
|
|
39
39
|
emit('validation-' + (res === true ? 'success' : 'error'), ref)
|
|
@@ -47,7 +47,7 @@ export default createComponent({
|
|
|
47
47
|
promises.push(
|
|
48
48
|
valid.then(
|
|
49
49
|
valid => ({ valid, comp }),
|
|
50
|
-
|
|
50
|
+
err => ({ valid: false, comp, err })
|
|
51
51
|
)
|
|
52
52
|
)
|
|
53
53
|
}
|
|
@@ -71,34 +71,33 @@ export default createComponent({
|
|
|
71
71
|
return Promise.resolve(true)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return Promise.all(promises).then(
|
|
77
|
-
res => {
|
|
78
|
-
if (index === validateIndex) {
|
|
79
|
-
const errors = res.filter(r => r.valid !== true)
|
|
74
|
+
return Promise.all(promises).then(res => {
|
|
75
|
+
const errors = res.filter(r => r.valid !== true)
|
|
80
76
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
if (errors.length === 0) {
|
|
78
|
+
index === validateIndex && emitEvent(true)
|
|
79
|
+
return true
|
|
80
|
+
}
|
|
85
81
|
|
|
86
|
-
|
|
82
|
+
const { valid, comp, err } = errors[ 0 ]
|
|
87
83
|
|
|
88
|
-
|
|
84
|
+
// if not outdated already
|
|
85
|
+
if (index === validateIndex) {
|
|
86
|
+
err !== void 0 && console.error(err)
|
|
89
87
|
|
|
90
|
-
|
|
91
|
-
focus === true
|
|
92
|
-
&& valid !== true
|
|
93
|
-
&& typeof comp.focus === 'function'
|
|
94
|
-
) {
|
|
95
|
-
comp.focus()
|
|
96
|
-
}
|
|
88
|
+
emitEvent(false, comp)
|
|
97
89
|
|
|
98
|
-
|
|
90
|
+
if (
|
|
91
|
+
focus === true
|
|
92
|
+
&& valid !== true
|
|
93
|
+
&& typeof comp.focus === 'function'
|
|
94
|
+
) {
|
|
95
|
+
comp.focus()
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
|
-
|
|
98
|
+
|
|
99
|
+
return false
|
|
100
|
+
})
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
function resetValidation () {
|
|
@@ -112,8 +111,11 @@ export default createComponent({
|
|
|
112
111
|
function submit (evt) {
|
|
113
112
|
evt !== void 0 && stopAndPrevent(evt)
|
|
114
113
|
|
|
114
|
+
const index = validateIndex + 1
|
|
115
|
+
|
|
115
116
|
validate().then(val => {
|
|
116
|
-
if
|
|
117
|
+
// if not outdated && validation succeeded
|
|
118
|
+
if (index === validateIndex && val === true) {
|
|
117
119
|
if (props.onSubmit !== void 0) {
|
|
118
120
|
emit('submit', evt)
|
|
119
121
|
}
|
|
@@ -84,7 +84,14 @@ export default function (focused, innerLoading) {
|
|
|
84
84
|
else if (isDirtyModel.value === false) {
|
|
85
85
|
isDirtyModel.value = true
|
|
86
86
|
|
|
87
|
-
if (
|
|
87
|
+
if (
|
|
88
|
+
hasActiveRules.value === true
|
|
89
|
+
&& props.lazyRules !== 'ondemand'
|
|
90
|
+
// Don't re-trigger if it's already in progress;
|
|
91
|
+
// It might mean that focus switched to submit btn and
|
|
92
|
+
// QForm's submit() has been called already (ENTER key)
|
|
93
|
+
&& innerLoading.value === false
|
|
94
|
+
) {
|
|
88
95
|
debouncedValidate()
|
|
89
96
|
}
|
|
90
97
|
}
|
|
@@ -110,7 +117,7 @@ export default function (focused, innerLoading) {
|
|
|
110
117
|
return true
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
validateIndex
|
|
120
|
+
const index = ++validateIndex
|
|
114
121
|
|
|
115
122
|
if (innerLoading.value !== true && props.lazyRules !== true) {
|
|
116
123
|
isDirtyModel.value = true
|
|
@@ -127,9 +134,7 @@ export default function (focused, innerLoading) {
|
|
|
127
134
|
innerErrorMessage.value = m
|
|
128
135
|
}
|
|
129
136
|
|
|
130
|
-
|
|
131
|
-
innerLoading.value = false
|
|
132
|
-
}
|
|
137
|
+
innerLoading.value = false
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
const promises = []
|
|
@@ -159,35 +164,26 @@ export default function (focused, innerLoading) {
|
|
|
159
164
|
return true
|
|
160
165
|
}
|
|
161
166
|
|
|
162
|
-
|
|
163
|
-
innerLoading.value = true
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const index = validateIndex
|
|
167
|
+
innerLoading.value = true
|
|
167
168
|
|
|
168
169
|
return Promise.all(promises).then(
|
|
169
170
|
res => {
|
|
170
|
-
if (index !== validateIndex) {
|
|
171
|
-
return true
|
|
172
|
-
}
|
|
173
|
-
|
|
174
171
|
if (res === void 0 || Array.isArray(res) === false || res.length === 0) {
|
|
175
|
-
update(false)
|
|
172
|
+
index === validateIndex && update(false)
|
|
176
173
|
return true
|
|
177
174
|
}
|
|
178
175
|
|
|
179
176
|
const msg = res.find(r => r === false || typeof r === 'string')
|
|
180
|
-
update(msg !== void 0, msg)
|
|
177
|
+
index === validateIndex && update(msg !== void 0, msg)
|
|
181
178
|
return msg === void 0
|
|
182
179
|
},
|
|
183
180
|
e => {
|
|
184
181
|
if (index === validateIndex) {
|
|
185
182
|
console.error(e)
|
|
186
183
|
update(true)
|
|
187
|
-
return false
|
|
188
184
|
}
|
|
189
185
|
|
|
190
|
-
return
|
|
186
|
+
return false
|
|
191
187
|
}
|
|
192
188
|
)
|
|
193
189
|
}
|
package/src/utils/date.js
CHANGED
|
@@ -174,15 +174,18 @@ function formatTimezone (offset, delimeter = '') {
|
|
|
174
174
|
function applyYearMonthDayChange (date, mod, sign) {
|
|
175
175
|
let
|
|
176
176
|
year = date.getFullYear(),
|
|
177
|
-
month = date.getMonth()
|
|
178
|
-
day = date.getDate()
|
|
177
|
+
month = date.getMonth()
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
const day = date.getDate()
|
|
180
|
+
|
|
181
|
+
if (mod.year !== void 0) {
|
|
182
|
+
year += sign * mod.year
|
|
183
|
+
delete mod.year
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
if (mod.
|
|
185
|
-
month += sign * mod.
|
|
186
|
+
if (mod.month !== void 0) {
|
|
187
|
+
month += sign * mod.month
|
|
188
|
+
delete mod.month
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
date.setDate(1)
|
|
@@ -192,30 +195,14 @@ function applyYearMonthDayChange (date, mod, sign) {
|
|
|
192
195
|
date.setMonth(month)
|
|
193
196
|
date.setDate(Math.min(day, daysInMonth(date)))
|
|
194
197
|
|
|
195
|
-
if (mod.
|
|
196
|
-
date.setDate(date.getDate() + sign * mod.
|
|
198
|
+
if (mod.date !== void 0) {
|
|
199
|
+
date.setDate(date.getDate() + sign * mod.date)
|
|
200
|
+
delete mod.date
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
return date
|
|
200
204
|
}
|
|
201
205
|
|
|
202
|
-
function getChange (date, mod, sign) {
|
|
203
|
-
const
|
|
204
|
-
d = new Date(date),
|
|
205
|
-
t = mod.years !== void 0 || mod.months !== void 0 || mod.days !== void 0
|
|
206
|
-
? applyYearMonthDayChange(d, mod, sign)
|
|
207
|
-
: d
|
|
208
|
-
|
|
209
|
-
for (const key in mod) {
|
|
210
|
-
if (key !== 'years' && key !== 'months' && key !== 'days') {
|
|
211
|
-
const op = capitalize(key)
|
|
212
|
-
t[ `set${ op }` ](t[ `get${ op }` ]() + sign * mod[ key ])
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return t
|
|
217
|
-
}
|
|
218
|
-
|
|
219
206
|
function applyYearMonthDay (date, mod, middle) {
|
|
220
207
|
const
|
|
221
208
|
year = mod.year !== void 0 ? mod.year : date[ `get${ middle }FullYear` ](),
|
|
@@ -230,22 +217,86 @@ function applyYearMonthDay (date, mod, middle) {
|
|
|
230
217
|
date[ `set${ middle }Month` ](month)
|
|
231
218
|
date[ `set${ middle }Date` ](day)
|
|
232
219
|
|
|
220
|
+
delete mod.year
|
|
221
|
+
delete mod.month
|
|
222
|
+
delete mod.date
|
|
223
|
+
|
|
233
224
|
return date
|
|
234
225
|
}
|
|
235
226
|
|
|
236
|
-
|
|
227
|
+
function getChange (date, rawMod, sign) {
|
|
237
228
|
const
|
|
229
|
+
mod = normalizeMod(rawMod),
|
|
230
|
+
d = new Date(date),
|
|
231
|
+
t = mod.year !== void 0 || mod.month !== void 0 || mod.date !== void 0
|
|
232
|
+
? applyYearMonthDayChange(d, mod, sign) // removes year/month/day
|
|
233
|
+
: d
|
|
234
|
+
|
|
235
|
+
for (const key in mod) {
|
|
236
|
+
const op = capitalize(key)
|
|
237
|
+
t[ `set${ op }` ](t[ `get${ op }` ]() + sign * mod[ key ])
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return t
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function normalizeMod (mod) {
|
|
244
|
+
const acc = { ...mod }
|
|
245
|
+
|
|
246
|
+
if (mod.years !== void 0) {
|
|
247
|
+
acc.year = mod.years
|
|
248
|
+
delete acc.years
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (mod.months !== void 0) {
|
|
252
|
+
acc.month = mod.months
|
|
253
|
+
delete acc.months
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (mod.days !== void 0) {
|
|
257
|
+
acc.date = mod.days
|
|
258
|
+
delete acc.days
|
|
259
|
+
}
|
|
260
|
+
if (mod.day !== void 0) {
|
|
261
|
+
acc.date = mod.day
|
|
262
|
+
delete acc.day
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (mod.hour !== void 0) {
|
|
266
|
+
acc.hours = mod.hour
|
|
267
|
+
delete acc.hour
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (mod.minute !== void 0) {
|
|
271
|
+
acc.minutes = mod.minute
|
|
272
|
+
delete acc.minute
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (mod.second !== void 0) {
|
|
276
|
+
acc.seconds = mod.second
|
|
277
|
+
delete acc.second
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (mod.millisecond !== void 0) {
|
|
281
|
+
acc.milliseconds = mod.millisecond
|
|
282
|
+
delete acc.millisecond
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return acc
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function adjustDate (date, rawMod, utc) {
|
|
289
|
+
const
|
|
290
|
+
mod = normalizeMod(rawMod),
|
|
238
291
|
middle = utc === true ? 'UTC' : '',
|
|
239
292
|
d = new Date(date),
|
|
240
293
|
t = mod.year !== void 0 || mod.month !== void 0 || mod.date !== void 0
|
|
241
|
-
? applyYearMonthDay(d, mod, middle)
|
|
294
|
+
? applyYearMonthDay(d, mod, middle) // removes year/month/day
|
|
242
295
|
: d
|
|
243
296
|
|
|
244
297
|
for (const key in mod) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
t[ `set${ middle }${ op }` ](mod[ key ])
|
|
248
|
-
}
|
|
298
|
+
const op = key.charAt(0).toUpperCase() + key.slice(1)
|
|
299
|
+
t[ `set${ middle }${ op }` ](mod[ key ])
|
|
249
300
|
}
|
|
250
301
|
|
|
251
302
|
return t
|
|
@@ -479,16 +530,23 @@ export function startOfDate (date, unit, utc) {
|
|
|
479
530
|
|
|
480
531
|
switch (unit) {
|
|
481
532
|
case 'year':
|
|
533
|
+
case 'years':
|
|
482
534
|
t[ `${ prefix }Month` ](0)
|
|
483
535
|
case 'month':
|
|
536
|
+
case 'months':
|
|
484
537
|
t[ `${ prefix }Date` ](1)
|
|
485
538
|
case 'day':
|
|
539
|
+
case 'days':
|
|
540
|
+
case 'date':
|
|
486
541
|
t[ `${ prefix }Hours` ](0)
|
|
487
542
|
case 'hour':
|
|
543
|
+
case 'hours':
|
|
488
544
|
t[ `${ prefix }Minutes` ](0)
|
|
489
545
|
case 'minute':
|
|
546
|
+
case 'minutes':
|
|
490
547
|
t[ `${ prefix }Seconds` ](0)
|
|
491
548
|
case 'second':
|
|
549
|
+
case 'seconds':
|
|
492
550
|
t[ `${ prefix }Milliseconds` ](0)
|
|
493
551
|
}
|
|
494
552
|
return t
|
|
@@ -501,16 +559,23 @@ export function endOfDate (date, unit, utc) {
|
|
|
501
559
|
|
|
502
560
|
switch (unit) {
|
|
503
561
|
case 'year':
|
|
562
|
+
case 'years':
|
|
504
563
|
t[ `${ prefix }Month` ](11)
|
|
505
564
|
case 'month':
|
|
565
|
+
case 'months':
|
|
506
566
|
t[ `${ prefix }Date` ](daysInMonth(t))
|
|
507
567
|
case 'day':
|
|
568
|
+
case 'days':
|
|
569
|
+
case 'date':
|
|
508
570
|
t[ `${ prefix }Hours` ](23)
|
|
509
571
|
case 'hour':
|
|
572
|
+
case 'hours':
|
|
510
573
|
t[ `${ prefix }Minutes` ](59)
|
|
511
574
|
case 'minute':
|
|
575
|
+
case 'minutes':
|
|
512
576
|
t[ `${ prefix }Seconds` ](59)
|
|
513
577
|
case 'second':
|
|
578
|
+
case 'seconds':
|
|
514
579
|
t[ `${ prefix }Milliseconds` ](999)
|
|
515
580
|
}
|
|
516
581
|
return t
|
|
@@ -546,21 +611,28 @@ export function getDateDiff (date, subtract, unit = 'days') {
|
|
|
546
611
|
|
|
547
612
|
switch (unit) {
|
|
548
613
|
case 'years':
|
|
614
|
+
case 'year':
|
|
549
615
|
return (t.getFullYear() - sub.getFullYear())
|
|
550
616
|
|
|
551
617
|
case 'months':
|
|
618
|
+
case 'month':
|
|
552
619
|
return (t.getFullYear() - sub.getFullYear()) * 12 + t.getMonth() - sub.getMonth()
|
|
553
620
|
|
|
554
621
|
case 'days':
|
|
622
|
+
case 'day':
|
|
623
|
+
case 'date':
|
|
555
624
|
return getDiff(startOfDate(t, 'day'), startOfDate(sub, 'day'), MILLISECONDS_IN_DAY)
|
|
556
625
|
|
|
557
626
|
case 'hours':
|
|
627
|
+
case 'hour':
|
|
558
628
|
return getDiff(startOfDate(t, 'hour'), startOfDate(sub, 'hour'), MILLISECONDS_IN_HOUR)
|
|
559
629
|
|
|
560
630
|
case 'minutes':
|
|
631
|
+
case 'minute':
|
|
561
632
|
return getDiff(startOfDate(t, 'minute'), startOfDate(sub, 'minute'), MILLISECONDS_IN_MINUTE)
|
|
562
633
|
|
|
563
634
|
case 'seconds':
|
|
635
|
+
case 'second':
|
|
564
636
|
return getDiff(startOfDate(t, 'second'), startOfDate(sub, 'second'), 1000)
|
|
565
637
|
}
|
|
566
638
|
}
|
|
@@ -606,26 +678,33 @@ export function isSameDate (date, date2, unit) {
|
|
|
606
678
|
|
|
607
679
|
switch (unit) {
|
|
608
680
|
case 'second':
|
|
681
|
+
case 'seconds':
|
|
609
682
|
if (t.getSeconds() !== d.getSeconds()) {
|
|
610
683
|
return false
|
|
611
684
|
}
|
|
612
685
|
case 'minute': // intentional fall-through
|
|
686
|
+
case 'minutes':
|
|
613
687
|
if (t.getMinutes() !== d.getMinutes()) {
|
|
614
688
|
return false
|
|
615
689
|
}
|
|
616
690
|
case 'hour': // intentional fall-through
|
|
691
|
+
case 'hours':
|
|
617
692
|
if (t.getHours() !== d.getHours()) {
|
|
618
693
|
return false
|
|
619
694
|
}
|
|
620
695
|
case 'day': // intentional fall-through
|
|
696
|
+
case 'days':
|
|
697
|
+
case 'date':
|
|
621
698
|
if (t.getDate() !== d.getDate()) {
|
|
622
699
|
return false
|
|
623
700
|
}
|
|
624
701
|
case 'month': // intentional fall-through
|
|
702
|
+
case 'months':
|
|
625
703
|
if (t.getMonth() !== d.getMonth()) {
|
|
626
704
|
return false
|
|
627
705
|
}
|
|
628
706
|
case 'year': // intentional fall-through
|
|
707
|
+
case 'years':
|
|
629
708
|
if (t.getFullYear() !== d.getFullYear()) {
|
|
630
709
|
return false
|
|
631
710
|
}
|