diff --git a/packages/localize/src/formatDate.js b/packages/localize/src/formatDate.js index ab5352b86..ddfbbbaa2 100644 --- a/packages/localize/src/formatDate.js +++ b/packages/localize/src/formatDate.js @@ -206,25 +206,25 @@ export function parseDate(date) { let parsedString; switch (memoizedGetDateFormatBasedOnLocale()) { case 'day-month-year': - parsedString = `${stringToParse.slice(6, 10)}-${stringToParse.slice( + parsedString = `${stringToParse.slice(6, 10)}/${stringToParse.slice( 3, 5, - )}-${stringToParse.slice(0, 2)}T00:00:00Z`; + )}/${stringToParse.slice(0, 2)}`; break; case 'month-day-year': - parsedString = `${stringToParse.slice(6, 10)}-${stringToParse.slice( + parsedString = `${stringToParse.slice(6, 10)}/${stringToParse.slice( 0, 2, - )}-${stringToParse.slice(3, 5)}T00:00:00Z`; + )}/${stringToParse.slice(3, 5)}`; break; case 'year-month-day': - parsedString = `${stringToParse.slice(0, 4)}-${stringToParse.slice( + parsedString = `${stringToParse.slice(0, 4)}/${stringToParse.slice( 5, 7, - )}-${stringToParse.slice(8, 10)}T00:00:00Z`; + )}/${stringToParse.slice(8, 10)}`; break; default: - parsedString = '0000-00-00T00:00:00Z'; + parsedString = '0000/00/00'; } const parsedDate = new Date(parsedString); // Check if parsedDate is not `Invalid Date` diff --git a/packages/localize/test/LocalizeManager.test.js b/packages/localize/test/LocalizeManager.test.js index fcf0f6f25..b2c57b0c9 100644 --- a/packages/localize/test/LocalizeManager.test.js +++ b/packages/localize/test/LocalizeManager.test.js @@ -368,7 +368,7 @@ describe('LocalizeManager', () => { date: 'I was written on {today, date}.', number: 'You have {n, plural, =0 {no photos.} =1 {one photo.} other {# photos.}}', }); - const today = new Date('2018-04-30'); + const today = new Date('2018/04/30'); expect(removeLtrRtl(manager.msg('my-ns:date', { today }))).to.equal( 'I was written on 30 Apr 2018.', ); diff --git a/packages/localize/test/formatDate.test.js b/packages/localize/test/formatDate.test.js index 544c190d6..3276488e2 100644 --- a/packages/localize/test/formatDate.test.js +++ b/packages/localize/test/formatDate.test.js @@ -11,7 +11,7 @@ beforeEach(() => { describe('formatDate', () => { it('displays the appropriate date based on locale', async () => { - const testDate = new Date('2012-05-21T00:00:00Z'); + const testDate = new Date('2012/05/21'); expect(formatDate(testDate)).to.equal('21/05/2012'); @@ -29,7 +29,7 @@ describe('formatDate', () => { }); it('displays the date based on options', async () => { - const testDate = new Date('2012-05-21T00:00:00Z'); + const testDate = new Date('2012/05/21'); const options = { weekday: 'long', year: 'numeric', @@ -120,8 +120,8 @@ describe('parseDate()', () => { Object.prototype.toString.call(value) === '[object Date]' && // is Date Object value.getDate() === date.getDate() && // day value.getMonth() === date.getMonth() && // month - value.getFullYear() === date.getFullYear() - ); // year + value.getFullYear() === date.getFullYear() // year + ); } afterEach(() => { @@ -129,22 +129,22 @@ describe('parseDate()', () => { document.documentElement.lang = 'en-GB'; }); it('adds leading zeros', () => { - expect(equalsDate(parseDate('1-1-1979'), new Date('1979-01-01'))).to.equal(true); - expect(equalsDate(parseDate('1-11-1979'), new Date('1979-11-01'))).to.equal(true); + expect(equalsDate(parseDate('1-1-1979'), new Date('1979/01/01'))).to.equal(true); + expect(equalsDate(parseDate('1-11-1979'), new Date('1979/11/01'))).to.equal(true); }); it('creates a date object', () => { expect(parseDate('10/10/2000') instanceof Date).to.equal(true); }); it('returns a date object', () => { - expect(equalsDate(parseDate('1-1-1979'), new Date('1979-01-01'))).to.equal(true); - expect(equalsDate(parseDate('31.12.1970'), new Date('1970-12-31'))).to.equal(true); + expect(equalsDate(parseDate('1-1-1979'), new Date('1979/01/01'))).to.equal(true); + expect(equalsDate(parseDate('31.12.1970'), new Date('1970/12/31'))).to.equal(true); }); it('handles all kind of delimiters', () => { - expect(equalsDate(parseDate('12.12.1976'), new Date('1976-12-12'))).to.equal(true); - expect(equalsDate(parseDate('13.12.1976'), new Date('1976-12-13'))).to.equal(true); - expect(equalsDate(parseDate('14.12.1976'), new Date('1976-12-14'))).to.equal(true); - expect(equalsDate(parseDate('14.12-1976'), new Date('1976-12-14'))).to.equal(true); - expect(equalsDate(parseDate('14-12/1976'), new Date('1976-12-14'))).to.equal(true); + expect(equalsDate(parseDate('12.12.1976'), new Date('1976/12/12'))).to.equal(true); + expect(equalsDate(parseDate('13.12.1976'), new Date('1976/12/13'))).to.equal(true); + expect(equalsDate(parseDate('14.12.1976'), new Date('1976/12/14'))).to.equal(true); + expect(equalsDate(parseDate('14.12-1976'), new Date('1976/12/14'))).to.equal(true); + expect(equalsDate(parseDate('14-12/1976'), new Date('1976/12/14'))).to.equal(true); }); it('return undefined when no valid date provided', () => { expect(parseDate('12.12.1976.,')).to.equal(undefined);