From 088b16656f26315a4518e3a491bc7ec0b26144c7 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Wed, 15 Jan 2025 13:44:07 +0100 Subject: [PATCH] fix(NcDateTimePickerNative): do not set invalid values Signed-off-by: Maksim Sukharev --- .../NcDateTimePickerNative.vue | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/components/NcDateTimePickerNative/NcDateTimePickerNative.vue b/src/components/NcDateTimePickerNative/NcDateTimePickerNative.vue index fb7eaad434..ed60f00fc1 100644 --- a/src/components/NcDateTimePickerNative/NcDateTimePickerNative.vue +++ b/src/components/NcDateTimePickerNative/NcDateTimePickerNative.vue @@ -13,29 +13,50 @@ All available types are: 'date', 'datetime-local', 'month', 'time' and 'week', p ### Examples -#### Usage: type='datetime-local' ```vue + ``` #### Usage: type='datetime-local' with min date and max date @@ -309,8 +330,7 @@ export default { input: ($event) => { if (isNaN($event.target.valueAsNumber)) { this.model = null - } - if (this.type === 'time') { + } else if (this.type === 'time') { const time = $event.target.value if (this.model === '') { // this case is because of Chrome bug @@ -321,21 +341,24 @@ export default { * @return {Date} new chosen Date() */ this.model = new Date(`${yyyy}-${MM}-${dd}T${time}`) + } else { + const { yyyy, MM, dd } = this.getReadableDate(this.model) + this.model = new Date(`${yyyy}-${MM}-${dd}T${time}`) } - const { yyyy, MM, dd } = this.getReadableDate(this.model) - this.model = new Date(`${yyyy}-${MM}-${dd}T${time}`) } else if (this.type === 'month') { const MM = (new Date($event.target.value).getMonth() + 1).toString().padStart(2, '0') if (this.model === '') { const { yyyy, dd, hh, mm } = this.getReadableDate(new Date()) this.model = new Date(`${yyyy}-${MM}-${dd}T${hh}:${mm}`) + } else { + const { yyyy, dd, hh, mm } = this.getReadableDate(this.model ?? new Date()) + this.model = new Date(`${yyyy}-${MM}-${dd}T${hh}:${mm}`) } - const { yyyy, dd, hh, mm } = this.getReadableDate(this.model) - this.model = new Date(`${yyyy}-${MM}-${dd}T${hh}:${mm}`) + } else { + const timezoneOffsetSeconds = new Date($event.target.valueAsNumber).getTimezoneOffset() * 1000 * 60 + const inputDateWithTimezone = $event.target.valueAsNumber + timezoneOffsetSeconds + this.model = new Date(inputDateWithTimezone) } - const timezoneOffsetSeconds = new Date($event.target.valueAsNumber).getTimezoneOffset() * 1000 * 60 - const inputDateWithTimezone = $event.target.valueAsNumber + timezoneOffsetSeconds - this.model = new Date(inputDateWithTimezone) }, } },