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