Skip to content

Commit

Permalink
fix: update Hebrew [he] locale for double units (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvizvi authored Dec 27, 2020
1 parent 1605cc0 commit 1c4b0da
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/locale/he.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
// Hebrew [he]
import dayjs from 'dayjs'

const texts = {
s: 'מספר שניות',
ss: '%d שניות',
m: 'דקה',
mm: '%d דקות',
h: 'שעה',
hh: '%d שעות',
hh2: 'שעתיים',
d: 'יום',
dd: '%d ימים',
dd2: 'יומיים',
M: 'חודש',
MM: '%d חודשים',
MM2: 'חודשיים',
y: 'שנה',
yy: '%d שנים',
yy2: 'שנתיים'
}

function relativeTimeFormatter(number, withoutSuffix, key) {
const text = texts[key + (number === 2 ? '2' : '')] || texts[key]
return text.replace('%d', number)
}

const locale = {
name: 'he',
weekdays: 'ראשון_שני_שלישי_רביעי_חמישי_שישי_שבת'.split('_'),
Expand All @@ -11,17 +35,17 @@ const locale = {
relativeTime: {
future: 'בעוד %s',
past: 'לפני %s',
s: 'כמה שניות',
m: 'דקה',
mm: '%d דקות',
h: 'שעה',
hh: '%d שעות',
d: 'יום',
dd: '%d ימים',
M: 'חודש',
MM: '%d חודשים',
y: 'שנה',
yy: '%d שנים'
s: relativeTimeFormatter,
m: relativeTimeFormatter,
mm: relativeTimeFormatter,
h: relativeTimeFormatter,
hh: relativeTimeFormatter,
d: relativeTimeFormatter,
dd: relativeTimeFormatter,
M: relativeTimeFormatter,
MM: relativeTimeFormatter,
y: relativeTimeFormatter,
yy: relativeTimeFormatter
},
ordinal: n => n,
format: {
Expand Down
45 changes: 45 additions & 0 deletions test/locale/he.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import moment from 'moment'
import dayjs from '../../src'
import relativeTime from '../../src/plugin/relativeTime'
import '../../src/locale/he'

dayjs.extend(relativeTime)

it('RelativeTime: Time from X', () => {
const T = [
[44.4, 'second'], // a few seconds
[89.5, 'second'], // a minute
[2, 'minute'], // 2 minutes
[43, 'minute'], // 43 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('he')
moment.locale('he')

const dayjsDay = dayjs()
const momentDay = moment()

const dayjsCompare = dayjs().add(t[0], t[1])
const momentCompare = moment().add(t[0], t[1])

expect(dayjsDay.from(dayjsCompare)).toBe(momentDay.from(momentCompare))

expect(dayjsDay.to(dayjsCompare)).toBe(momentDay.to(momentCompare))

expect(dayjsDay.from(dayjsCompare, true)).toBe(momentDay.from(momentCompare, true))
})
})

0 comments on commit 1c4b0da

Please sign in to comment.