Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for breton language and implementation of mutations #1103

Merged
merged 10 commits into from
Oct 13, 2020
56 changes: 56 additions & 0 deletions src/locale/br.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
// Breton [br]
import dayjs from 'dayjs'

function lastNumber(number) {
if (number > 9) {
return lastNumber(number % 10)
}
return number
}
function softMutation(text) {
const mutationTable = {
m: 'v',
b: 'v',
d: 'z'
}
return mutationTable[text.charAt(0)] + text.substring(1)
}
function mutation(text, number) {
if (number === 2) {
return softMutation(text)
}
return text
}
function relativeTimeWithMutation(number, withoutSuffix, key) {
const format = {
mm: 'munutenn',
MM: 'miz',
dd: 'devezh'
}
return `${number} ${mutation(format[key], number)}`
}
function specialMutationForYears(number) {
switch (lastNumber(number)) {
case 1:
case 3:
case 4:
case 5:
case 9:
return `${number} bloaz`
default:
return `${number} vloaz`
}
}

const locale = {
name: 'br',
weekdays: 'Sul_Lun_Meurzh_Mercʼher_Yaou_Gwener_Sadorn'.split('_'),
Expand All @@ -18,6 +59,21 @@ const locale = {
LLL: 'D [a viz] MMMM YYYY h[e]mm A',
LLLL: 'dddd, D [a viz] MMMM YYYY h[e]mm A'
},
relativeTime: {
future: 'a-benn %s',
past: '%s ʼzo',
s: 'un nebeud segondennoù',
m: 'ur vunutenn',
mm: relativeTimeWithMutation,
h: 'un eur',
hh: '%d eur',
d: 'un devezh',
dd: relativeTimeWithMutation,
M: 'ur miz',
MM: relativeTimeWithMutation,
y: 'ur bloaz',
yy: specialMutationForYears
},
meridiem: hour => (hour < 12 ? 'a.m.' : 'g.m.') // a-raok merenn | goude merenn
}

Expand Down
54 changes: 54 additions & 0 deletions test/locale/br.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../../src'
import relativeTime from '../../src/plugin/relativeTime'
import '../../src/locale/br'

dayjs.extend(relativeTime)

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

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

it('Format Month with locale function', () => {
for (let i = 0; i <= 7; i += 1) {
const dayjsBR = dayjs().locale('br').add(i, 'day')
const momentBR = moment().locale('br').add(i, 'day')
const testFormat1 = 'DD MMMM YYYY MMM'
const testFormat2 = 'MMMM'
const testFormat3 = 'MMM'
expect(dayjsBR.format(testFormat1)).toEqual(momentBR.format(testFormat1))
expect(dayjsBR.format(testFormat2)).toEqual(momentBR.format(testFormat2))
expect(dayjsBR.format(testFormat3)).toEqual(momentBR.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('br')
moment.locale('br')
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))
})
})