-
Notifications
You must be signed in to change notification settings - Fork 2
/
csv-to-ics.awk
45 lines (41 loc) · 894 Bytes
/
csv-to-ics.awk
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
function to_timestamp(iso_dt) {
if (length(iso_dt) ~ /19|20/) {
Y = substr(iso_dt, 1, 4)
M = substr(iso_dt, 6, 2)
D = substr(iso_dt, 9, 2)
h = substr(iso_dt, 12, 2)
m = substr(iso_dt, 15, 2)
s = substr(iso_dt, 18, 2)
Z = substr(iso_dt, 20, 1)
return Y M D "T" h m s Z
} else if (length(iso_dt) == 10) {
Y = substr(iso_dt, 1, 4)
M = substr(iso_dt, 6, 2)
D = substr(iso_dt, 9, 2)
return Y M D
}
}
BEGIN {
print "BEGIN:VCALENDAR"
}
NR == 1 {
split($0, fields, FS)
}
NR != 1 {
print "BEGIN:VEVENT"
for (i = 1; i <= NF; i++) {
key = toupper(fields[i])
value = $i
if (value == "" || key ~ /DURATION/) {
continue
}
if (key ~ /DTSTART|DTEND|DTSTAMP|CREATED|LAST-MOD/ && value ~ /-|:/) {
value = to_timestamp(value)
}
print key ":" value
}
print "END:VEVENT"
}
END {
print "END:VCALENDAR"
}