-
Notifications
You must be signed in to change notification settings - Fork 53
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
Update index.js #18
base: main
Are you sure you want to change the base?
Update index.js #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,10 @@ | |
|
||
DayScheduleSelector.DEFAULTS = { | ||
days : [0, 1, 2, 3, 4, 5, 6], // Sun - Sat | ||
stringDays : ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | ||
startTime : '08:00', // HH:mm format | ||
endTime : '20:00', // HH:mm format | ||
timeFormat : 'hh:mm', // hh:mm or HH:MM | ||
interval : 30, // minutes | ||
template : '<div class="day-schedule-selector">' + | ||
'<table class="schedule-table">' + | ||
|
@@ -37,7 +39,7 @@ | |
* @public | ||
*/ | ||
DayScheduleSelector.prototype.renderHeader = function () { | ||
var stringDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] | ||
var stringDays = this.options.stringDays | ||
, days = this.options.days | ||
, html = ''; | ||
|
||
|
@@ -52,6 +54,7 @@ | |
DayScheduleSelector.prototype.renderRows = function () { | ||
var start = this.options.startTime | ||
, end = this.options.endTime | ||
, timeFormat = this.options.timeFormat | ||
, interval = this.options.interval | ||
, days = this.options.days | ||
, $el = this.$el.find('.schedule-rows'); | ||
|
@@ -61,7 +64,7 @@ | |
return '<td class="time-slot" data-time="' + hhmm(d) + '" data-day="' + days[i] + '"></td>' | ||
}).join(); | ||
|
||
$el.append('<tr><td class="time-label">' + hmmAmPm(d) + '</td>' + daysInARow + '</tr>'); | ||
$el.append('<tr><td class="time-label">' + hmmAmPm(d,timeFormat) + '</td>' + daysInARow + '</tr>'); | ||
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. See the comment below about using a |
||
}); | ||
}; | ||
|
||
|
@@ -242,11 +245,20 @@ | |
* @private | ||
* @returns {String} Time in H:mm format with am/pm, e.g. '9:30am' | ||
*/ | ||
function hmmAmPm(date) { | ||
function hmmAmPm(date,timeFormat) { | ||
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. There is a Instead of the How do you think about this? 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. Sorry, was too busy but flagged this to respond :) Your idea is good. Additionally it would be good to add a 'locale' option if you want to further improve it. I just needed those two options that's why I made it as simple as with timeFormat :) Thanks! |
||
var hours = date.getHours() | ||
, minutes = date.getMinutes() | ||
, ampm = hours >= 12 ? 'pm' : 'am'; | ||
return hours + ':' + ('0' + minutes).slice(-2) + ampm; | ||
|
||
|
||
if (timeFormat == 'hh:mm') { | ||
var hours = hours >= 13 ? hours - 12 : hours; | ||
var time = hours + ':' + ('0' + minutes).slice(-2) + ampm; | ||
} else { | ||
var time = hours + ':' + ('0' + minutes).slice(-2); | ||
} | ||
|
||
return time | ||
} | ||
|
||
/** | ||
|
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.
This is a good idea, and we should figure out a way to do internationalization for other labels, too. 👍