Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ranges of minute feature #310

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
Binary file added assets/feature_minute_range.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
:disabled-hours="demo.options.disabledHours"
:enabled-dates="demo.options.enabledDates"
:minute-interval="demo.options.minuteInterval"
:start-minute="demo.options.startMinute"
:end-minute="demo.options.endMinute"
:first-day-of-week="demo.options.firstDayOfWeek"
:min-date="demo.options.minDate"
:max-date="demo.options.maxDate"
Expand Down Expand Up @@ -330,7 +332,7 @@
},
{
id: '4',
title: 'Time Picker - With small input (input-size="sm") & minute-interval="10"',
title: 'Time Picker - With small input (input-size="sm") & minute-interval="8" & start-minute="3" & end-minute="59"',
description: 'Time selector',
editOption: false,
initial: '11:26 am',
Expand All @@ -340,7 +342,9 @@
formatted: 'hh:mm a',
onlyTime: true,
color: 'firebrick',
minuteInterval: '10',
minuteInterval: '8',
startMinute: 3,
endMinute: 59,
label: 'Select time',
inputSize: 'sm',
id: 'TimePicker',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
})
}
const ArrayMinuteRange = (start, end, twoDigit, step = 1, disabledMinutes) => {
const len = Math.floor(end / step) - start
step = Math.trunc(step)
end = Math.min(end, 59)
const len = Math.ceil((end - start + 1) / step)

return Array(len).fill().map((_, idx) => {
const number = start + idx * step
Expand Down Expand Up @@ -94,6 +96,8 @@
value: { type: String, default: null },
format: { type: String, default: null },
minuteInterval: { type: [String, Number], default: 1 },
startMinute: { type: Number, default: 0 },
endMinute: { type: Number, default: 60 },
height: { type: Number, required: true },
color: { type: String, default: null },
inline: { type: Boolean, default: null },
Expand Down Expand Up @@ -142,7 +146,7 @@
},
minutes () {
const twoDigit = this.format.includes('mm') || this.format.includes('MM')
return ArrayMinuteRange(0, 60, twoDigit, this.minuteInterval, this._disabledMinutes)
return ArrayMinuteRange(this.startMinute, this.endMinute, twoDigit, this.minuteInterval, this._disabledMinutes)
},
apms () {
return this.isTwelveFormat
Expand Down Expand Up @@ -277,11 +281,11 @@
onScrollHours: debounce(function (scroll) {
const value = this.getValue(scroll)
const hour = this.isTwelveFormat
? this.apm
? this.apm.toLowerCase() === 'am'
? value + 1
: (value + 1 + 12)
:value
? this.apm
? this.apm.toLowerCase() === 'am'
? value + 1
: (value + 1 + 12)
: value
: value
if (this.isHoursDisabled(hour)) return
this.hour = hour === 24 && !this.isTwelveFormat ? 23 : hour
Expand Down
4 changes: 4 additions & 0 deletions src/VueCtkDateTimePicker/_subs/PickersContainer/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
:format="timeFormat"
:only-time="onlyTime"
:minute-interval="minuteInterval"
:start-minute="startMinute"
:end-minute="endMinute"
:visible="visible"
:height="height"
:disabled-hours="disabledHours"
Expand Down Expand Up @@ -120,6 +122,8 @@
onlyDate: { type: Boolean, default: false },
onlyTime: { type: Boolean, default: null },
minuteInterval: { type: [String, Number], default: 1 },
startMinute: { type: Number, default: 0 },
endMinute: { type: Number, default: 60 },
format: { type: String, default: 'YYYY-MM-DD hh:mm a' },
locale: { type: String, default: null },
maxDate: { type: String, default: null },
Expand Down
10 changes: 6 additions & 4 deletions src/VueCtkDateTimePicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
:only-time="onlyTime"
:only-date="hasOnlyDate"
:minute-interval="minuteInterval"
:start-minute="startMinute"
:end-minute="endMinute"
:locale="locale"
:min-date="minDate"
:max-date="maxDate"
Expand Down Expand Up @@ -100,8 +102,8 @@
}
}

const nearestMinutes = (interval, date, format) => {
const roundedMinutes = Math.ceil(date.minute() / interval) * interval
const nearestMinutes = (startMinute, interval, date, format) => {
const roundedMinutes = Math.ceil((date.minute() - startMinute) / interval) * interval + startMinute
return moment(date.clone().minute(roundedMinutes).second(0), format)
}

Expand Down Expand Up @@ -297,14 +299,14 @@
const dateToSend = dateTime
? moment(dateTime, 'YYYY-MM-DD HH:mm')
: null
const dateTimeToSend = dateToSend ? nearestMinutes(this.minuteInterval, moment(dateToSend), 'YYYY-MM-DD HH:mm').format(this.formatOutput) : null
const dateTimeToSend = dateToSend ? nearestMinutes(this.startMinute, this.minuteInterval, moment(dateToSend), 'YYYY-MM-DD HH:mm').format(this.formatOutput) : null
return dateTimeToSend
},
getDateTime () {
const date = this.value
? moment(this.value, this.formatOutput)
: null
return date ? nearestMinutes(this.minuteInterval, date, this.formatOutput).format('YYYY-MM-DD HH:mm') : null
return date ? nearestMinutes(this.startMinute, this.minuteInterval, date, this.formatOutput).format('YYYY-MM-DD HH:mm') : null
},
/**
* Closes the datepicker
Expand Down
2 changes: 2 additions & 0 deletions src/VueCtkDateTimePicker/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default {
format: { type: String, default: 'YYYY-MM-DD hh:mm a' },
outputFormat: { type: String, default: null },
minuteInterval: { type: [String, Number], default: 1 },
startMinute: { type: Number, default: 0 },
endMinute: { type: Number, default: 60 },
minDate: { type: String, default: null },
maxDate: { type: String, default: null },
autoClose: { type: Boolean, default: false },
Expand Down