From 04cb40bf33aae98fd8390ca5367747dd72dc6a17 Mon Sep 17 00:00:00 2001 From: Ethan Soergel Date: Wed, 15 Mar 2023 15:43:02 -0400 Subject: [PATCH] Allow formats that don't zero-pad months and days --- .../static/cloudcare/js/form_entry/spec/entries_spec.js | 4 +++- corehq/apps/cloudcare/static/cloudcare/js/utils.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/entries_spec.js b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/entries_spec.js index 3c32e056311b..a794fa1611bc 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/entries_spec.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/form_entry/spec/entries_spec.js @@ -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"); }); @@ -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 () { diff --git a/corehq/apps/cloudcare/static/cloudcare/js/utils.js b/corehq/apps/cloudcare/static/cloudcare/js/utils.js index f2385c703f2f..cebeb6a45d6c 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/utils.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/utils.js @@ -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) {