Skip to content

Commit 4bf8f5a

Browse files
authored
Merge pull request #8433 from nextcloud/8307-can-no-longer-edit-time
fix(events): do not discard text input of dates and times in event edit dialog
2 parents a2b6464 + 4efc441 commit 4bf8f5a

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"color-string": "^2.1.4",
6767
"core-js": "^3.49.0",
6868
"css-color-names": "^1.0.1",
69+
"datetime-locale-patterns": "^1.0.2",
6970
"debounce": "^3.0.0",
7071
"linkifyjs": "^4.3.3",
7172
"md5": "^2.3.0",

src/components/Shared/DatePicker.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
-->
55

66
<template>
7+
<!--
8+
`format` is specified as a workaround for https://github.com/nextcloud/calendar/issues/8307
9+
until the issue is fixed in `@nextcloud/vue`.
10+
11+
This works because `@vuepic/vue-datepicker` can use it to parse text inputs from the user
12+
when providing a format as pattern string (and not a one-way function).
13+
-->
714
<DateTimePicker
815
id="date-time-picker-input"
916
:min="minimumDate"
@@ -12,17 +19,22 @@
1219
:type="type"
1320
:hideLabel="true"
1421
class="date-time-picker"
22+
:format="formatStr"
1523
@blur="onBlur"
1624
@update:modelValue="onInput" />
1725
</template>
1826

1927
<script>
28+
import { getCanonicalLocale } from '@nextcloud/l10n'
2029
import {
2130
NcDateTimePicker as DateTimePicker,
2231
} from '@nextcloud/vue'
32+
import { getDateLocalePattern, getDateTimeLocalePattern, getTimeLocalePattern } from 'datetime-locale-patterns'
2333
import { mapStores } from 'pinia'
2434
import useDavRestrictionsStore from '../../store/davRestrictions.js'
2535
36+
const canonicalLocale = getCanonicalLocale()
37+
2638
export default {
2739
name: 'DatePicker',
2840
components: {
@@ -91,6 +103,28 @@ export default {
91103
92104
return this.max || new Date(this.davRestrictionsStore.maximumDate)
93105
},
106+
107+
/**
108+
* Returns the date format pattern for the current picker type.
109+
*
110+
* See https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
111+
*
112+
* @return {string | undefined} A format pattern or `undefined` to use the default `NcDateTimePicker` formatting.
113+
*/
114+
formatStr() {
115+
// Match logic from https://github.com/nextcloud-libraries/nextcloud-vue/blob/v9.8.0/src/components/NcDateTimePicker/NcDateTimePicker.vue#L549
116+
if (this.type === 'date' || this.type === 'date-range') {
117+
return getDateLocalePattern(canonicalLocale, { dateStyle: 'medium' })
118+
} else if (this.type === 'time' || this.type === 'time-range') {
119+
return getTimeLocalePattern(canonicalLocale, { timeStyle: 'short' })
120+
} else if (this.type === 'datetime' || this.type === 'datetime-range') {
121+
return getDateTimeLocalePattern(canonicalLocale, { dateStyle: 'medium', timeStyle: 'short' })
122+
} else {
123+
// 'datetime-locale-patterns' does not support `month` and `year`.
124+
// So fall back to default formatting.
125+
return undefined
126+
}
127+
},
94128
},
95129
96130
methods: {

0 commit comments

Comments
 (0)