This repository was archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 529
Added the getTime method #40
Open
JordyMoos
wants to merge
2
commits into
weareoutman:gh-pages
Choose a base branch
from
JordyMoos:get-datetime
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -427,6 +427,30 @@ | |
| popover.css(styles); | ||
| }; | ||
|
|
||
| // The input can be changed by the user | ||
| // So before we can use this.hours/this.minutes we must update it | ||
| ClockPicker.prototype.parseInputValue = function(){ | ||
| var value = this.input.prop('value') || this.options['default'] || ''; | ||
|
|
||
| if (value === 'now') { | ||
| value = new Date(+ new Date() + this.options.fromnow); | ||
| } | ||
| if (value instanceof Date) { | ||
| value = value.getHours() + ':' + value.getMinutes(); | ||
| } | ||
|
|
||
| value = value.split(':'); | ||
|
|
||
| // Minutes can have AM/PM that needs to be removed | ||
| this.hours = + value[0] || 0; | ||
| this.minutes = + (value[1] + '').replace(/\D/g, '') || 0; | ||
|
|
||
| if (this.twelvehour) { | ||
| var period = (value[1] + '').replace(/\d+/g, '').toLowerCase(); | ||
| this.amOrPm = this.hours < 12 || period === 'am' ? 'AM' : 'PM'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 12:00AM and 12:00PM both get converted to 12:00PM.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattkrick You are right fixed the issue in this commit |
||
| } | ||
| }; | ||
|
|
||
| // Show popover | ||
| ClockPicker.prototype.show = function(e){ | ||
| // Not show again | ||
|
|
@@ -453,17 +477,9 @@ | |
| this.isAppended = true; | ||
| } | ||
|
|
||
| // Get the time | ||
| var value = ((this.input.prop('value') || this.options['default'] || '') + '').split(':'); | ||
| if (value[0] === 'now') { | ||
| var now = new Date(+ new Date() + this.options.fromnow); | ||
| value = [ | ||
| now.getHours(), | ||
| now.getMinutes() | ||
| ]; | ||
| } | ||
| this.hours = + value[0] || 0; | ||
| this.minutes = + value[1] || 0; | ||
| // Get the time from the input field | ||
| this.parseInputValue(); | ||
|
|
||
| this.spanHours.html(leadingZero(this.hours)); | ||
| this.spanMinutes.html(leadingZero(this.minutes)); | ||
|
|
||
|
|
@@ -670,6 +686,23 @@ | |
| this.fg.setAttribute('cy', cy); | ||
| }; | ||
|
|
||
| // Allow user to get time time as Date object | ||
| ClockPicker.prototype.getTime = function(callback) { | ||
| this.parseInputValue(); | ||
|
|
||
| var hours = this.hours; | ||
| if (this.options.twelvehour && hours < 12 && this.amOrPm === 'PM') { | ||
| hours += 12; | ||
| } | ||
|
|
||
| var selectedTime = new Date(); | ||
| selectedTime.setMinutes(this.minutes) | ||
| selectedTime.setHours(hours); | ||
| selectedTime.setSeconds(0); | ||
|
|
||
| return callback && callback.apply(this.element, selectedTime) || selectedTime; | ||
| } | ||
|
|
||
| // Hours and minutes are selected | ||
| ClockPicker.prototype.done = function() { | ||
| raiseCallback(this.options.beforeDone); | ||
|
|
@@ -712,18 +745,31 @@ | |
| // Extends $.fn.clockpicker | ||
| $.fn.clockpicker = function(option){ | ||
| var args = Array.prototype.slice.call(arguments, 1); | ||
| return this.each(function(){ | ||
|
|
||
| function handleClockPickerRequest() { | ||
| var $this = $(this), | ||
| data = $this.data('clockpicker'); | ||
| if (! data) { | ||
| var options = $.extend({}, ClockPicker.DEFAULTS, $this.data(), typeof option == 'object' && option); | ||
| $this.data('clockpicker', new ClockPicker($this, options)); | ||
| } else { | ||
| // Manual operatsions. show, hide, remove, e.g. | ||
| // Manual operations. show, hide, remove, getTime, e.g. | ||
| if (typeof data[option] === 'function') { | ||
| data[option].apply(data, args); | ||
| return data[option].apply(data, args); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // If we explicitly do a call on a single element then we can return the value (if needed) | ||
| // This allows us, for example, to return the value of getTime | ||
| if (this.length == 1) { | ||
| var returnValue = handleClockPickerRequest.apply(this[0]); | ||
|
|
||
| // If we do not have any return value then return the object itself so you can chain | ||
| return returnValue !== undefined ? returnValue : this; | ||
| } | ||
|
|
||
| // If we do have a list then we do not care about return values | ||
| return this.each(handleClockPickerRequest); | ||
| }; | ||
| }()); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the first
+be there? What does it do?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casts it to a number