We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc858c3 commit 60bc336Copy full SHA for 60bc336
src/duration.ts
@@ -179,12 +179,9 @@ export function roundToSingleUnit(duration: Duration, {relativeTo = Date.now()}:
179
days = daysDiff
180
}
181
months = years = 0
182
- } else if (monthsDiff < 11) {
+ } else if (monthsDiff <= 11) {
183
months = monthsDiff
184
years = 0
185
- } else if (monthsDiff === 11) {
186
- months = 0
187
- years += 1 // the old behavior: "11 months" is rounded to "1 year"
188
} else {
189
months = 0
190
years = yearDiff * sign
test/duration.ts
@@ -291,8 +291,8 @@ suite('duration', function () {
291
},
292
],
293
['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')}],
+ ['P11M', 'P11M', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
+ ['-P11M', '-P11M', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
296
['-P11M15D', '-P1Y', {relativeTo: new Date('2024-01-06T00:00:00')}],
297
['P1Y4D', 'P1Y', {relativeTo: new Date('2022-11-01T00:00:00Z')}],
298
['P1Y5M13D', 'P1Y', {relativeTo: new Date('2023-01-01T00:00:00Z')}],
@@ -429,7 +429,7 @@ suite('duration', function () {
429
relativeTo: new Date('2022-12-01T00:00:00Z'),
430
431
432
- ['P11M', [1, 'year']],
+ ['P11M', [11, 'month']],
433
['P1Y4D', [1, 'year']],
434
[
435
'P1Y5M13D',
test/relative-time.js
@@ -2503,7 +2503,7 @@ suite('relative-time', function () {
2503
datetime: '2024-01-16T00:00:00.000Z',
2504
tense: 'past',
2505
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"
+ expected: '11 months ago',
2507
2508
])
2509
0 commit comments