Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit e16f714

Browse files
authored
Merge pull request #1907 from swilliamset/datepicker-fix-for-parseDate-parsing-strings
Datepicker w/ Moment parseDate parsing strings results in good date object not `Invalid Date`
2 parents 7cb7900 + 36e097f commit e16f714

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

grunt/tasks/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function test (grunt) {
1818
['connect:testServer', 'jshint', 'saucelabs-qunit:defaultBrowsers']);
1919

2020
grunt.registerTask('travisci', 'Tests to run when in Travis CI environment',
21-
['browserify:commonjs', 'test', 'dist', 'qunit:dist']);
21+
['browserify:commonjs', 'dist', 'test', 'qunit:dist']);
2222

2323
// if you've already accidentally added your files for commit, this will at least unstage them. If you haven't, this will wipe them out.
2424
grunt.registerTask('resetdist', 'resets changes to dist to keep them from being checked in', function resetdist () {

js/datepicker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,13 @@
395395
return (true === md.isValid()) ? md.toDate() : BAD_DATE;
396396
};
397397

398-
tryMomentParseAll = function (d, parseFunc1, parseFunc2) {
399-
var pd = parseFunc1(d);
398+
tryMomentParseAll = function (rawDateString, parseFunc1, parseFunc2) {
399+
var pd = parseFunc1(rawDateString);
400400
if (!self.isInvalidDate(pd)) {
401401
return pd;
402402
}
403403

404-
pd = parseFunc2(pd);
404+
pd = parseFunc2(rawDateString);
405405
if (!self.isInvalidDate(pd)) {
406406
return pd;
407407
}

test/datepicker-moment-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ define( function ( require ) {
129129
assert.equal( date1, date2, "getValue alias matches getDate" );
130130
} );
131131

132-
QUnit.test( "should set new date using setDate method", function( assert ) {
132+
QUnit.test( "should set new date using setDate method passing a Date object", function( assert ) {
133133
var $datepicker = $( html ).datepicker();
134134
var newDate = new Date( 1987, 2, 31 );
135135
var datepickerDate;
@@ -140,6 +140,18 @@ define( function ( require ) {
140140
assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" );
141141
} );
142142

143+
QUnit.test( "should set new date using setDate method passing a ISO string", function( assert ) {
144+
var $datepicker = $( html ).datepicker();
145+
var dateString = '2015-05-29T04:00:00.000Z';
146+
var newDate = new Date(dateString);
147+
var datepickerDate;
148+
149+
$datepicker.datepicker( "setDate", dateString);
150+
datepickerDate = $datepicker.datepicker( "getDate" );
151+
152+
assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" );
153+
} );
154+
143155
QUnit.test( "should enable/disable datepicker", function( assert ) {
144156
var $datepicker = $( html ).datepicker();
145157
var $datepickerInput = $datepicker.find( "input" );

test/datepicker-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ define(function( require ) {
7575
assert.equal( date1, date2, "getValue alias matches getDate" );
7676
} );
7777

78-
QUnit.test( "should set new date using setDate method", function( assert ) {
78+
QUnit.test( "should set new date using setDate method passing a Date object", function( assert ) {
7979
var $datepicker = $( html ).datepicker();
8080
var newDate = new Date( 1987, 2, 31 );
8181
var datepickerDate;
@@ -86,6 +86,18 @@ define(function( require ) {
8686
assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" );
8787
} );
8888

89+
QUnit.test( "should set new date using setDate method passing a ISO string", function( assert ) {
90+
var $datepicker = $( html ).datepicker();
91+
var dateString = '2015-05-29T04:00:00.000Z';
92+
var newDate = new Date(dateString);
93+
var datepickerDate;
94+
95+
$datepicker.datepicker( "setDate", dateString);
96+
datepickerDate = $datepicker.datepicker( "getDate" );
97+
98+
assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" );
99+
} );
100+
89101
QUnit.test( "should enable/disable datepicker", function( assert ) {
90102
var $datepicker = $( html ).datepicker();
91103
var $datepickerInput = $datepicker.find( "input" );

0 commit comments

Comments
 (0)