File Coverage

blib/lib/SOAP/WSDL/XSD/Typelib/Builtin/time.pm
Criterion Covered Total %
statement 31 31 100.0
branch 4 4 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 43 44 97.7


line stmt bran cond sub pod time code
1             package SOAP::WSDL::XSD::Typelib::Builtin::time;
2 36     36   1276 use strict;
  36         82  
  36         1935  
3 36     36   224 use warnings;
  36         67  
  36         900  
4 36     36   233 use Date::Parse;
  36         86  
  36         5372  
5 36     36   208 use Date::Format;
  36         76  
  36         3075  
6 36     36   1123 use Class::Std::Fast::Storable constructor => 'none', cache => 1;
  36         23837  
  36         359  
7 36     36   5848 use base qw(SOAP::WSDL::XSD::Typelib::Builtin::anySimpleType);
  36         218  
  36         3715  
8              
9 36     36   249 use version; our $VERSION = qv('3.001');
  36         80  
  36         312  
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 569 if (
15             $_[1] =~ m{ ^ \d{2} \: \d{2} \: \d{2} (:? \. \d{1,7} )?
16             [\+\-] \d{2} \: \d{2} $
17             }xms
18             ) {
19 1         5 $_[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         42 my @now = localtime;
32 1         28 my @time_from = map { my $alternative = shift @now;
  7         527  
33 7 100       18 ! defined $_
34             ? $alternative
35             : $_ } strptime($_[1]);
36 1         4 undef $time_from[-1];
37 1         6 my $time_str = strftime( '%H:%M:%S%z', @time_from );
38 1         221 substr $time_str, -2, 0, ':';
39 1         9 $_[0]->SUPER::set_value($time_str);
40             }
41             }
42              
43             1;