Skip to content

Commit

Permalink
fix: update Breton [br] locale relativeTime config (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleduigou authored Oct 13, 2020
1 parent cc87eff commit b038bfd
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
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))
})
})

0 comments on commit b038bfd

Please sign in to comment.