|
| 1 | +import moment from 'moment' |
| 2 | +import MockDate from 'mockdate' |
| 3 | +import dayjs from '../../src' |
| 4 | +import relativeTime from '../../src/plugin/relativeTime' |
| 5 | +import '../../src/locale/br' |
| 6 | + |
| 7 | +dayjs.extend(relativeTime) |
| 8 | + |
| 9 | +beforeEach(() => { |
| 10 | + MockDate.set(new Date()) |
| 11 | +}) |
| 12 | + |
| 13 | +afterEach(() => { |
| 14 | + MockDate.reset() |
| 15 | +}) |
| 16 | + |
| 17 | +it('Format Month with locale function', () => { |
| 18 | + for (let i = 0; i <= 7; i += 1) { |
| 19 | + const dayjsBR = dayjs().locale('br').add(i, 'day') |
| 20 | + const momentBR = moment().locale('br').add(i, 'day') |
| 21 | + const testFormat1 = 'DD MMMM YYYY MMM' |
| 22 | + const testFormat2 = 'MMMM' |
| 23 | + const testFormat3 = 'MMM' |
| 24 | + expect(dayjsBR.format(testFormat1)).toEqual(momentBR.format(testFormat1)) |
| 25 | + expect(dayjsBR.format(testFormat2)).toEqual(momentBR.format(testFormat2)) |
| 26 | + expect(dayjsBR.format(testFormat3)).toEqual(momentBR.format(testFormat3)) |
| 27 | + } |
| 28 | +}) |
| 29 | + |
| 30 | +it('RelativeTime: Time from X', () => { |
| 31 | + const T = [ |
| 32 | + [44.4, 'second'], // a few seconds |
| 33 | + [89.5, 'second'], // a minute |
| 34 | + [130, 'second'], // two minutes |
| 35 | + [43, 'minute'], // 44 minutes |
| 36 | + [1, 'hour'], // 1 hour |
| 37 | + [21, 'hour'], // 21 hours |
| 38 | + [2, 'day'], // 2 days |
| 39 | + [25, 'day'], // 25 days |
| 40 | + [2, 'month'], // 2 months |
| 41 | + [10, 'month'], // 10 months |
| 42 | + [18, 'month'], // 2 years |
| 43 | + [15, 'year'] // 15 years |
| 44 | + ] |
| 45 | + |
| 46 | + T.forEach((t) => { |
| 47 | + dayjs.locale('br') |
| 48 | + moment.locale('br') |
| 49 | + expect(dayjs().from(dayjs().add(t[0], t[1]))) |
| 50 | + .toBe(moment().from(moment().add(t[0], t[1]))) |
| 51 | + expect(dayjs().from(dayjs().add(t[0], t[1]), true)) |
| 52 | + .toBe(moment().from(moment().add(t[0], t[1]), true)) |
| 53 | + }) |
| 54 | +}) |
0 commit comments