Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"color-string": "^2.1.4",
"core-js": "^3.49.0",
"css-color-names": "^1.0.1",
"datetime-locale-patterns": "^1.0.2",
"debounce": "^3.0.0",
"linkifyjs": "^4.3.3",
"md5": "^2.3.0",
Expand Down
34 changes: 34 additions & 0 deletions src/components/Shared/DatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
-->

<template>
<!--
`format` is specified as a workaround for https://github.com/nextcloud/calendar/issues/8307
until the issue is fixed in `@nextcloud/vue`.

This works because `@vuepic/vue-datepicker` can use it to parse text inputs from the user
when providing a format as pattern string (and not a one-way function).
-->
<DateTimePicker
id="date-time-picker-input"
:min="minimumDate"
Expand All @@ -12,17 +19,22 @@
:type="type"
:hideLabel="true"
class="date-time-picker"
:format="formatStr"
@blur="onBlur"
@update:modelValue="onInput" />
</template>

<script>
import { getCanonicalLocale } from '@nextcloud/l10n'
import {
NcDateTimePicker as DateTimePicker,
} from '@nextcloud/vue'
import { getDateLocalePattern, getDateTimeLocalePattern, getTimeLocalePattern } from 'datetime-locale-patterns'
import { mapStores } from 'pinia'
import useDavRestrictionsStore from '../../store/davRestrictions.js'

const canonicalLocale = getCanonicalLocale()

export default {
name: 'DatePicker',
components: {
Expand Down Expand Up @@ -91,6 +103,28 @@ export default {

return this.max || new Date(this.davRestrictionsStore.maximumDate)
},

/**
* Returns the date format pattern for the current picker type.
*
* See https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
*
* @return {string | undefined} A format pattern or `undefined` to use the default `NcDateTimePicker` formatting.
*/
formatStr() {
// Match logic from https://github.com/nextcloud-libraries/nextcloud-vue/blob/v9.8.0/src/components/NcDateTimePicker/NcDateTimePicker.vue#L549
if (this.type === 'date' || this.type === 'date-range') {
return getDateLocalePattern(canonicalLocale, { dateStyle: 'medium' })
} else if (this.type === 'time' || this.type === 'time-range') {
return getTimeLocalePattern(canonicalLocale, { timeStyle: 'short' })
} else if (this.type === 'datetime' || this.type === 'datetime-range') {
return getDateTimeLocalePattern(canonicalLocale, { dateStyle: 'medium', timeStyle: 'short' })
} else {
// 'datetime-locale-patterns' does not support `month` and `year`.
// So fall back to default formatting.
return undefined
}
},
},

methods: {
Expand Down
Loading