-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatesConverters.ts
More file actions
38 lines (35 loc) · 1.17 KB
/
datesConverters.ts
File metadata and controls
38 lines (35 loc) · 1.17 KB
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
import type { CalendarEventDTO } from '../gen_types/CalendarEventDTO'
import type { EventInstance } from '../gen_types/EventInstance'
/**
* Change in place the dates inside an event to Date objects
* @param event - event to change in place
* @returns nothing
*/
export function replaceEventStringsToDates(event: CalendarEventDTO): void {
if (!event) {
return
}
event.startTime = new Date(event.startTime)
event.endTime = new Date(event.endTime)
event.created = new Date(event.created)
event.updated = new Date(event.updated)
event.originalStartTime = event.originalStartTime
? new Date(event.originalStartTime)
: event.originalStartTime
event.recurringUntil = event.recurringUntil
? new Date(event.recurringUntil)
: event.recurringUntil
event.exdates = event.exdates?.map(date => new Date(date))
}
/**
* Change in place the dates inside an instance to Date objects
* @param instance - instance to change in place
* @returns nothing
*/
export function replaceInstanceStringsToDates(instance: EventInstance): void {
if (!instance) {
return
}
instance.startTime = new Date(instance.startTime)
instance.endTime = new Date(instance.endTime)
}