same(a1, a2, message);
}
+function addMonths(date, offset) {
+ var maxDay = 32 - new Date(date.getFullYear(), date.getMonth() + offset, 32).getDate();
+ date.setDate(Math.min(date.getDate(), maxDay));
+ date.setMonth(date.getMonth() + offset);
+ return date;
+}
+
function init(id, options) {
$.datepicker.setDefaults($.datepicker.regional['']);
- var inp = $(id);
- inp.datepicker($.extend({duration: ''}, options || {}));
- return inp;
+ return $(id).datepicker($.extend({duration: ''}, options || {}));
}
var PROP_NAME = 'datepicker';
module("datepicker: core");
test('baseStructure', function() {
- var dp = $('#ui-datepicker-div');
var inp = init('#inp');
inp.focus();
+ var dp = $('#ui-datepicker-div');
var iframe = ($.browser.msie && parseInt($.browser.version) < 7);
ok(dp.is(':visible'), 'Structure - datepicker visible');
ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left');
inp = init('#inp', {numberOfMonths: 2});
inp.focus();
ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month');
- equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi [2] - child count');
- month = dp.children(':first');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first month division');
- month = dp.children(':eq(1)');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second month division');
+ equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure multi [2] - child count');
+ var child = dp.children(':first');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first month division');
+ child = dp.children(':eq(1)');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second month division');
+ child = dp.children(':eq(2)');
+ ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2] - row break');
inp.datepicker('hide').datepicker('destroy');
// Multi-month [2, 2]
inp = init('#inp', {numberOfMonths: [2, 2]});
inp.focus();
ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month');
- equals(dp.children().length, 4 + (iframe ? 1 : 0), 'Structure multi [2,2] - child count');
- month = dp.children(':first');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first month division');
- month = dp.children(':eq(1)');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second month division');
- month = dp.children(':eq(2)');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third month division');
- month = dp.children(':eq(3)');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth month division');
+ equals(dp.children().length, 6 + (iframe ? 1 : 0), 'Structure multi [2,2] - child count');
+ child = dp.children(':first');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first month division');
+ child = dp.children(':eq(1)');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second month division');
+ child = dp.children(':eq(2)');
+ ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row break');
+ child = dp.children(':eq(3)');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third month division');
+ child = dp.children(':eq(4)');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth month division');
+ child = dp.children(':eq(5)');
+ ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row break');
inp.datepicker('hide').datepicker('destroy');
// Inline
var header = dp.children(':first');
ok(header.is('div.ui-datepicker-header'), 'Structure inline - header division');
equals(header.children().length, 3, 'Structure inline - header child count');
- var table = month.children(':eq(1)');
+ var table = dp.children(':eq(1)');
ok(table.is('table.ui-datepicker-calendar'), 'Structure inline - month table');
ok(table.children(':first').is('thead'), 'Structure inline - month table thead');
ok(table.children(':eq(1)').is('tbody'), 'Structure inline - month table body');
inl = init('#inl', {numberOfMonths: 2});
dp = inl.children();
ok(dp.is('.ui-datepicker-inline') && dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div');
- equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi - child count');
- month = dp.children(':first');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi - first month division');
- month = dp.children(':eq(1)');
- ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi - second month division');
+ equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure inline multi - child count');
+ child = dp.children(':first');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure inline multi - first month division');
+ child = dp.children(':eq(1)');
+ ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure inline multi - second month division');
+ child = dp.children(':eq(2)');
+ ok(child.is('div.ui-datepicker-row-break'), 'Structure inline multi - row break');
inl.datepicker('destroy');
});
inp.datepicker('option', {defaultDate: ' -1 m '}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
- date = new Date();
- date.setMonth(date.getMonth() - 1);
+ date = addMonths(new Date(), -1);
equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m');
inp.datepicker('option', {defaultDate: '+2M'}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
- date.setMonth(date.getMonth() + 3);
+ date = addMonths(new Date(), 2);
equalsDate(inp.datepicker('getDate'), date, 'Default date +2M');
inp.datepicker('option', {defaultDate: '-2y'}).
datepicker('hide').val('').datepicker('show').
inp.datepicker('option', {defaultDate: '+1M +10d'}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
- date = new Date();
- date.setMonth(date.getMonth() + 1);
+ date = addMonths(new Date(), 1);
date.setDate(date.getDate() + 10);
equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d');
date = new Date(2007, 1 - 1, 26);
equals(dp.find('.ui-datepicker-prev').text(), 'Prev', 'Navigation prev - default');
equals(dp.find('.ui-datepicker-current').text(), 'Today', 'Navigation current - default');
equals(dp.find('.ui-datepicker-next').text(), 'Next', 'Navigation next - default');
- inp.datepicker('hide').datepicker('option', {navigationAsDateFormat: true, prevText: '< M', currentText: 'MM', nextText: 'M >'}).val('02/04/2008').datepicker('show');
+ inp.datepicker('hide').datepicker('option', {navigationAsDateFormat: true, prevText: '< M', currentText: 'MM', nextText: 'M >'}).
+ val('02/04/2008').datepicker('show');
var longNames = $.datepicker.regional[''].monthNames;
var shortNames = $.datepicker.regional[''].monthNamesShort;
var date = new Date();
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
equalsDate(inp.datepicker('getDate'), date,
'Min/max - -1w, +1 M +10 D - ctrl+pgup');
- date = new Date();
- date.setMonth(date.getMonth() + 1);
+ date = addMonths(new Date(), 1);
date.setDate(date.getDate() + 10);
inp.val('').datepicker('show');
inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}).