Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Close buefy#2000 add time-creator prop to timepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
jtommy authored and LeoMouyna committed Jan 6, 2020
1 parent 3723666 commit a987e25
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docs/data/routes.json
Expand Up @@ -346,7 +346,8 @@
"/",
"documentation",
"documentation/timepicker"
]
],
"isUpdated": true
},
"documentation/clockpicker": {
"title": "Clockpicker",
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/components/timepicker/api/timepicker.js
Expand Up @@ -141,6 +141,13 @@ export default [
values: '-',
default: '-'
},
{
name: '<code>time-creator</code>',
description: 'Function used internally to create a new Date instance',
type: 'Function',
values: '—',
default: '<code>() => new Date()</code>'
},
{
name: 'Any native attribute',
description: '—',
Expand Down
14 changes: 12 additions & 2 deletions src/utils/TimepickerMixin.js
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/utils/config.js
Expand Up @@ -19,6 +19,7 @@ let config = {
defaultDateFormatter: null,
defaultDateParser: null,
defaultDateCreator: null,
defaultTimeCreator: null,
defaultDayNames: null,
defaultMonthNames: null,
defaultFirstDayOfWeek: null,
Expand Down

0 comments on commit a987e25

Please sign in to comment.