Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bf7225

Browse files
Add test for duration with both months and minutes (P1M2DT3M30S)
Co-authored-by: francinelucca <[email protected]>
1 parent cc554ce commit 7bf7225

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/duration-format-ponyfill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default class DurationFormat {
114114
let formattedValue = new Intl.NumberFormat(locale, nfOpts).format(value)
115115

116116
// Custom handling for narrow month formatting to use "mo" instead of "m"
117-
if (unit === 'months' && unitStyle === 'narrow') {
117+
if (unit === 'months' && (unitStyle === 'narrow' || (style === 'narrow' && formattedValue.endsWith('m')))) {
118118
formattedValue = formattedValue.replace(/(\d+)m$/, '$1mo')
119119
}
120120

test/duration-format-ponyfill.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ suite('duration format ponyfill', function () {
9292
{type: 'element', value: '8s'},
9393
],
9494
},
95+
{
96+
duration: 'P1M2DT3M30S',
97+
locale: 'en',
98+
style: 'narrow',
99+
parts: [
100+
{type: 'element', value: '1mo'},
101+
{type: 'literal', value: ' '},
102+
{type: 'element', value: '2d'},
103+
{type: 'literal', value: ' '},
104+
{type: 'element', value: '3m'},
105+
{type: 'literal', value: ' '},
106+
{type: 'element', value: '30s'},
107+
],
108+
},
95109
])
96110

97111
for (const {duration, locale, parts, ...opts} of tests) {

0 commit comments

Comments
 (0)