| Weather-YR documentation | Contained in the Weather-YR distribution. |
Weather::YR::Parser - Helps to parse special types of data.
This module is a helper to parse different types of data, such as dates.
This method parses a date string and returns a object reference to an instance of DateTime.
It takes the timestamp in the following format: YYYY-MM-DD HH:MM:SS
This method parses a date string and returns a object reference to an instance of DateTime.
It takes the timestamp in the format specified in ISO 8601.
Example: 2008-03-16T10:49:13Z
Knut-Olav, <knut-olav@hoven.ws>
Copyright (C) 2008 by Knut-Olav Hoven
This library is free software; you can redireibute it and/or modify it under the terms as GNU GPL version 2.
| Weather-YR documentation | Contained in the Weather-YR distribution. |
package Weather::YR::Parser; use strict; use warnings; use DateTime; use DateTime::Format::ISO8601;
sub parse_date { my ( $str ) = @_; my ($year, $month, $day, $hour, $minute, $sec) = $str =~ m{ (\d{4}) - (\d{2}) - (\d{2}) \s (\d{2}) : (\d{2}) : (\d{2}) }x; my $date = DateTime->new( 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $sec, ); return $date; }
sub parse_date_iso8601 { my ( $str ) = @_; my $dt = DateTime::Format::ISO8601->parse_datetime($str); return $dt; }
1;