diff --git a/src/locale/hu.js b/src/locale/hu.js index 116086da6..92df6992f 100644 --- a/src/locale/hu.js +++ b/src/locale/hu.js @@ -13,17 +13,17 @@ const locale = { relativeTime: { future: '%s múlva', past: '%s', - s: 'néhány másodperc', - m: 'egy perc', - mm: '%d perc', - h: 'egy óra', - hh: '%d óra', - d: 'egy nap', - dd: '%d nap', - M: 'egy hónap', - MM: '%d hónap', - y: 'egy éve', - yy: '%d év' + s: (_, s, ___, isFuture) => `néhány másodperc${isFuture || s ? '' : 'e'}`, + m: (_, s, ___, isFuture) => `egy perc${isFuture || s ? '' : 'e'}`, + mm: (n, s, ___, isFuture) => `${n} perc${isFuture || s ? '' : 'e'}`, + h: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'óra' : 'órája'}`, + hh: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'óra' : 'órája'}`, + d: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'nap' : 'napja'}`, + dd: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'nap' : 'napja'}`, + M: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'hónap' : 'hónapja'}`, + MM: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'hónap' : 'hónapja'}`, + y: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'év' : 'éve'}`, + yy: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'év' : 'éve'}` }, formats: { LT: 'H:mm', @@ -38,4 +38,3 @@ const locale = { dayjs.locale(locale, null, true) export default locale - diff --git a/test/locale/hu.test.js b/test/locale/hu.test.js new file mode 100644 index 000000000..0a9cee20d --- /dev/null +++ b/test/locale/hu.test.js @@ -0,0 +1,45 @@ +import moment from 'moment' +import dayjs from '../../src' +import relativeTime from '../../src/plugin/relativeTime' +import '../../src/locale/hu' + +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('hu') + moment.locale('hu') + + 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)) + }) +})