File Coverage

blib/lib/SOAP/WSDL/XSD/Typelib/Builtin/date.pm
Criterion Covered Total %
statement 30 30 100.0
branch 6 6 100.0
condition n/a
subroutine 7 7 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::date;
2 38     38   1038 use strict;
  38         72  
  38         1331  
3 38     38   190 use warnings;
  38         72  
  38         990  
4 38     38   33853 use Date::Parse;
  38         375197  
  38         6180  
5 38     38   37613 use Date::Format;
  38         127053  
  38         3678  
6              
7 38     38   1447 use Class::Std::Fast::Storable constructor => 'none', cache => 1;
  38         22305  
  38         498  
8 38     38   6634 use base qw(SOAP::WSDL::XSD::Typelib::Builtin::anySimpleType);
  38         132  
  38         14718  
9              
10             sub set_value {
11             # use set_value from base class if we have a XML-DateTime format
12             #2037-12-31+01:00
13 30 100   30 0 2251 if (
14             $_[1] =~ m{ ^\d{4} \- \d{2} \- \d{2}
15             (:? [\+\-] \d{2} \: \d{2} )$
16             }xms
17             ) {
18 2         9 $_[0]->SUPER::set_value($_[1])
19             }
20             # converting a date is hard work: It needs a timezone, because
21             # 2007-12-30+12:00 and 2007-12-31-12:00 mean the same day - just in
22             # different locations.
23             # strftime actually prints out the correct date, but always prints the
24             # local timezone with %z.
25             # So, if our timezone is not 0, we strftime it without timezone and
26             # append it by hand by the following formula:
27             # The timezone hours are the int (timesone seconds / 3600)
28             # The timezone minutes (if someone ever specifies something like that)
29             # are int( (seconds % 3600) / 60 )
30             # say, int( (seconds modulo 3600) / 60 )
31             #
32             # If we have no timezone (meaning the timezone is
33             else {
34             # strptime sets empty values to undef - and strftime doesn't like that...
35 28         641 my @time_from = strptime($_[1]);
36 28         1953 my $time_zone_seconds = $time_from[6];
37 28 100       51 @time_from = map { (! defined $_) ? 0 : $_ } @time_from;
  196         414  
38             # use Data::Dumper;
39             # warn Dumper \@time_from, sprintf('%+03d%02d', $time_from[6] / 3600, $time_from[6] % 60 );
40 28         44 my $time_str;
41 28 100       46 if (defined $time_zone_seconds) {
42 25         144 $time_str = sprintf('%04d-%02d-%02d%+03d:%02d', $time_from[5]+1900, $time_from[4]+1, $time_from[3], int($time_from[6] / 3600), int($time_from[6] % 3600) / 60);
43             }
44             else {
45 3         13 $time_str = strftime( '%Y-%m-%d%z', @time_from );
46 3         615 substr $time_str, -2, 0, ':';
47             }
48              
49             # ? strftime( '%Y-%m-%d', @time_from )
50             # . sprintf('%+03d%02d', int($time_from[6] / 3600), int ( ($time_from[6] % 3600) / 60 ) )
51             # : do {
52             # strftime( '%Y-%m-%d%z', @time_from );
53             # };
54             # substr $time_str, -2, 0, ':';
55 28         98 $_[0]->SUPER::set_value($time_str);
56             }
57             }
58              
59             1;
60