Skip to content

Commit

Permalink
fix: Update Ukrainian (uk) locale monthFormat and monthStandalone (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerika committed May 22, 2020
1 parent 9c0523e commit a08756e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/locale/uk.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Ukrainian [uk]
import dayjs from 'dayjs'

const monthFormat = 'січня_лютого_березня_квітня_травня_червня_липня_серпня_вересня_жовтня_листопада_грудня'.split('_')
const monthStandalone = 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_')

const MONTHS_IN_FORMAT = /D[oD]?(\[[^[\]]*\]|\s)+MMMM?/

function plural(word, num) {
const forms = word.split('_')
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
Expand All @@ -23,12 +28,21 @@ function relativeTimeWithPlural(number, withoutSuffix, key) {
return `${number} ${plural(format[key], +number)}`
}

const months = (dayjsInstance, format) => {
if (MONTHS_IN_FORMAT.test(format)) {
return monthFormat[dayjsInstance.month()]
}
return monthStandalone[dayjsInstance.month()]
}
months.s = monthStandalone
months.f = monthFormat

const locale = {
name: 'uk',
weekdays: 'неділя_понеділок_вівторок_середа_четвер_п’ятниця_субота'.split('_'),
weekdaysShort: 'ндл_пнд_втр_срд_чтв_птн_сбт'.split('_'),
weekdaysMin: 'нд_пн_вт_ср_чт_пт_сб'.split('_'),
months: 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_'),
months,
monthsShort: 'сiч_лют_бер_квiт_трав_черв_лип_серп_вер_жовт_лист_груд'.split('_'),
weekStart: 1,
relativeTime: {
Expand Down
13 changes: 13 additions & 0 deletions test/locale/uk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ afterEach(() => {
MockDate.reset()
})

it('Format Month with locale function', () => {
for (let i = 0; i <= 7; i += 1) {
const dayjsUK = dayjs().locale('uk').add(i, 'day')
const momentUK = moment().locale('uk').add(i, 'day')
const testFormat1 = 'DD MMMM YYYY MMM'
const testFormat2 = 'MMMM'
const testFormat3 = 'MMM'
expect(dayjsUK.format(testFormat1)).toEqual(momentUK.format(testFormat1))
expect(dayjsUK.format(testFormat2)).toEqual(momentUK.format(testFormat2))
expect(dayjsUK.format(testFormat3)).toEqual(momentUK.format(testFormat3))
}
})

it('RelativeTime: Time from X', () => {
const T = [
[44.4, 'second'], // a few seconds
Expand Down

0 comments on commit a08756e

Please sign in to comment.