diff --git a/src/index.js b/src/index.js index f50b59e78..8c919b0d8 100644 --- a/src/index.js +++ b/src/index.js @@ -251,11 +251,12 @@ class Dayjs { } format(formatStr) { - if (!this.isValid()) return C.INVALID_DATE_STRING + const locale = this.$locale() + + if (!this.isValid()) return locale.invalidDate || C.INVALID_DATE_STRING const str = formatStr || C.FORMAT_DEFAULT const zoneStr = Utils.z(this) - const locale = this.$locale() const { $H, $m, $M } = this const { weekdays, months, meridiem diff --git a/test/plugin/updateLocale.test.js b/test/plugin/updateLocale.test.js index ecbcbd41c..1fdfe93cb 100644 --- a/test/plugin/updateLocale.test.js +++ b/test/plugin/updateLocale.test.js @@ -68,4 +68,15 @@ describe('Update locale', () => { expect(dayjs().format(formatString)) .toEqual(moment().format(formatString)) }) + + it('Update invalid date string', () => { + const locale = 'en' + const localeSetting = { invalidDate: 'bad date' } + dayjs.updateLocale(locale, localeSetting) + moment.updateLocale(locale, localeSetting) + dayjs.locale(locale) + moment.locale(locale) + expect(dayjs('').format()).toBe(moment('').format()) + expect(dayjs('otherString').format()).toBe(moment('otherString').format()) + }) })