Properly support AM/PM time format
This commit is contained in:
parent
df120c4f26
commit
4b3e73889f
1 changed files with 22 additions and 9 deletions
|
@ -70,10 +70,19 @@ function rcube_calendar_ui(settings)
|
||||||
var parse_datetime = function(time, date)
|
var parse_datetime = function(time, date)
|
||||||
{
|
{
|
||||||
// we use the utility function from datepicker to parse dates
|
// we use the utility function from datepicker to parse dates
|
||||||
var date = $.datepicker.parseDate(datepicker_settings.dateFormat, date, datepicker_settings);
|
var date = date ? $.datepicker.parseDate(datepicker_settings.dateFormat, date, datepicker_settings) : new Date();
|
||||||
var time_arr = time.split(/[:.]/);
|
|
||||||
if (!isNaN(time_arr[0])) date.setHours(time_arr[0]);
|
var time_arr = time.replace(/\s*[ap]m?/i, '').replace(/0([0-9])/g, '$1').split(/[:.]/);
|
||||||
if (!isNaN(time_arr[1])) date.setMinutes(time_arr[1]);
|
if (!isNaN(time_arr[0])) {
|
||||||
|
date.setHours(time_arr[0]);
|
||||||
|
if (time.match(/pm?/i) && date.getHours() < 12)
|
||||||
|
date.setHours(parseInt(time_arr[0]) + 12);
|
||||||
|
else if (date.getHours() == 12)
|
||||||
|
date.setHours(0);
|
||||||
|
}
|
||||||
|
if (!isNaN(time_arr[1]))
|
||||||
|
date.setMinutes(time_arr[1]);
|
||||||
|
|
||||||
return date;
|
return date;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -947,7 +956,10 @@ function rcube_calendar_ui(settings)
|
||||||
|
|
||||||
// format time string
|
// format time string
|
||||||
var formattime = function(hour, minutes) {
|
var formattime = function(hour, minutes) {
|
||||||
return ((hour < 10) ? "0" : "") + hour + ((minutes < 10) ? ":0" : ":") + minutes;
|
var d = new Date();
|
||||||
|
d.setHours(hour);
|
||||||
|
d.setMinutes(minutes);
|
||||||
|
return $.fullCalendar.formatDate(d, settings['time_format'])
|
||||||
};
|
};
|
||||||
|
|
||||||
// if start date is changed, shift end date according to initial duration
|
// if start date is changed, shift end date according to initial duration
|
||||||
|
@ -974,7 +986,7 @@ function rcube_calendar_ui(settings)
|
||||||
var result = [];
|
var result = [];
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
var full = p.term - 1 > 0 || p.term.length > 1;
|
var full = p.term - 1 > 0 || p.term.length > 1;
|
||||||
var hours = full? p.term - 0 : now.getHours();
|
var hours = (full ? parse_datetime(p.term, '') : now).getHours();
|
||||||
var step = 15;
|
var step = 15;
|
||||||
var minutes = hours * 60 + (full ? 0 : now.getMinutes());
|
var minutes = hours * 60 + (full ? 0 : now.getMinutes());
|
||||||
var min = Math.ceil(minutes / step) * step % 60;
|
var min = Math.ceil(minutes / step) * step % 60;
|
||||||
|
@ -999,11 +1011,12 @@ function rcube_calendar_ui(settings)
|
||||||
// scroll to current time
|
// scroll to current time
|
||||||
var widget = $(this).autocomplete('widget');
|
var widget = $(this).autocomplete('widget');
|
||||||
var menu = $(this).data('autocomplete').menu;
|
var menu = $(this).data('autocomplete').menu;
|
||||||
var val = $(this).val();
|
var val = $(this).val().replace(/^(.+)(am?)/i, '0:$1').replace(/^(.+)(pm?)/i, '1:$1');
|
||||||
var li, html, offset = 0;
|
var li, html, offset = 0;
|
||||||
|
widget.css('width', '7em');
|
||||||
widget.children().each(function(){
|
widget.children().each(function(){
|
||||||
li = $(this);
|
li = $(this);
|
||||||
html = li.children().first().html();
|
html = li.children().first().html().replace(/^(.+)(am?)/i, '0:$1').replace(/^(.+)(pm?)/i, '1:$1');
|
||||||
if (html < val)
|
if (html < val)
|
||||||
offset += li.height();
|
offset += li.height();
|
||||||
if (html == val)
|
if (html == val)
|
||||||
|
|
Loading…
Add table
Reference in a new issue