-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (29 loc) · 974 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export default (option, dayjsClass, dayjs) => {
dayjs.between = (from, to) => {
const fromMilli = dayjs(from).valueOf()
const max = dayjs(to).valueOf() - fromMilli
const dateOffset = Math.floor(Math.random() * max + 1)
const newDate = dayjs(fromMilli + dateOffset)
return dayjs(newDate)
}
dayjs.soon = (days = 1, refDate = dayjs()) => {
const ref = dayjs(refDate)
const to = ref.add(days, 'day')
return dayjs.between(ref, to)
}
dayjs.recent = (days = 1, refDate = dayjs()) => {
const ref = dayjs(refDate)
const from = ref.subtract(days, 'day')
return dayjs.between(from, ref)
}
dayjs.future = (years = 1, refDate = dayjs()) => {
const ref = dayjs(refDate)
const to = ref.add(years, 'year')
return dayjs.between(ref, to)
}
dayjs.past = (years = 1, refDate = dayjs()) => {
const ref = dayjs(refDate)
const from = ref.subtract(years, 'year')
return dayjs.between(from, ref)
}
}