Skip to content

Commit b8718c9

Browse files
refactor: include literals at the end of the format
1 parent a7c5e08 commit b8718c9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/dates/split-date-format.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,9 @@ export default function splitDateFormat(format, locale = 'en') {
8080
match = dateFormatRegExp.exec(pattern);
8181
}
8282

83+
if (lastIndex < pattern.length) {
84+
addLiteral(parts, pattern.substring(lastIndex));
85+
}
86+
8387
return parts;
8488
}

test/dates.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,25 @@ describe('splitDateFormat', () => {
11921192
}]);
11931193
});
11941194

1195+
it('result contains literals parts at the start and end of the format', () => {
1196+
1197+
expect(splitDateFormat('Foo "M" y')).toEqual([{
1198+
type: 'literal',
1199+
pattern: 'Foo "M" '
1200+
}, {
1201+
type: 'year',
1202+
pattern: 'y'
1203+
}]);
1204+
1205+
expect(splitDateFormat('M "M" Foo ')).toEqual([{
1206+
type: 'month',
1207+
pattern: 'M'
1208+
}, {
1209+
type: 'literal',
1210+
pattern: ' "M" Foo '
1211+
}]);
1212+
});
1213+
11951214
it('parts contain names information if the pattern uses localized names', () => {
11961215
const expected = [{
11971216
type: "month",

0 commit comments

Comments
 (0)