changeset 191:127b1d0f874e

Use Time::Piece for some timestamp parsing.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 13 Jun 2014 21:43:53 +0300
parents 15c49bb1ce05
children 52d8fa967c24
files fetch_weather.pl
diffstat 1 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_weather.pl	Fri Jun 13 17:38:09 2014 +0300
+++ b/fetch_weather.pl	Fri Jun 13 21:43:53 2014 +0300
@@ -17,7 +17,7 @@
 use HTML::Entities;
 use XML::Simple;
 use Text::Iconv;
-use Date::Parse;
+use Time::Piece;
 use Date::Format;
 use Data::Dumper;
 
@@ -59,14 +59,15 @@
 sub parse_timestamp($$)
 {
   # XXX: A bit of a hack, but it works.
-  return str2time($_[0]) - str2time("00:00") + $_[1];
+  return Time::Piece->strptime($_[0], "%OH:%OM")->epoch -
+         Time::Piece->strptime("00:00", "%OH:%OM")->epoch + $_[1];
 }
 
 
 sub gmt_time_fmt($)
 {
   # 2012-02-27T00:00:00Z
-  return time2str("%Y-%m-%dT%TZ", $_[0], "UTC");
+  return gmtime($_[0])->strftime("%Y-%m-%dT%TZ");
 }
 
 sub str_trim($)
@@ -359,11 +360,11 @@
       # Find our desired element nodes
       my $odata = fnodea(fnode($otree, "body"), "div", "class=elementc");
       my $oupdate = fnode($odata, "p");
-      my $time_base = str2time("00:00");
+      my $time_base = Time::Piece->strptime("00:00", "%H:%M")->epoch;
       if ($oupdate) {
         my $tmp = $oupdate->{"nodes"}[0]{"text"};
         if ($tmp =~ /:\s+(\d\d\.\d\d\.\d\d\d\d)\s+(\d\d:\d\d)/) {
-          $time_base = str2time($1);
+          $time_base = Time::Piece->strptime($1, "%Od.%Om.%Y")->epoch;
         }
       }