dot

packages and services management
Log | Files | Refs | README

commit 7310024635461498d0dfca12841f81f322de5489
parent 8200cb121fffe64f8eb1ae4dbdc5c6d801eda12d
Author: josuah <mail@josuah.net>
Date:   Sun, 25 Dec 2016 21:19:33 +0000

Added conversion functions to icaldir

Diffstat:
M.local/bin/icaldir | 51++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/.local/bin/icaldir b/.local/bin/icaldir @@ -1,9 +1,39 @@ -#!/usr/bin/awk -f +awk '# Store an ical file one event per file in a directory, like for maildir -function print_date(date) +function is_bissextile(year) { - printf("%s-%s-%s %s:%s:%s", + return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); +} + + +function days_in_month(month, year) +{ + if (month == 2) { + return 28 + is_bissextile(year); + } else if (month < 8) { + return 30 + (month % 2 == 1); + } else { + return 30 + (month % 2 == 0); + } +} + + +function to_seconds(year, month, day, hour, minute, second) +{ + for (month--; month > 0; month--) + day += days_in_month(month, year); + + for (year--; year >= 1970; year--) + day += 365 + is_bissextile(year); + + return (second + 60 * (minute + 60 * (hour + (24 * (day - 1))))); +} + + +function ical_to_seconds(date) +{ + return to_seconds( \ substr(date, 1, 4), # Year substr(date, 5, 2), # Month substr(date, 7, 2), # Day @@ -14,6 +44,7 @@ function print_date(date) BEGIN { + path = HOME "" FS = ":"; } @@ -36,16 +67,14 @@ BEGIN { /END:VEVENT/ { - print_date(vevent["DTSTART"]); - print_date(vevent["DTEND"]); - printf "\n"; + printf("%s\n", ical_to_seconds(vevent["DTSTART"])); + printf("%s\n", ical_to_seconds(vevent["DTEND"])); gsub(/\\/, "", vevent["LOCATION"]); - printf("Summary: %s\n", vevent["SUMMARY"]); + printf("%s\t", vevent["SUMMARY"]); gsub(/\\/, "", vevent["LOCATION"]); - printf("Location: %s\n", vevent["LOCATION"]); + printf("%s\t", vevent["LOCATION"]); - gsub(/\\n/, "\n", vevent["DESCRIPTION"]); - printf("\n%s\n", vevent["DESCRIPTION"]); -} + print(vevent["DESCRIPTION"]); +}' "$1"