ttsv2ics - ics2txt - convert icalendar .ics file to plain text | |
git clone git://bitreich.org/ics2txt git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
ttsv2ics (1785B) | |
--- | |
1 #!/usr/bin/awk -f | |
2 | |
3 function isleap(year) | |
4 { | |
5 return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0) | |
6 } | |
7 | |
8 function mdays(mon, year) | |
9 { | |
10 return (mon == 2) ? (28 + isleap(year)) : (30 + (mon + (mon > 7)… | |
11 } | |
12 | |
13 # Split the time in seconds since epoch into a table, with fields | |
14 # named as with gmtime(3): tm["year"], tm["mon"], tm["mday"], | |
15 # tm["hour"], tm["min"], tm["sec"] | |
16 function gmtime(sec, tm, | |
17 s) | |
18 { | |
19 tm["year"] = 1970 | |
20 while (sec >= (s = 86400 * (365 + isleap(tm["year"])))) { | |
21 tm["year"]++ | |
22 sec -= s | |
23 } | |
24 | |
25 tm["mon"] = 1 | |
26 while (sec >= (s = 86400 * mdays(tm["mon"], tm["year"]))) { | |
27 tm["mon"]++ | |
28 sec -= s | |
29 } | |
30 | |
31 tm["mday"] = 1 | |
32 while (sec >= (s = 86400)) { | |
33 tm["mday"]++ | |
34 sec -= s | |
35 } | |
36 | |
37 tm["hour"] = 0 | |
38 while (sec >= 3600) { | |
39 tm["hour"]++ | |
40 sec -= 3600 | |
41 } | |
42 | |
43 tm["min"] = 0 | |
44 while (sec >= 60) { | |
45 tm["min"]++ | |
46 sec -= 60 | |
47 } | |
48 | |
49 tm["sec"] = sec | |
50 } | |
51 | |
52 function print_fold(prefix, s, n) | |
53 { | |
54 while (s != "") { | |
55 line = substr(s, 1, n) | |
56 if (length(s) > n) sub(" +[^ \t\r\n]*$", "", line) | |
57 print prefix line | |
58 s = substr(s, length(line) + 2) | |
59 } | |
60 } | |
61 | |
62 BEGIN { | |
63 FS = "\t" | |
64 | |
65 print "BEGIN:VCALENDAR" | |
66 print "VERSION:2.0" | |
67 print "CALSCALE:GREGORIAN" | |
68 print "METHOD:PUBLISH" | |
69 } | |
70 | |
71 NR == 1 { | |
72 for (i = 1; i <= NF; i++) | |
73 name[i] = $i | |
74 next | |
75 } | |
76 | |
77 { | |
78 for (i = 1; i <= NF; i++) | |
79 ev[name[i]] = $i | |
80 | |
81 print "" | |
82 print "BEGIN:VEVENT" | |
83 | |
84 gmtime(ev["beg"] + offset, ev) | |
85 printf "DTSTART:%04d%02d%02dT%02d%02d00Z\n", | |
86 ev["year"], ev["mon"], ev["mday"], ev["hour"], ev["min"] | |
87 | |
88 gmtime(ev["end"] + offset, ev) | |
89 printf "DTEND:%04d%02d%02dT%02d%02d00Z\n", | |
90 ev["year"], ev["mon"], ev["mday"], ev["hour"], ev["min"] | |
91 | |
92 print "SUMMARY:" ev["sum"] | |
93 print "DESCRIPTION:" ev["des"] | |
94 print "CATEGORIES:" ev["cat"] | |
95 print "LOCATION:" ev["loc"] | |
96 print "END:VEVENT" | |
97 | |
98 delete ev | |
99 } | |
100 | |
101 END { | |
102 print "" | |
103 print "END:VCALENDAR" | |
104 } |