Skip to content

Commit

Permalink
fix: Update pl locale fusional config
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Jan 19, 2020
1 parent 9ac6ab4 commit d372475
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/locale/pl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import dayjs from 'dayjs'

function plural(n) {
return (n % 10 < 5) && (n % 10 > 1) && ((~~(n / 10) % 10) !== 1) // eslint-disable-line
}
/* eslint-disable */
function translate(number, withoutSuffix, key) {
const result = `${number} `
switch (key) {
case 'm':
return withoutSuffix ? 'minuta' : 'minutę'
case 'mm':
return result + (plural(number) ? 'minuty' : 'minut')
case 'h':
return withoutSuffix ? 'godzina' : 'godzinę'
case 'hh':
return result + (plural(number) ? 'godziny' : 'godzin')
case 'MM':
return result + (plural(number) ? 'miesiące' : 'miesięcy')
case 'yy':
return result + (plural(number) ? 'lata' : 'lat')
}
}
/* eslint-enable */
const locale = {
name: 'pl',
weekdays: 'Niedziela_Poniedziałek_Wtorek_Środa_Czwartek_Piątek_Sobota'.split('_'),
Expand All @@ -11,18 +33,18 @@ const locale = {
weekStart: 1,
relativeTime: {
future: 'za %s',
past: 'po %s',
past: '%s temu',
s: 'kilka sekund',
m: 'minuta',
mm: '%d minut',
h: 'godzina',
hh: '%d godzin',
d: 'dzień',
m: translate,
mm: translate,
h: translate,
hh: translate,
d: '1 dzień',
dd: '%d dni',
M: 'miesiąc',
MM: '%d miesięcy',
MM: translate,
y: 'rok',
yy: '%d lat'
yy: translate
},
formats: {
LT: 'HH:mm',
Expand Down
47 changes: 47 additions & 0 deletions test/locale/pl.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../../src'
import relativeTime from '../../src/plugin/relativeTime'
import '../../src/locale/pl'

dayjs.extend(relativeTime)

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

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

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

T.forEach((t) => {
dayjs.locale('pl')
moment.locale('pl')
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 d372475

Please sign in to comment.