From 83792f7509ea37f686e8cb574f4b1063de7880c0 Mon Sep 17 00:00:00 2001 From: koding88 Date: Mon, 24 Aug 2026 23:04:24 +0700 Subject: [PATCH] fix(locale): Maldivian weekStart out of range weekStart must be within 0..6; the value 7 only behaved like a Sunday start by accident of the week gap arithmetic. Per CLDR, the week in the Maldives starts on Sunday. Fixes #1535 --- src/locale/dv.js | 2 +- test/locale/dv.test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/locale/dv.test.js diff --git a/src/locale/dv.js b/src/locale/dv.js index 897d7af04..70bdc287e 100644 --- a/src/locale/dv.js +++ b/src/locale/dv.js @@ -5,7 +5,7 @@ const locale = { name: 'dv', weekdays: 'އާދިއްތަ_ހޯމަ_އަންގާރަ_ބުދަ_ބުރާސްފަތި_ހުކުރު_ހޮނިހިރު'.split('_'), months: 'ޖެނުއަރީ_ފެބްރުއަރީ_މާރިޗު_އޭޕްރީލު_މޭ_ޖޫން_ޖުލައި_އޯގަސްޓު_ސެޕްޓެމްބަރު_އޮކްޓޯބަރު_ނޮވެމްބަރު_ޑިސެމްބަރު'.split('_'), - weekStart: 7, + weekStart: 0, weekdaysShort: 'އާދިއްތަ_ހޯމަ_އަންގާރަ_ބުދަ_ބުރާސްފަތި_ހުކުރު_ހޮނިހިރު'.split('_'), monthsShort: 'ޖެނުއަރީ_ފެބްރުއަރީ_މާރިޗު_އޭޕްރީލު_މޭ_ޖޫން_ޖުލައި_އޯގަސްޓު_ސެޕްޓެމްބަރު_އޮކްޓޯބަރު_ނޮވެމްބަރު_ޑިސެމްބަރު'.split('_'), weekdaysMin: 'އާދި_ހޯމަ_އަން_ބުދަ_ބުރާ_ހުކު_ހޮނި'.split('_'), diff --git a/test/locale/dv.test.js b/test/locale/dv.test.js new file mode 100644 index 000000000..46ff3830a --- /dev/null +++ b/test/locale/dv.test.js @@ -0,0 +1,29 @@ +import MockDate from 'mockdate' +import dayjs from '../../src' +import '../../src/locale/dv' + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +it('Maldivian week starts on Sunday (weekStart must be within 0..6)', () => { + const { weekStart } = dayjs().locale('dv').$locale() + expect(weekStart).toBe(0) + + // every day of the week belongs to a week that starts on Sunday + for (let i = 0; i < 7; i += 1) { + const day = dayjs('2024-06-16').add(i, 'day') // 2024-06-16 is a Sunday + expect(day.locale('dv').startOf('week').day()).toBe(0) + expect(day.locale('dv').endOf('week').day()).toBe(6) + } +}) + +it('Sunday itself is the first day of its week in dv locale', () => { + const sunday = dayjs('2024-06-16').locale('dv') + expect(sunday.startOf('week').format('YYYY-MM-DD')).toBe('2024-06-16') + expect(sunday.endOf('week').format('YYYY-MM-DD')).toBe('2024-06-22') +})