-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
35 lines (31 loc) · 989 Bytes
/
utils.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
export function addDays(date, days) {
const newDate = moment(date).add(days, 'days')
return newDate
}
export function addHours(date, hours) {
const newDate = moment(date).add(hours, 'hours')
return newDate
}
export function calcStartDate(dateText, timezone = 'UTC') {
const startDate = moment(`${dateText} ${timezone}`)
return startDate
}
export function calcEndDate(dateText, duration = [8, 10], timezone = 'UTC') {
let startDate
if (typeof dateText === 'string') {
startDate = calcStartDate(dateText, timezone)
} else {
startDate = dateText
}
const adjustedDate = addDays(startDate, duration[0])
const adjustedTime = addHours(adjustedDate, duration[1])
return adjustedTime
}
export function calcNewEventDates(seedDate, newEvents) {
let prevDate = seedDate
for (const event in newEvents) {
newEvents[event].startDate = prevDate
newEvents[event].endDate = calcEndDate(newEvents[event].startDate)
prevDate = addDays(prevDate, 14)
}
}