| 1 | package WWW::EFA::DateFactory; | ||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use Class::Date qw/date/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | A Factory for creating L<Class::Date> objects | ||||||||||
| 9 | |||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||
| 11 | |||||||||||
| 12 | my $factory = WWW::EFA::DateFactory->new(); | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | =head1 METHODS | ||||||||||
| 17 | |||||||||||
| 18 | =head2 date_from_itdDateTime | ||||||||||
| 19 | |||||||||||
| 20 | my $date = $factory->date_from_itdDateTime( $doc->findnodes( 'itdDateTime' ) ); | ||||||||||
| 21 | |||||||||||
| 22 | Expects an XML::LibXML::Element of XML like this: | ||||||||||
| 23 | |||||||||||
| 24 | <itdDateTime> | ||||||||||
| 25 | <itdDate year="2011" month="11" day="15" weekday="3"/> | ||||||||||
| 26 | <itdTime hour="9" minute="59"/> | ||||||||||
| 27 | </itdDateTime> | ||||||||||
| 28 | |||||||||||
| 29 | Returns a L<WWW::EFA::Departure> object | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | 0 | ▶ | sub date_from_itdDateTime { | ||||||||
|
Subroutine
date_from_itdDateTime: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 33 | 0 | my $self = shift; | |||||||||
| 34 | 0 | my $elem = shift; | |||||||||
| 35 | |||||||||||
| 36 | 0 | my( $date_elem ) = $elem->findnodes( 'itdDate' ); | |||||||||
| 37 | 0 | my( $time_elem ) = $elem->findnodes( 'itdTime' ); | |||||||||
| 38 | |||||||||||
| 39 | # Sometimes the day is '-1'.... this is not valid... | ||||||||||
| 40 | 0 | ▶ | if( $date_elem->getAttribute( 'day' ) < 0 ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | return undef; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | # TODO: RCL 2011-11-13 Test that attributes exist and are valid | ||||||||||
| 45 | 0 | my $date = date( { | |||||||||
| 46 | year => $date_elem->getAttribute( 'year' ), | ||||||||||
| 47 | month => $date_elem->getAttribute( 'month' ), | ||||||||||
| 48 | day => $date_elem->getAttribute( 'day' ), | ||||||||||
| 49 | hour => $time_elem->getAttribute( 'hour' ), | ||||||||||
| 50 | min => $time_elem->getAttribute( 'minute' ), | ||||||||||
| 51 | } ); | ||||||||||
| 52 | |||||||||||
| 53 | 0 | return $date; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | 2 | 1; | |||||||||
| 58 | |||||||||||
| 59 | =head1 COPYRIGHT | ||||||||||
| 60 | |||||||||||
| 61 | Copyright 2011, Robin Clarke, Munich, Germany | ||||||||||
| 62 | |||||||||||
| 63 | =head1 AUTHOR | ||||||||||
| 64 | |||||||||||
| 65 | Robin Clarke <perl@robinclarke.net> | ||||||||||
| 66 | |||||||||||