From 57d18e373f2c3bbe55b206c3c8263057a26b7505 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 22 Apr 2016 21:15:35 +0200 Subject: improved date handling diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules index a1e2d2f..fd74380 100755 --- a/utils/rhrd-schedules +++ b/utils/rhrd-schedules @@ -60,18 +60,18 @@ sub generate sub show__day { - my ($ctx, @date) = @_; + my ($ctx, $year, $month, $day) = @_; - print "https://pv.helsinki.at/export/day_schedule/$date[0]/$date[1]/$date[2]\n"; + print "https://pv.helsinki.at/export/day_schedule/$year/$month/$day\n"; - my ($ret, $data) = RHRD::utils::fetch_parse_json("https://pv.helsinki.at/export/day_schedule/$date[0]/$date[1]/$date[2]", "rhrd-schedules"); + my ($ret, $data) = RHRD::utils::fetch_parse_json("https://pv.helsinki.at/export/day_schedule/$year/$month/$day", "rhrd-schedules"); if(!$ret) { print STDERR "Error fetching export from PV: $data\n"; return 1; } - my $dow = Date::Calc::Day_of_Week(@date); - my $week = RHRD::utils::get_rd_week(DateTime->new(year => $date[0], month => $date[1], day => $date[2], hour => 12)); + my $dow = Date::Calc::Day_of_Week($year, $month, $day); + my $week = RHRD::utils::get_rd_week(DateTime->new(year => $year, month => $month, day => $day, hour => 12)); my $errcnt = 0; for my $entry (@{$data}) { @@ -125,14 +125,19 @@ sub show { my ($ctx, $week, $dow) = @_; - # TODO: parse week number and day - - my @date = (2016, 4, 14); + my @dates = (); -# print "$date[0].$date[1].$date[2] (" . Date::Calc::Day_of_Week_to_Text() . "):\n"; - print Date::Calc::Date_to_Text(@date) . ":\n"; - my $errcnt = show__day($ctx, @date); - print " -> $errcnt errors.\n\n"; + # TODO: parse week number and day + my @d1 = (2016, 4, 14); + my @d2 = (2016, 4, 15); + $dates[0] = \@d1; + $dates[1] = \@d2; + + for my $date (@dates) { + print Date::Calc::Date_to_Text(@{$date}) . ":\n"; + my $errcnt = show__day($ctx, @{$date}); + print " -> $errcnt errors.\n\n"; + } return 0; } -- cgit v0.10.2