This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
62 lines (48 loc) · 1.5 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { formatISO, getTime } from 'date-fns'
import { zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz'
export function convertTime12to24(time12h) {
const [time, modifier] = time12h.split(' ')
// eslint-disable-next-line
let [hours, minutes] = time.split(':')
if (hours === '12') {
hours = '00'
}
if (modifier === 'PM') {
hours = parseInt(hours, 10) + 12
}
return `${hours}:${minutes}`
}
export function getTimestamp(day, time) {
const [hour, min] = time.split(':')
const date = new Date(
2021,
9,
day,
parseInt(hour) + 2,
parseInt(min)
).getTime()
const utcTime = utcToZonedTime(date, 'Europe/Lisbon')
return getTime(utcTime)
}
export function generateGoogleCalendarUrl(event) {
const { title, startTime, endTime, room, fullSpeaker } = event
const startTimeTimestamp = getTimestamp(
parseInt(event.day),
convertTime12to24(startTime)
)
const endTimeTimestamp = getTimestamp(
parseInt(event.day),
convertTime12to24(endTime)
)
const utcTimeStart = formatISO(
zonedTimeToUtc(startTimeTimestamp, 'Europe/Lisbon'),
{ format: 'basic' }
)
const utcTimeEnd = formatISO(
zonedTimeToUtc(endTimeTimestamp, 'Europe/Lisbon'),
{ format: 'basic' }
)
const location =
'LxFactory, R. Rodrigues de Faria 103, 1300-501 Lisboa, Portugal'
return `https://www.google.com/calendar/render?action=TEMPLATE&text=${title}&location=${location}&dates=${utcTimeStart}%2F${utcTimeEnd}&details=Speaker: ${fullSpeaker}%0AStage: ${room}`
}