added support of 12 hours mode at altFieldDateFormat, fixes #66

This commit is contained in:
t1m0n 2016-06-06 11:01:33 +03:00
parent 8dbf738ea6
commit 44ce4aede2
5 changed files with 47 additions and 13 deletions

12
dist/js/datepicker.js vendored
View File

@ -362,11 +362,12 @@
d = datepicker.getParsedDate(date),
fullHours = d.fullHours,
hours = d.hours,
ampm = string.match(boundary('aa')) || string.match(boundary('AA')),
dayPeriod = 'am',
validHours;
if (this.opts.timepicker && this.timepicker && this.ampm) {
validHours = this.timepicker._getValidHoursFromDate(date);
if (this.opts.timepicker && this.timepicker && ampm) {
validHours = this.timepicker._getValidHoursFromDate(date, ampm);
fullHours = leadingZero(validHours.hours);
hours = validHours.hours;
dayPeriod = validHours.dayPeriod;
@ -2055,10 +2056,11 @@
/**
* Calculates valid hour value to display in text input and datepicker's body.
* @param date {Date|Number} - date or hours
* @param [ampm] {Boolean} - 12 hours mode
* @returns {{hours: *, dayPeriod: string}}
* @private
*/
_getValidHoursFromDate: function (date) {
_getValidHoursFromDate: function (date, ampm) {
var d = date,
hours = date;
@ -2067,10 +2069,10 @@
hours = d.hours;
}
var ampm = this.d.ampm,
var _ampm = ampm || this.d.ampm,
dayPeriod = 'am';
if (ampm) {
if (_ampm) {
switch(true) {
case hours == 0:
hours = 12;

File diff suppressed because one or more lines are too long

View File

@ -362,11 +362,12 @@
d = datepicker.getParsedDate(date),
fullHours = d.fullHours,
hours = d.hours,
ampm = string.match(boundary('aa')) || string.match(boundary('AA')),
dayPeriod = 'am',
validHours;
if (this.opts.timepicker && this.timepicker && this.ampm) {
validHours = this.timepicker._getValidHoursFromDate(date);
if (this.opts.timepicker && this.timepicker && ampm) {
validHours = this.timepicker._getValidHoursFromDate(date, ampm);
fullHours = leadingZero(validHours.hours);
hours = validHours.hours;
dayPeriod = validHours.dayPeriod;

View File

@ -171,10 +171,11 @@
/**
* Calculates valid hour value to display in text input and datepicker's body.
* @param date {Date|Number} - date or hours
* @param [ampm] {Boolean} - 12 hours mode
* @returns {{hours: *, dayPeriod: string}}
* @private
*/
_getValidHoursFromDate: function (date) {
_getValidHoursFromDate: function (date, ampm) {
var d = date,
hours = date;
@ -183,10 +184,10 @@
hours = d.hours;
}
var ampm = this.d.ampm,
var _ampm = ampm || this.d.ampm,
dayPeriod = 'am';
if (ampm) {
if (_ampm) {
switch(true) {
case hours == 0:
hours = 12;

View File

@ -189,6 +189,36 @@ describe('Options', function () {
dp.selectDate(date);
assert.equal(dp.$altField.val(), '17-12-2015');
});
it('should support 24 hour mode, even if main date format is in 12', function () {
var date = new Date(2015, 11, 17, 22, 47);
dp = $input.datepicker({
timepicker: true,
timeFormat: 'hh:ii aa',
altField: '.alt-field',
altFieldDateFormat: 'dd-mm-yyyy hh:ii'
}).data('datepicker');
dp.selectDate(date);
assert.equal(dp.$altField.val(), '17-12-2015 22:47');
});
it('should support 12 hour mode', function () {
var date = new Date(2015, 11, 17, 22, 47);
dp = $input.datepicker({
timepicker: true,
timeFormat: 'hh:ii',
altField: '.alt-field',
altFieldDateFormat: 'dd-mm-yyyy hh:ii aa'
}).data('datepicker');
dp.selectDate(date);
assert.equal(dp.$altField.val(), '17-12-2015 10:47 pm');
})
});
@ -216,7 +246,7 @@ describe('Options', function () {
expect(dp.selectedDates).to.have.length(1)
})
})
});
describe('keyboardNav', function () {
var year = 2015,