Skip to content

Commit 60bc336

Browse files
committed
support "11 months" and fix tests
1 parent fc858c3 commit 60bc336

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/duration.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,9 @@ export function roundToSingleUnit(duration: Duration, {relativeTo = Date.now()}:
179179
days = daysDiff
180180
}
181181
months = years = 0
182-
} else if (monthsDiff < 11) {
182+
} else if (monthsDiff <= 11) {
183183
months = monthsDiff
184184
years = 0
185-
} else if (monthsDiff === 11) {
186-
months = 0
187-
years += 1 // the old behavior: "11 months" is rounded to "1 year"
188185
} else {
189186
months = 0
190187
years = yearDiff * sign

test/duration.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ suite('duration', function () {
291291
},
292292
],
293293
['P9M20DT25H', 'P10M', {relativeTo: new Date('2023-01-12T00:00:00Z')}],
294-
['P11M', 'P1Y', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
295-
['-P11M', '-P1Y', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
294+
['P11M', 'P11M', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
295+
['-P11M', '-P11M', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
296296
['-P11M15D', '-P1Y', {relativeTo: new Date('2024-01-06T00:00:00')}],
297297
['P1Y4D', 'P1Y', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
298298
['P1Y5M13D', 'P1Y', {relativeTo: new Date('2023-01-01T00:00:00Z')}],
@@ -429,7 +429,7 @@ suite('duration', function () {
429429
relativeTo: new Date('2022-12-01T00:00:00Z'),
430430
},
431431
],
432-
['P11M', [1, 'year']],
432+
['P11M', [11, 'month']],
433433
['P1Y4D', [1, 'year']],
434434
[
435435
'P1Y5M13D',

test/relative-time.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,7 @@ suite('relative-time', function () {
25032503
datetime: '2024-01-16T00:00:00.000Z',
25042504
tense: 'past',
25052505
format: 'auto',
2506-
expected: 'last year', // a quick fix for the old bug: "23 days ago" because "11 months" was discarded, ideally it should support "11 months"
2506+
expected: '11 months ago',
25072507
},
25082508
])
25092509

0 commit comments

Comments
 (0)