1
0
mirror of https://github.com/comatory/fb2iCal synced 2025-06-05 22:09:25 +02:00

feature: convert form input to Svelte component and create module for

fetching event data & parsing it
This commit is contained in:
Ondřej Synáček
2020-12-20 13:50:12 +01:00
parent 128b03344b
commit b28995aa1e
10 changed files with 182 additions and 166 deletions

View File

@ -23,3 +23,26 @@ export const sortRecord = (a, b) => {
return 0
}
// NOTE: Generate random IDs: https://stackoverflow.com/a/2117523/3056783
export const uuidv4 = () => {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}
export const parseStartTimeFromiCalString = (text = '') => {
const [ dateStr, timeStr ] = text.split('T')
const rawDate = dateStr || ''
const rawTime = timeStr || ''
const year = Number(rawDate.slice(0, 4))
const month = Number(Math.max(rawDate.slice(4, 6) - 1), 0)
const date = Number(rawDate.slice(6, 8))
const hour = Number(rawTime.slice(0, 2))
const minutes = Number(rawTime.slice(2, 4))
const seconds = Number(rawTime.slice(4, 6))
const parsedDate = new Date(year, month, date, hour, minutes, seconds)
return parsedDate.toString()
}