From 57b93c346efcd3b180f24cf19e78dd3ceab0cd1d Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 27 May 2013 17:26:09 +0100 Subject: show predicted arrivals --- driver.pl | 2 ++ forecast.html.tt | 16 +++++++++++++--- lib/HomePanel/Render.pm | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/driver.pl b/driver.pl index 54a04ab..561b253 100644 --- a/driver.pl +++ b/driver.pl @@ -20,6 +20,8 @@ my $bus = WebService::TFL::Bus->new()->request( ); my $template = file(__FILE__)->parent->file('forecast.html.tt'); +binmode STDOUT,':utf8'; + print HomePanel::Render->new({ template_file => $template, diff --git a/forecast.html.tt b/forecast.html.tt index a3cb750..82d8412 100644 --- a/forecast.html.tt +++ b/forecast.html.tt @@ -5,12 +5,21 @@ hourly = f.hourly.slice('from', today_start, 'to', today_stop); MACRO hours_length(span) BLOCK; d=span.stop_time.subtract_datetime(span.start_time); - v=d.in_units('days','hours'); - v.0 * 24 + v.1; + format_duration( + 'pattern','%k', + 'base',span.start_time, + 'normalize',1).format_duration(d); END; MACRO time(d) BLOCK; d.clone.set_time_zone('Europe/London').strftime('%H:%M'); END; + MACRO minsec_until(d) BLOCK; + dur=d.subtract_datetime(now); + format_duration( + 'pattern','%M:%S', + 'base',now, + 'normalize',1).format_duration(dur); + END; -%] @@ -23,6 +32,7 @@ } .timeline { position: relative; + height: 6em; } .stripes { position: absolute; @@ -127,7 +137,7 @@ [% p.LineName %] [% p.DestinationText %] - [% p.EstimatedTime %] + [% minsec_until(p.EstimatedTime) %] [% END %] diff --git a/lib/HomePanel/Render.pm b/lib/HomePanel/Render.pm index a1bbcc9..6984048 100644 --- a/lib/HomePanel/Render.pm +++ b/lib/HomePanel/Render.pm @@ -4,6 +4,8 @@ use MooseX::Types::Path::Class; use Template::Provider::Encoding; use Template::Stash::ForceUTF8; use Template; +use DateTime; +use DateTime::Format::Duration; has [qw(provider stash template)] => ( is => 'ro', @@ -70,6 +72,8 @@ sub render { b => $self->bus, t => $self->tube, icon_for => \&icon_for, + now => DateTime->now, + format_duration => sub { DateTime::Format::Duration->new(@_) }, }, \$output, ) or die $self->template->error; -- cgit v1.2.3