File Coverage

blib/lib/SOAP/WSDL/XSD/Typelib/Builtin/time.pm
Criterion Covered Total %
statement 28 28 100.0
branch 4 4 100.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             package SOAP::WSDL::XSD::Typelib::Builtin::time;
2 38     38   1343 use strict;
  38         73  
  38         1241  
3 38     38   209 use warnings;
  38         79  
  38         1138  
4 38     38   215 use Date::Parse;
  38         74  
  38         6014  
5 38     38   252 use Date::Format;
  38         77  
  38         3008  
6 38     38   1263 use Class::Std::Fast::Storable constructor => 'none', cache => 1;
  38         26789  
  38         363  
7 38     38   5642 use base qw(SOAP::WSDL::XSD::Typelib::Builtin::anySimpleType);
  38         94  
  38         14060  
8              
9             our $VERSION = $SOAP::WSDL::VERSION;
10              
11             sub set_value {
12             # use set_value from base class if we have a XML-Time format
13             # 00:00:00.0000000+01:00
14 2 100   2 0 651 if (
15             $_[1] =~ m{ ^ \d{2} \: \d{2} \: \d{2} (:? \. \d{1,7} )?
16             [\+\-] \d{2} \: \d{2} $
17             }xms
18             ) {
19 1         6 $_[0]->SUPER::set_value($_[1])
20             }
21             # use a combination of strptime and strftime for converting the date
22             # Unfortunately, strftime outputs the time zone as [+-]0000, whereas XML
23             # whants it as [+-]00:00
24             # We leave out the optional nanoseconds part, as it would always be empty.
25             else {
26             # strptime sets empty values to undef - and strftime doesn't like that...
27             # we even need to set it to 1 to prevent a "Day '0' out of range 1..31" warning..
28              
29             # we need to set the current date for correct TZ conversion -
30             # could be daylight savings time
31 1         40 my @now = localtime;
32 1         32 my @time_from = map { my $alternative = shift @now;
  7         579  
33 7 100       20 ! defined $_
34             ? $alternative
35             : $_ } strptime($_[1]);
36 1         3 undef $time_from[-1];
37 1         5 my $time_str = strftime( '%H:%M:%S%z', @time_from );
38 1         230 substr $time_str, -2, 0, ':';
39 1         10 $_[0]->SUPER::set_value($time_str);
40             }
41             }
42              
43             1;