import MockDate from 'mockdate'
import dayjs from '../src'
beforeEach(() => {
MockDate.set(new Date())
})
afterEach(() => {
MockDate.reset()
})
test('is same without units', () => {
const m = dayjs(new Date(2011, 3, 2, 3, 4, 5, 10))
const mCopy = dayjs(m)
expect(m.isSame(dayjs(new Date(2012, 3, 2, 3, 5, 5, 10)))).toBe(false, 'year is later')
expect(m.isSame(dayjs(new Date(2010, 3, 2, 3, 3, 5, 10)))).toBe(false, 'year is earlier')
expect(m.isSame(dayjs(new Date(2011, 4, 2, 3, 4, 5, 10)))).toBe(false, 'month is later')
expect(m.isSame(dayjs(new Date(2011, 2, 2, 3, 4, 5, 10)))).toBe(false, 'month is earlier')
expect(m.isSame(dayjs(new Date(2011, 3, 3, 3, 4, 5, 10)))).toBe(false, 'day is later')
expect(m.isSame(dayjs(new Date(2011, 3, 1, 3, 4, 5, 10)))).toBe(false, 'day is earlier')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 4, 4, 5, 10)))).toBe(false, 'hour is later')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 2, 4, 5, 10)))).toBe(false, 'hour is earlier')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 3, 5, 5, 10)))).toBe(false, 'minute is later')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 3, 3, 5, 10)))).toBe(false, 'minute is earlier')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 3, 4, 6, 10)))).toBe(false, 'second is later')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 3, 4, 4, 11)))).toBe(false, 'second is earlier')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 3, 4, 5, 10)))).toBe(true, 'millisecond match')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 3, 4, 5, 11)))).toBe(false, 'millisecond is later')
expect(m.isSame(dayjs(new Date(2011, 3, 2, 3, 4, 5, 9)))).toBe(false, 'millisecond is earlier')
expect(m.isSame(m)).toBe(true, 'moments are the same as themselves')
expect(+m).toEqual(+mCopy, 'isSame second should not change moment')
})
test('is same year', () => {
const m = dayjs(new Date(2011, 1, 2, 3, 4, 5, 6))
const mCopy = dayjs(m)
expect(m.isSame(dayjs(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year')).toBe(true, 'year match')
expect(m.isSame(dayjs(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years')).toBe(true, 'plural should work')
expect(m.isSame(dayjs(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year')).toBe(false, 'year mismatch')
expect(m.isSame(dayjs(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year')).toBe(true, 'exact start of year')
expect(m.isSame(dayjs(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year')).toBe(true, 'exact end of year')
expect(m.isSame(dayjs(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year')).toBe(false, 'start of next year')
expect(m.isSame(dayjs(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year')).toBe(false, 'end of previous year')
expect(m.isSame(m, 'year')).toBe(true, 'same moments are in the same year')
expect(+m).toEqual(+mCopy, 'isSame year should not change moment')
})
test('is same month', () => {
const m = dayjs(new Date(2011, 2, 3, 4, 5, 6, 7))
const mCopy = dayjs(m)
expect(m.isSame(dayjs(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month')).toBe(true, 'month match')
expect(m.isSame(dayjs(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months')).toBe(true, 'plural should work')
expect(m.isSame(dayjs(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month')).toBe(false, 'year mismatch')
expect(m.isSame(dayjs(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month')).toBe(false, 'month mismatch')
expect(m.isSame(dayjs(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month')).toBe(true, 'exact start of month')
expect(m.isSame(dayjs(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month')).toBe(true, 'exact end of month')
expect(m.isSame(dayjs(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month')).toBe(false, 'start of next month')
expect(m.isSame(dayjs(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month')).toBe(false, 'end of previous month')
expect(m.isSame(m, 'month')).toBe(true, 'same moments are in the same month')
expect(+m).toEqual(+mCopy, 'isSame month should not change moment')
})
test('is same day', () => {
const m = dayjs(new Date(2011, 1, 2, 3, 4, 5, 6))
const mCopy = dayjs(m)
expect(m.isSame(dayjs(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day')).toBe(true, 'day match')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days')).toBe(true, 'plural should work')
expect(m.isSame(dayjs(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day')).toBe(false, 'year mismatch')
expect(m.isSame(dayjs(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day')).toBe(false, 'month mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day')).toBe(false, 'day mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day')).toBe(true, 'exact start of day')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day')).toBe(true, 'exact end of day')
expect(m.isSame(dayjs(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day')).toBe(false, 'start of next day')
expect(m.isSame(dayjs(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day')).toBe(false, 'end of previous day')
expect(m.isSame(m, 'day')).toBe(true, 'same moments are in the same day')
expect(+m).toEqual(+mCopy, 'isSame day should not change moment')
})
test('is same hour', () => {
const m = dayjs(new Date(2011, 1, 2, 3, 4, 5, 6))
const mCopy = dayjs(m)
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour')).toBe(true, 'hour match')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours')).toBe(true, 'plural should work')
expect(m.isSame(dayjs(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour')).toBe(false, 'year mismatch')
expect(m.isSame(dayjs(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour')).toBe(false, 'month mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour')).toBe(false, 'day mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour')).toBe(false, 'hour mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour')).toBe(true, 'exact start of hour')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour')).toBe(true, 'exact end of hour')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour')).toBe(false, 'start of next hour')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour')).toBe(false, 'end of previous hour')
expect(m.isSame(m, 'hour')).toBe(true, 'same moments are in the same hour')
expect(+m).toEqual(+mCopy, 'isSame hour should not change moment')
})
test('is same minute', () => {
const m = dayjs(new Date(2011, 1, 2, 3, 4, 5, 6))
const mCopy = dayjs(m)
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute')).toBe(true, 'minute match')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes')).toBe(true, 'plural should work')
expect(m.isSame(dayjs(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute')).toBe(false, 'year mismatch')
expect(m.isSame(dayjs(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute')).toBe(false, 'month mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute')).toBe(false, 'day mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute')).toBe(false, 'hour mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute')).toBe(false, 'minute mismatch')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute')).toBe(true, 'exact start of minute')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute')).toBe(true, 'exact end of minute')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute')).toBe(false, 'start of next minute')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute')).toBe(false, 'end of previous minute')
expect(m.isSame(m, 'minute')).toBe(true, 'same moments are in the same minute')
expect(+m).toEqual(+mCopy, 'isSame minute should not change moment')
})
test('is same second', () => {
const m = dayjs(new Date(2011, 1, 2, 3, 4, 5, 6))
const mCopy = dayjs(m)
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second')).toBe(true, 'second match')
expect(m.isSame(dayjs(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds')).toBe(true, 'plural should work')
expect(m.isSam
没有合适的资源?快使用搜索试试~ 我知道了~
Day.js 2kB的时间日期库 Moment.js 的 轻量化方案
共366个文件
js:280个
ts:39个
md:35个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 190 浏览量
2023-06-16
08:48:28
上传
评论
收藏 544KB ZIP 举报
温馨提示
快速 2kB 替代 Moment.js具有相同的现代 API。Day.js 是一个极简主义的 JavaScript 库,它使用与 Moment 兼容.js API 解析、验证、操作和显示现代浏览器的日期和时间。如果你使用Moment.js,你已经知道如何使用Day.js。 熟悉的时刻.js API 和模式。可链式。 I18n 支持。2kb 迷你图书馆。 支持所有浏览器
资源推荐
资源详情
资源评论
收起资源包目录
Day.js 2kB的时间日期库 Moment.js 的 轻量化方案 (366个子文件)
.editorconfig 78B
.gitignore 166B
comparison.test.js 40KB
isBetween.test.js 21KB
isSameOrBefore.test.js 15KB
customParseFormat.test.js 15KB
isSameOrAfter.test.js 15KB
utc.test.js 12KB
timezone.test.js 11KB
index.js 10KB
objectSupport.test.js 10KB
display.test.js 10KB
duration.test.js 9KB
parse.test.js 8KB
index.js 7KB
index.js 7KB
isoWeek.test.js 5KB
utc-utcOffset.test.js 5KB
relativeTime.test.js 5KB
badMutable.test.js 5KB
advancedFormat.test.js 5KB
index.js 5KB
pluralGetSet.test.js 5KB
localeData.test.js 5KB
get-set.test.js 4KB
index.js 4KB
locale.test.js 4KB
preParsePostFormat.test.js 4KB
localizedFormat.test.js 4KB
calendar.test.js 4KB
manipulate.test.js 3KB
keys.test.js 3KB
is.test.js 3KB
ru.js 3KB
sk.js 3KB
cs.js 3KB
de.test.js 3KB
uk.js 3KB
bn-bd.js 3KB
sr-cyrl.js 3KB
index.js 3KB
timezone.test.js 3KB
fi.js 3KB
issue2027.swapped-order.test.js 2KB
issue2027.correct-order.test.js 2KB
index.js 2KB
sr.js 2KB
sr-cyrl.test.js 2KB
index.js 2KB
bn-bd.test.js 2KB
bn.test.js 2KB
is.js 2KB
it-ch.test.js 2KB
updateLocale.test.js 2KB
bo.js 2KB
index.js 2KB
bn.js 2KB
lt.js 2KB
pl.js 2KB
he.js 2KB
karma.sauce.conf.js 2KB
et.js 2KB
ku.js 2KB
br.js 2KB
ta.js 2KB
bg.test.js 2KB
sr.test.js 2KB
pl.test.js 2KB
ru.test.js 2KB
ml.js 2KB
uk.test.js 2KB
ar.js 2KB
quarterOfYear.test.js 2KB
tzm.js 2KB
esm.js 2KB
de-at.js 2KB
de.js 2KB
zh-cn.js 2KB
de-ch.js 2KB
ne.js 2KB
zh.js 2KB
kn.js 2KB
hu.js 2KB
zh-tw.js 2KB
devHelper.test.js 2KB
gu.js 2KB
te.js 2KB
index.js 2KB
bg.js 2KB
pa-in.js 2KB
weekday.test.js 2KB
weekOfYear.test.js 2KB
th.js 2KB
br.test.js 2KB
ka.js 2KB
my.js 2KB
dv.js 2KB
index.js 1KB
hi.js 1KB
ar.test.js 1KB
共 366 条
- 1
- 2
- 3
- 4
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6656
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功