diff --git a/src/index.js b/src/index.js index 434f60362..7e3af1c59 100644 --- a/src/index.js +++ b/src/index.js @@ -374,7 +374,7 @@ class Dayjs { } toJSON() { - return this.toISOString() + return this.isValid() ? this.toISOString() : null } toISOString() { diff --git a/src/locale/pt-br.js b/src/locale/pt-br.js index 5133a72f7..286a54585 100644 --- a/src/locale/pt-br.js +++ b/src/locale/pt-br.js @@ -3,7 +3,7 @@ import dayjs from 'dayjs' const locale = { name: 'pt-br', weekdays: 'Domingo_Segunda-feira_Terça-feira_Quarta-feira_Quinta-feira_Sexta-feira_Sábado'.split('_'), - weekdaysMin : 'Do_2ª_3ª_4ª_5ª_6ª_Sá'.split('_'), + weekdaysMin: 'Do_2ª_3ª_4ª_5ª_6ª_Sá'.split('_'), weekStart: 1, months: 'Janeiro_Fevereiro_Março_Abril_Maio_Junho_Julho_Agosto_Setembro_Outubro_Novembro_Dezembro'.split('_'), ordinal: n => `${n}º`, diff --git a/test/display.test.js b/test/display.test.js index c8fe19350..6c546d923 100644 --- a/test/display.test.js +++ b/test/display.test.js @@ -248,6 +248,8 @@ it('As Javascript Date -> toDate', () => { it('As JSON -> toJSON', () => { expect(dayjs().toJSON()).toBe(moment().toJSON()) + expect(dayjs('otherString').toJSON()).toBe(moment('otherString').toJSON()) + expect(dayjs('otherString').toJSON()).toBe(null) }) it('As ISO 8601 String -> toISOString e.g. 2013-02-04T22:44:30.652Z', () => {