Skip to content

Commit

Permalink
fix: proper month naming for short format & ru locale (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
tverskih authored and pimenovoleg committed Jul 9, 2019
1 parent 2e4fff4 commit 1c269c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export interface IFormatterConfig {

monthNames: {
long: string[];
short: string[];
short: {
standalone: string[];
formatted: string[];
};
narrow: string[];
};

Expand Down
5 changes: 4 additions & 1 deletion packages/mosaic-moment-adapter/adapter/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const enUS: IFormatterConfig = {
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
'October', 'November', 'December'
],
short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
short: {
standalone: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
formatted: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D']
},

Expand Down
5 changes: 4 additions & 1 deletion packages/mosaic-moment-adapter/adapter/locales/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const ruRU: IFormatterConfig = {
'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь',
'Октябрь', 'Ноябрь', 'Декабрь'
],
short: ['янв', 'фев', 'март', 'апр', 'май', 'июнь', 'июль', 'авг', 'сен', 'окт', 'ноя', 'дек'],
short: {
standalone: ['янв', 'фев', 'март', 'апр', 'май', 'июнь', 'июль', 'авг', 'сен', 'окт', 'ноя', 'дек'],
formatted: ['янв', 'фев', 'мар', 'апр', 'мая', 'июня', 'июля', 'авг', 'сен', 'окт', 'ноя', 'дек']
},
narrow: ['Я', 'Ф', 'М', 'А', 'М', 'И', 'И', 'А', 'С', 'О', 'Н', 'Д']
},

Expand Down
12 changes: 12 additions & 0 deletions packages/mosaic-moment-adapter/adapter/moment-date-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ describe('MomentDateAdapter', () => {
]);
});

it('should get formatted month (genitive) name for short absolute date', () => {
adapter.setLocale('ru');
const NBSP = '\u00A0';
expect(
Array.from(Array(12).keys())
.map((monthIndex) => moment().month(monthIndex))
.map((date) => adapter.absoluteShortDate(date))
// '9 декабря' => ['9', 'декабря'] => 'декабря'
.map((formattedDate) => formattedDate.split(NBSP)[1])
).toEqual(['янв', 'фев', 'мар', 'апр', 'мая', 'июня', 'июля', 'авг', 'сен', 'окт', 'ноя', 'дек']);
});

it('should get long month names en', () => {
adapter.setLocale('en');

Expand Down
4 changes: 2 additions & 2 deletions packages/mosaic-moment-adapter/adapter/moment-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export class MomentDateAdapter extends DateAdapter<Moment> {

momentLocaleData = moment.updateLocale(locale, {
monthsShort: {
format: this.formatterConfig.monthNames.short,
standalone: this.formatterConfig.monthNames.short
format: this.formatterConfig.monthNames.short.formatted,
standalone: this.formatterConfig.monthNames.short.standalone
},
weekdaysShort: this.formatterConfig.dayOfWeekNames.short,
weekdays: this.formatterConfig.dayOfWeekNames.long
Expand Down

0 comments on commit 1c269c9

Please sign in to comment.