#!/usr/bin/perl -w
use strict;
-use Data::ICal;
use Getopt::Long;
use Date::Manip;
+use iCal::Parser;
+use Text::Wrap;
my $start = undef;
my $end = undef;
print "Processing date range: " . UnixDate($start, '%Y-%m-%d') . " - " . UnixDate($end, '%Y-%m-%d') . "\n";
-my $calendar = Data::ICal->new(filename => $filename);
+my $parser = iCal::Parser->new(
+ 'start' => UnixDate($start, '%Y%m%d'),
+ 'end' => UnixDate($end, '%Y%m%d'),
+ 'no_todos' => 1,
+);
+
+my $cal = $parser->parse($filename);
+my $events = $cal->{'events'};
+
+my %clients;
use Data::Dumper;
-for my $entry (@{ $calendar->entries() }) {
- if ($entry->ical_entry_type eq 'VEVENT') {
- my $summary = return_property($entry, 'Summary');
- my $description = return_property($entry, 'Description');
- my $dtstart = return_property($entry, 'dtstart');
- print "event: $summary - $dtstart - $description\n";
+for my $year (keys %{ $events }) {
+ for my $month (sort keys %{ $events->{$year} }) {
+ for my $day (sort keys %{ $events->{$year}{$month} }) {
+ for my $uid (keys %{ $events->{$year}{$month}{$day} }) {
+ my $summary = $events->{$year}{$month}{$day}{$uid}{'SUMMARY'} || '';
+ my $desc = $events->{$year}{$month}{$day}{$uid}{'DESCRIPTION'} || 'misc';
+ my $hours = $events->{$year}{$month}{$day}{$uid}{'hours'} || 0;
+ my $dtstart = $events->{$year}{$month}{$day}{$uid}{'DTSTART'} || '';
+
+ $hours = 8
+ if defined $events->{$year}{$month}{$day}{$uid}{'allday'};
+
+ $clients{lc($summary)}{'work'}{$desc}{'hours'} += $hours;
+ $clients{lc($summary)}{'client'} ||= $summary;
+ push @{ $clients{lc($summary)}{'work'}{$desc}{'times'} }, [ $hours, $dtstart ];
+ #print "event: $summary - $dtstart - $desc\n";
#print Dumper($entry);
- } else {
- print "not event\n";
+ }
}
+ }
}
-sub return_property {
- my $entry = shift;
- my $property = shift;
+for my $client (sort keys %clients) {
+ print "$clients{$client}{'client'}:\n";
+ for my $desc (sort keys %{ $clients{$client}{'work'} }) {
+ print wrap(' ', ' ', $desc) . "\n";
- my $properties = $entry->property($property);
-
- return ""
- unless defined $properties;
+ for my $time (sort @{ $clients{$client}{'work'}{$desc}{'times'} }) {
+ print detail_line($time->[0], $time->[1]);
+ }
- if (scalar(@{ $properties }) > 0) {
- return @{ $properties }[0]->value();
- } else {
- return "";
+ if (scalar(@{ $clients{$client}{'work'}{$desc}{'times'} }) > 1) {
+ print detail_line($clients{$client}{'work'}{$desc}{'hours'}, 'Total');
+ }
}
+ print "\n";
+}
+
+sub detail_line {
+ return sprintf(" %5.2f - %s\n", @_);
}
+