mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
added support of 12 hours mode at altFieldDateFormat, fixes #66
This commit is contained in:
parent
8dbf738ea6
commit
44ce4aede2
12
dist/js/datepicker.js
vendored
12
dist/js/datepicker.js
vendored
@ -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;
|
||||
|
||||
4
dist/js/datepicker.min.js
vendored
4
dist/js/datepicker.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user