Skip to content

Commit 03ccdc8

Browse files
Change month microformat from 'm' to 'mo' in narrow style
Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>
1 parent 62f1392 commit 03ccdc8

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ This will used to determine the length of the unit names. This value is passed t
273273
| relative | narrow | in 1 mo. |
274274
| duration | long | 1 month, 2 days, 4 hours |
275275
| duration | short | 1 mth, 2 days, 4 hr |
276-
| duration | narrow | 1m 2d 4h |
276+
| duration | narrow | 1mo 2d 4h |
277277

278278
##### second, minute, hour, weekday, day, month, year, timeZoneName
279279

src/duration-format-ponyfill.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,15 @@ export default class DurationFormat {
110110
: unitStyle === 'numeric'
111111
? {}
112112
: {style: 'unit', unit: nfUnit, unitDisplay: unitStyle}
113-
list.push(new Intl.NumberFormat(locale, nfOpts).format(value))
113+
114+
let formattedValue = new Intl.NumberFormat(locale, nfOpts).format(value)
115+
116+
// Custom handling for narrow month formatting to use "mo" instead of "m"
117+
if (unit === 'months' && unitStyle === 'narrow') {
118+
formattedValue = formattedValue.replace(/(\d+)m$/, '$1mo')
119+
}
120+
121+
list.push(formattedValue)
114122
}
115123
return new ListFormat(locale, {
116124
type: 'unit',

test/duration-format-ponyfill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ suite('duration format ponyfill', function () {
3737
locale: 'en',
3838
style: 'narrow',
3939
parts: [
40-
{type: 'element', value: '1m'},
40+
{type: 'element', value: '1mo'},
4141
{type: 'literal', value: ' '},
4242
{type: 'element', value: '2d'},
4343
{type: 'literal', value: ' '},

test/relative-time.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ suite('relative-time', function () {
19411941
datetime: '2022-09-24T14:46:00.000Z',
19421942
tense: 'future',
19431943
format: 'micro',
1944-
expected: '1m',
1944+
expected: '1mo',
19451945
},
19461946
{
19471947
datetime: '2022-10-23T14:46:00.000Z',
@@ -1991,7 +1991,7 @@ suite('relative-time', function () {
19911991
datetime: '2022-11-24T14:46:00.000Z',
19921992
tense: 'future',
19931993
format: 'micro',
1994-
expected: '1m',
1994+
expected: '1mo',
19951995
},
19961996
{
19971997
datetime: '2023-10-23T14:46:00.000Z',
@@ -2023,7 +2023,7 @@ suite('relative-time', function () {
20232023
datetime: '2022-11-24T14:46:00.000Z',
20242024
tense: 'past',
20252025
format: 'micro',
2026-
expected: '1m',
2026+
expected: '1mo',
20272027
},
20282028
{
20292029
datetime: '2022-10-25T14:46:00.000Z',
@@ -2073,7 +2073,7 @@ suite('relative-time', function () {
20732073
datetime: '2022-09-23T14:46:00.000Z',
20742074
tense: 'past',
20752075
format: 'micro',
2076-
expected: '1m',
2076+
expected: '1mo',
20772077
},
20782078
{
20792079
datetime: '2021-10-25T14:46:00.000Z',
@@ -2178,13 +2178,13 @@ suite('relative-time', function () {
21782178
{
21792179
datetime: '2021-10-30T14:46:00.000Z',
21802180
format: 'elapsed',
2181-
expected: '11m 29d',
2181+
expected: '11mo 29d',
21822182
},
21832183
{
21842184
datetime: '2021-10-30T14:46:00.000Z',
21852185
format: 'elapsed',
21862186
precision: 'month',
2187-
expected: '11m',
2187+
expected: '11mo',
21882188
},
21892189
{
21902190
datetime: '2021-10-29T14:46:00.000Z',

0 commit comments

Comments
 (0)