Skip to content

Commit

Permalink
fixes #247 (set min time)
Browse files Browse the repository at this point in the history
  • Loading branch information
amsul committed Nov 11, 2013
1 parent 045ad12 commit 091a118
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ File | Contents | Size (min & gzip)
----------------------- | ------------------------ | ----------------------
`picker.js` | __Base *__ | 1.36kb
`picker.date.js` | Date picker | 2.05kb
`picker.time.js` | Time picker | 1.38kb
`picker.time.js` | Time picker | 1.37kb

__*__ The base script is **required** for any of the pickers to function.

Expand Down
9 changes: 6 additions & 3 deletions _raw/lib/picker.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ TimePicker.prototype.now = function( type, value/*, options*/ ) {
var date = new Date(),
dateMinutes = date.getHours() * MINUTES_IN_HOUR + date.getMinutes()

// Make sure “now” falls within the interval range.
dateMinutes -= dateMinutes % this.item.interval

// If the value is a number, adjust by that many intervals because
// the time has passed. In the case of “midnight” and a negative `min`,
// increase the value by 2. Otherwise increase it by 1.
Expand All @@ -244,12 +247,12 @@ TimePicker.prototype.now = function( type, value/*, options*/ ) {
*/
TimePicker.prototype.normalize = function( type, value/*, options*/ ) {

var minObject = this.item.min, interval = this.item.interval,
var interval = this.item.interval,

// If setting min and it doesn’t exist, don’t shift anything.
// If setting min time, don’t shift anything.
// Otherwise get the value and min difference and then
// normalize the difference with the interval.
difference = type == 'min' && !minObject ? 0 : ( value - minObject.pick ) % interval
difference = type == 'min' ? 0 : ( value - this.item.min.pick ) % interval

// If it’s a negative value, add one interval to keep it as “passed”.
return value - ( difference + ( value < 0 ? interval : 0 ) )
Expand Down
2 changes: 1 addition & 1 deletion lib/compressed/picker.time.js

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

9 changes: 6 additions & 3 deletions lib/picker.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ TimePicker.prototype.now = function( type, value/*, options*/ ) {
var date = new Date(),
dateMinutes = date.getHours() * MINUTES_IN_HOUR + date.getMinutes()

// Make sure “now” falls within the interval range.
dateMinutes -= dateMinutes % this.item.interval

// If the value is a number, adjust by that many intervals because
// the time has passed. In the case of “midnight” and a negative `min`,
// increase the value by 2. Otherwise increase it by 1.
Expand All @@ -244,12 +247,12 @@ TimePicker.prototype.now = function( type, value/*, options*/ ) {
*/
TimePicker.prototype.normalize = function( type, value/*, options*/ ) {

var minObject = this.item.min, interval = this.item.interval,
var interval = this.item.interval,

// If setting min and it doesn’t exist, don’t shift anything.
// If setting min time, don’t shift anything.
// Otherwise get the value and min difference and then
// normalize the difference with the interval.
difference = type == 'min' && !minObject ? 0 : ( value - minObject.pick ) % interval
difference = type == 'min' ? 0 : ( value - this.item.min.pick ) % interval

// If it’s a negative value, add one interval to keep it as “passed”.
return value - ( difference + ( value < 0 ? interval : 0 ) )
Expand Down
5 changes: 4 additions & 1 deletion tests/dev/time.htm
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ <h3><label for="input_01">Pick a date. Go ahead...</label></h3>
// [8,45]
// ],
// min: 4,
min: [ 5, 40 ],
// min: [ 5, 40 ],
// max: -2,
// max: [ 9, 0 ],
}),
picker = $input.pickatime('picker')

picker.set('min',[5,40])
picker.set('max',[22,20])

</script>


Expand Down

0 comments on commit 091a118

Please sign in to comment.