diff --git a/CHANGELOG.md b/CHANGELOG.md index 68d8d7dcd..4c92c6216 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Add more customization variables for dropdown and loading (thanks @HugoHeneault) * Add more customization variables for datepicker (thanks @service-paradis) * Add ``defaultDatepickerMobileModal`` constructor option (thanks @ievhen-soloviov) +* #2000 Add ``time-creator`` prop to timepicker ### Fixes diff --git a/docs/data/routes.json b/docs/data/routes.json index 19076cde9..cbf92f84e 100644 --- a/docs/data/routes.json +++ b/docs/data/routes.json @@ -346,7 +346,8 @@ "/", "documentation", "documentation/timepicker" - ] + ], + "isUpdated": true }, "documentation/clockpicker": { "title": "Clockpicker", diff --git a/docs/pages/components/timepicker/api/timepicker.js b/docs/pages/components/timepicker/api/timepicker.js index 763db2bb3..b329e35e9 100644 --- a/docs/pages/components/timepicker/api/timepicker.js +++ b/docs/pages/components/timepicker/api/timepicker.js @@ -141,6 +141,13 @@ export default [ values: '-', default: '-' }, + { + name: 'time-creator', + description: 'Function used internally to create a new Date instance', + type: 'Function', + values: '—', + default: '() => new Date()' + }, { name: 'Any native attribute', description: '—', diff --git a/src/utils/TimepickerMixin.js b/src/utils/TimepickerMixin.js index 8806f4d4c..03b61409d 100644 --- a/src/utils/TimepickerMixin.js +++ b/src/utils/TimepickerMixin.js @@ -45,7 +45,7 @@ const defaultTimeParser = (timeString, vm) => { if (vm.computedValue && !isNaN(vm.computedValue)) { d = new Date(vm.computedValue) } else { - d = new Date() + d = vm.timeCreator() d.setMilliseconds(0) } d.setSeconds(seconds) @@ -119,6 +119,16 @@ export default { return config.defaultTimepickerMobileNative } }, + timeCreator: { + type: Function, + default: () => { + if (typeof config.defaultTimeCreator === 'function') { + return config.defaultTimeCreator() + } else { + return new Date() + } + } + }, position: String, unselectableTimes: Array, openOnFocus: Boolean, @@ -289,7 +299,7 @@ export default { if (this.computedValue && !isNaN(this.computedValue)) { time = new Date(this.computedValue) } else { - time = new Date() + time = this.timeCreator() time.setMilliseconds(0) } time.setHours(hours) diff --git a/src/utils/config.js b/src/utils/config.js index 559c07091..e660e28a0 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -19,6 +19,7 @@ let config = { defaultDateFormatter: null, defaultDateParser: null, defaultDateCreator: null, + defaultTimeCreator: null, defaultDayNames: null, defaultMonthNames: null, defaultFirstDayOfWeek: null,