diff --git a/src/locale/et.js b/src/locale/et.js index 82422bbf4..8a9ad1e70 100644 --- a/src/locale/et.js +++ b/src/locale/et.js @@ -1,6 +1,25 @@ // Estonian [et] import dayjs from 'dayjs' +function relativeTimeWithTense(number, withoutSuffix, key, isFuture) { + const format = { + s: ['mõne sekundi', 'mõni sekund', 'paar sekundit'], + m: ['ühe minuti', 'üks minut'], + mm: ['%d minuti', '%d minutit'], + h: ['ühe tunni', 'tund aega', 'üks tund'], + hh: ['%d tunni', '%d tundi'], + d: ['ühe päeva', 'üks päev'], + M: ['kuu aja', 'kuu aega', 'üks kuu'], + MM: ['%d kuu', '%d kuud'], + y: ['ühe aasta', 'aasta', 'üks aasta'], + yy: ['%d aasta', '%d aastat'] + } + if (withoutSuffix) { + return (format[key][2] ? format[key][2] : format[key][1]).replace('%d', number) + } + return (isFuture ? format[key][0] : format[key][1]).replace('%d', number) +} + const locale = { name: 'et', // Estonian weekdays: 'pühapäev_esmaspäev_teisipäev_kolmapäev_neljapäev_reede_laupäev'.split('_'), // Note weekdays are not capitalized in Estonian @@ -10,28 +29,20 @@ const locale = { monthsShort: 'jaan_veebr_märts_apr_mai_juuni_juuli_aug_sept_okt_nov_dets'.split('_'), ordinal: n => `${n}.`, weekStart: 1, - /* - * This relativeTime is currently configured for having proper past - * tense forms since Estonian needs a separate version for future tense - * and I think past tense is a more common use case for this kind of library. - * - * Doing this properly requires this issue to be fixed: - * https://github.com/iamkun/dayjs/issues/302 - */ relativeTime: { future: '%s pärast', past: '%s tagasi', - s: 'mõni sekund', // for past tense - m: 'minut', // for past tense - mm: '%d minutit', // for past tense - h: 'tund', // for past tense - hh: '%d tundi', // for past tense - d: 'päev', // for past tense - dd: '%d päeva', // for past tense - M: 'kuu', // for past tense - MM: '%d kuud', // for past tense - y: 'aasta', // for past tense - yy: '%d aastat' // for past tense + s: relativeTimeWithTense, + m: relativeTimeWithTense, + mm: relativeTimeWithTense, + h: relativeTimeWithTense, + hh: relativeTimeWithTense, + d: relativeTimeWithTense, + dd: '%d päeva', + M: relativeTimeWithTense, + MM: relativeTimeWithTense, + y: relativeTimeWithTense, + yy: relativeTimeWithTense }, formats: { LT: 'H:mm', diff --git a/test/locale/et.test.js b/test/locale/et.test.js new file mode 100644 index 000000000..5b8b75833 --- /dev/null +++ b/test/locale/et.test.js @@ -0,0 +1,38 @@ +import moment from 'moment' +import MockDate from 'mockdate' +import dayjs from '../../src' +import relativeTime from '../../src/plugin/relativeTime' +import '../../src/locale/et' + +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 + [43, 'minute'], // 44 minutes + [21, 'hour'], // 21 hours + [25, 'day'], // 25 days + [10, 'month'], // 2 month + [18, 'month'] // 2 years + ] + + T.forEach((t) => { + dayjs.locale('et') + moment.locale('et') + expect(dayjs().from(dayjs().add(t[0], t[1]))) + .toBe(moment().from(moment().add(t[0], t[1]))) + expect(dayjs().from(dayjs().subtract(t[0], t[1]))) + .toBe(moment().from(moment().subtract(t[0], t[1]))) + expect(dayjs().from(dayjs().add(t[0], t[1]), true)) + .toBe(moment().from(moment().add(t[0], t[1]), true)) + }) +})