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

Datepicker w/ Moment parseDate parsing strings results in good date object not Invalid Date #1907

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grunt/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function test (grunt) {
['connect:testServer', 'jshint', 'saucelabs-qunit:defaultBrowsers']);

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

// 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.
grunt.registerTask('resetdist', 'resets changes to dist to keep them from being checked in', function resetdist () {
Expand Down
6 changes: 3 additions & 3 deletions js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@
return (true === md.isValid()) ? md.toDate() : BAD_DATE;
};

tryMomentParseAll = function (d, parseFunc1, parseFunc2) {
var pd = parseFunc1(d);
tryMomentParseAll = function (rawDateString, parseFunc1, parseFunc2) {
var pd = parseFunc1(rawDateString);
if (!self.isInvalidDate(pd)) {
return pd;
}

pd = parseFunc2(pd);
pd = parseFunc2(rawDateString);
if (!self.isInvalidDate(pd)) {
return pd;
}
Expand Down
14 changes: 13 additions & 1 deletion test/datepicker-moment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ define( function ( require ) {
assert.equal( date1, date2, "getValue alias matches getDate" );
} );

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

QUnit.test( "should set new date using setDate method passing a ISO string", function( assert ) {
var $datepicker = $( html ).datepicker();
var dateString = '2015-05-29T04:00:00.000Z';
var newDate = new Date(dateString);
var datepickerDate;

$datepicker.datepicker( "setDate", dateString);
datepickerDate = $datepicker.datepicker( "getDate" );

assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" );
} );

QUnit.test( "should enable/disable datepicker", function( assert ) {
var $datepicker = $( html ).datepicker();
var $datepickerInput = $datepicker.find( "input" );
Expand Down
14 changes: 13 additions & 1 deletion test/datepicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ define(function( require ) {
assert.equal( date1, date2, "getValue alias matches getDate" );
} );

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

QUnit.test( "should set new date using setDate method passing a ISO string", function( assert ) {
var $datepicker = $( html ).datepicker();
var dateString = '2015-05-29T04:00:00.000Z';
var newDate = new Date(dateString);
var datepickerDate;

$datepicker.datepicker( "setDate", dateString);
datepickerDate = $datepicker.datepicker( "getDate" );

assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" );
} );

QUnit.test( "should enable/disable datepicker", function( assert ) {
var $datepicker = $( html ).datepicker();
var $datepickerInput = $datepicker.find( "input" );
Expand Down