Skip to content

Commit

Permalink
fix: Implement ordinal in Bulgarian translation (fixes #1501) (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
boyanio authored Jun 1, 2021
1 parent 0b0c6a3 commit b728da5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/locale/bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,23 @@ const locale = {
months: 'януари_февруари_март_април_май_юни_юли_август_септември_октомври_ноември_декември'.split('_'),
monthsShort: 'янр_фев_мар_апр_май_юни_юли_авг_сеп_окт_ное_дек'.split('_'),
weekStart: 1,
ordinal: n => `${n}.`,
ordinal: (n) => {
const last2Digits = n % 100
if (last2Digits > 10 && last2Digits < 20) {
return `${n}-ти`
}

const lastDigit = n % 10
if (lastDigit === 1) {
return `${n}-ви`
} else if (lastDigit === 2) {
return `${n}-ри`
} else if (lastDigit === 7 || lastDigit === 8) {
return `${n}-ми`
}

return `${n}-ти`
},
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
Expand All @@ -27,7 +43,7 @@ const locale = {
h: 'час',
hh: '%d часа',
d: 'ден',
dd: '%d дни',
dd: '%d дена',
M: 'месец',
MM: '%d месеца',
y: 'година',
Expand Down
67 changes: 67 additions & 0 deletions test/locale/bg.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../../src'
import relativeTime from '../../src/plugin/relativeTime'
import advancedFormat from '../../src/plugin/advancedFormat'
import '../../src/locale/bg'

dayjs.extend(relativeTime)
dayjs.extend(advancedFormat)

beforeEach(() => {
MockDate.set(new Date())
})

afterEach(() => {
MockDate.reset()
})

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

it('RelativeTime: Time from X', () => {
const T = [
[44.4, 'second'], // a few seconds
[89.5, 'second'], // a minute
[130, 'second'], // two minutes
[43, 'minute'], // 44 minutes
[1, 'hour'], // 1 hour
[21, 'hour'], // 21 hours
[2, 'day'], // 2 days
[25, 'day'], // 25 days
[2, 'month'], // 2 months
[10, 'month'], // 10 months
[18, 'month'], // 2 years
[15, 'year'] // 15 years
]

T.forEach((t) => {
dayjs.locale('bg')
moment.locale('bg')
expect(dayjs().from(dayjs().add(t[0], t[1])))
.toBe(moment().from(moment().add(t[0], t[1])))
expect(dayjs().from(dayjs().add(t[0], t[1]), true))
.toBe(moment().from(moment().add(t[0], t[1]), true))
})
})

it('Ordinal', () => {
dayjs.locale('bg')
moment.locale('bg')

for (let d = 1; d <= 31; d += 1) {
const day = d < 10 ? `0${d}` : d
const date = `2021-01-${day}`
expect(dayjs(date).format('Do')).toBe(moment(date).format('Do'))
}
})

0 comments on commit b728da5

Please sign in to comment.