/
githubmirror
/
dayjs
Обзор
Документация
Войти
/
githubmirror
/
dayjs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
test/locale/ru.test.js
56 строк
2 KB
CJ Skillingstad
fix: update Russian [ru] locale meridiem and unit tests (#1403)
09 мар 2021, 07:27
Не верифицирован
09 мар 2021, 07:27
f10f39d
Код
Авторство
О чём код?
import moment from 'moment' import MockDate from 'mockdate' import dayjs from '../../src' import relativeTime from '../../src/plugin/relativeTime' import '../../src/locale/ru' 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 dayjsRU = dayjs().locale('ru').add(i, 'day') const momentRU = moment().locale('ru').add(i, 'day') const testFormat1 = 'DD MMMM YYYY MMM' const testFormat2 = 'MMMM' const testFormat3 = 'MMM' expect(dayjsRU.format(testFormat1)).toEqual(momentRU.format(testFormat1)) expect(dayjsRU.format(testFormat2)).toEqual(momentRU.format(testFormat2)) expect(dayjsRU.format(testFormat3)).toEqual(momentRU.format(testFormat3)) } }) 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('ru') moment.locale('ru') 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)) }) }) it('Meridiem', () => { expect(dayjs('2020-01-01 03:00:00').locale('ru').format('A')).toEqual('ночи') expect(dayjs('2020-01-01 11:00:00').locale('ru').format('A')).toEqual('утра') expect(dayjs('2020-01-01 16:00:00').locale('ru').format('A')).toEqual('дня') expect(dayjs('2020-01-01 20:00:00').locale('ru').format('A')).toEqual('вечера') })