summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2013-05-27 17:26:09 +0100
committerdakkar <dakkar@thenautilus.net>2013-05-27 17:26:09 +0100
commit57b93c346efcd3b180f24cf19e78dd3ceab0cd1d (patch)
tree89a2502aef8078d920806578ab70b5f07e1bf65c
parentfactored TFL client (diff)
downloadHomePanel-57b93c346efcd3b180f24cf19e78dd3ceab0cd1d.tar.gz
HomePanel-57b93c346efcd3b180f24cf19e78dd3ceab0cd1d.tar.bz2
HomePanel-57b93c346efcd3b180f24cf19e78dd3ceab0cd1d.zip
show predicted arrivals
-rw-r--r--driver.pl2
-rw-r--r--forecast.html.tt16
-rw-r--r--lib/HomePanel/Render.pm4
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;
-%]
<html>
<head>
@@ -23,6 +32,7 @@
}
.timeline {
position: relative;
+ height: 6em;
}
.stripes {
position: absolute;
@@ -127,7 +137,7 @@
<tr>
<td>[% p.LineName %]</td>
<td>[% p.DestinationText %]</td>
- <td>[% p.EstimatedTime %]</td>
+ <td>[% minsec_until(p.EstimatedTime) %]</td>
</tr>
[% END %]
</tbody>
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;