Skip to content

Commit

Permalink
Allow formats that don't zero-pad months and days
Browse files Browse the repository at this point in the history
  • Loading branch information
esoergel committed Mar 15, 2023
1 parent 7d6fa82 commit 04cb40b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ describe('Entries', function () {
};

assertParsesAs("03/04/20", "2020-03-04");
assertParsesAs("3/4/20", "2020-03-04");
assertParsesAs("2020-03-04", "2020-03-04");
});

Expand All @@ -359,7 +360,8 @@ describe('Entries', function () {
};

assertInvalid("23/01/2022");
assertInvalid("3/4/20"); // TODO
assertInvalid("23/1/22");
assertInvalid("23-1-22");
});

it('Should return TimeEntry', function () {
Expand Down
5 changes: 4 additions & 1 deletion corehq/apps/cloudcare/static/cloudcare/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ hqDefine('cloudcare/js/utils', [
};

var dateFormat = 'MM/DD/YYYY';
var dateFormats = ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY', 'MM/DD/YY', 'MM-DD-YY', moment.defaultFormat];
var dateFormats = ['MM/DD/YYYY', 'YYYY-MM-DD', // strict formats first
'M/D/YYYY', 'M/D/YY',
'M-D-YYYY', 'M-D-YY',
moment.defaultFormat];

/** Coerce an input date string to a moment object */
var parseInputDate = function (dateString) {
Expand Down

0 comments on commit 04cb40b

Please sign in to comment.