Home
       ttical-txt-tsv - ics2txt - convert icalendar .ics file to plain text
  HTML git clone git://bitreich.org/ics2txt git://hg6vgqziawt5s4dj.onion/ics2txt
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
       ---
       ttical-txt-tsv (1335B)
       ---
            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)) % 2)
           11 }
           12 
           13 function timegm(year, mon, mday, hour, min, sec)
           14 {
           15         while (--mon >= 1)
           16                 mday += mdays(mon, year)
           17         while (--year >= 1970)
           18                 mday += 365 + isleap(year)
           19         return (((((mday - 1) * 24) + hour) * 60) + min) * 60 + sec
           20 }
           21 
           22 function date_text(str, offset,
           23         year, mon, mday, hour, min)
           24 {
           25         year = substr(str,  1, 4)
           26         mon  = substr(str,  6, 2)
           27         mday = substr(str,  9, 2)
           28         hour = substr(str, 12, 2)
           29         min  = substr(str, 15, 2)
           30         return timegm(year, mon, mday, hour, min, 0) - offset
           31 }
           32 
           33 {
           34         gsub(/\t/, " ")
           35 }
           36 
           37 /^TZ[+-]/ {
           38         hour = substr($0, 4, 2)
           39         min = substr($0, 6, 2)
           40         tzoffset = substr(zone, 3, 1) hour * 3600 + min * 60
           41         next
           42 }
           43 
           44 /^[0-9]+-[0-9]+-[0-9]+ / {
           45         time = date_text($1 " " $2, tzoffset)
           46         row++
           47 }
           48 
           49 /^ / {
           50         d = $0
           51         sub(/^ */, "", d)
           52         des = des " " d
           53 }
           54 
           55 /^$/ {
           56         if (beg)
           57                 printf "%d\t%d\t%s\t%s\t%s\t%s\n", beg, end, cat, loc, sum, des
           58         beg = end = cat = loc = sum = des = "" 
           59 }
           60 
           61 row == 1 {
           62         beg = time
           63         sum = $0
           64         sub(/^[^ ]+ +[^ ]+ +/, "", sum)
           65 }
           66 
           67 row == 2 {
           68         end = time
           69 
           70         line = $0
           71         sub(/^[^ ]+ +[^ ]+ +/, "", line)
           72 
           73         cat = line
           74         sub(/\].*/, "", cat)
           75         sub(/^\[/, "", cat)
           76 
           77         loc = line
           78         sub(/[^]]*\] */, "", loc)
           79 
           80         row = 0
           81 }