Skip to content

Commit a08756e

Browse files
authoredMay 22, 2020
fix: Update Ukrainian (uk) locale monthFormat and monthStandalone (#899)
1 parent 9c0523e commit a08756e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
 

‎src/locale/uk.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Ukrainian [uk]
22
import dayjs from 'dayjs'
33

4+
const monthFormat = 'січня_лютого_березня_квітня_травня_червня_липня_серпня_вересня_жовтня_листопада_грудня'.split('_')
5+
const monthStandalone = 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_')
6+
7+
const MONTHS_IN_FORMAT = /D[oD]?(\[[^[\]]*\]|\s)+MMMM?/
8+
49
function plural(word, num) {
510
const forms = word.split('_')
611
return num % 10 === 1 && num % 100 !== 11 ? forms[0] : (num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) ? forms[1] : forms[2]) // eslint-disable-line
@@ -23,12 +28,21 @@ function relativeTimeWithPlural(number, withoutSuffix, key) {
2328
return `${number} ${plural(format[key], +number)}`
2429
}
2530

31+
const months = (dayjsInstance, format) => {
32+
if (MONTHS_IN_FORMAT.test(format)) {
33+
return monthFormat[dayjsInstance.month()]
34+
}
35+
return monthStandalone[dayjsInstance.month()]
36+
}
37+
months.s = monthStandalone
38+
months.f = monthFormat
39+
2640
const locale = {
2741
name: 'uk',
2842
weekdays: 'неділя_понеділок_вівторок_середа_четвер_п’ятниця_субота'.split('_'),
2943
weekdaysShort: 'ндл_пнд_втр_срд_чтв_птн_сбт'.split('_'),
3044
weekdaysMin: 'нд_пн_вт_ср_чт_пт_сб'.split('_'),
31-
months: 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_'),
45+
months,
3246
monthsShort: 'сiч_лют_бер_квiт_трав_черв_лип_серп_вер_жовт_лист_груд'.split('_'),
3347
weekStart: 1,
3448
relativeTime: {

‎test/locale/uk.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ afterEach(() => {
1414
MockDate.reset()
1515
})
1616

17+
it('Format Month with locale function', () => {
18+
for (let i = 0; i <= 7; i += 1) {
19+
const dayjsUK = dayjs().locale('uk').add(i, 'day')
20+
const momentUK = moment().locale('uk').add(i, 'day')
21+
const testFormat1 = 'DD MMMM YYYY MMM'
22+
const testFormat2 = 'MMMM'
23+
const testFormat3 = 'MMM'
24+
expect(dayjsUK.format(testFormat1)).toEqual(momentUK.format(testFormat1))
25+
expect(dayjsUK.format(testFormat2)).toEqual(momentUK.format(testFormat2))
26+
expect(dayjsUK.format(testFormat3)).toEqual(momentUK.format(testFormat3))
27+
}
28+
})
29+
1730
it('RelativeTime: Time from X', () => {
1831
const T = [
1932
[44.4, 'second'], // a few seconds

0 commit comments

Comments
 (0)
Please sign in to comment.