Introduction
Introduction Statistics Contact Development Disclaimer Help
ttsv2tcal - ics2txt - convert icalendar .ics file to plain text
git clone git://bitreich.org/ics2txt git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws…
Log
Files
Refs
Tags
README
---
ttsv2tcal (1493B)
---
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 function gmtime(sec, tm)
14 {
15 tm["year"] = 1970
16 while (sec >= (s = 86400 * (365 + isleap(tm["year"])))) {
17 tm["year"]++
18 sec -= s
19 }
20 tm["mon"] = 1
21 while (sec >= (s = 86400 * mdays(tm["mon"], tm["year"]))) {
22 tm["mon"]++
23 sec -= s
24 }
25 tm["mday"] = 1
26 while (sec >= (s = 86400)) {
27 tm["mday"]++
28 sec -= s
29 }
30 tm["hour"] = 0
31 while (sec >= 3600) {
32 tm["hour"]++
33 sec -= 3600
34 }
35 tm["min"] = 0
36 while (sec >= 60) {
37 tm["min"]++
38 sec -= 60
39 }
40 tm["sec"] = sec
41 }
42
43 function localtime(sec, tm,
44 tz, h, m)
45 {
46 return gmtime(sec + TZ, tm)
47 }
48
49 BEGIN {
50 "exec date +%z" | getline tz
51 close("exec date +%z")
52 TZ = substr(tz, 1, 1) substr(tz, 2, 2)*3600 + substr(tz, 4, 2)*60
53
54 print("TZ" tz)
55
56 FS = "\t"
57 }
58
59 NR == 1 {
60 for (i = 1; i <= NF; i++)
61 name[i] = $i
62 next
63 }
64
65 {
66 for (i = 1; i <= NF; i++)
67 ev[name[i]] = $i
68
69 print("")
70
71 localtime(ev["beg"] + offset, tm)
72 printf("%04d-%02d-%02d %02d:%02d\n",
73 tm["year"], tm["mon"], tm["mday"], tm["hour"], tm["min"])
74 delete ev["beg"]
75
76 localtime(ev["end"] + offset, tm)
77 printf("%04d-%02d-%02d %02d:%02d\n",
78 tm["year"], tm["mon"], tm["mday"], tm["hour"], tm["min"])
79 delete ev["end"]
80
81 for (i = 1; i <= NF; i++) {
82 if (name[i] in ev && ev[name[i]])
83 printf(" %s: %s\n", name[i], ev[name[i]])
84 }
85
86 delete ev
87 }
88
89 END {
90 print("")
91 }
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.