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 36     36   630 use strict;
  36         36  
  36         980  
3 36     36   119 use warnings;
  36         37  
  36         632  
4 36     36   13722 use Date::Parse;
  36         175613  
  36         3955  
5 36     36   13610 use Date::Format;
  36         68722  
  36         2002  
6              
7 36     36   580 use Class::Std::Fast::Storable constructor => 'none', cache => 1;
  36         14019  
  36         276  
8 36     36   3937 use base qw(SOAP::WSDL::XSD::Typelib::Builtin::anySimpleType);
  36         53  
  36         8527  
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 1589 if (
14             $_[1] =~ m{ ^\d{4} \- \d{2} \- \d{2}
15             (:? [\+\-] \d{2} \: \d{2} )$
16             }xms
17             ) {
18 2         8 $_[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         500 my @time_from = strptime($_[1]);
36 28         1471 my $time_zone_seconds = $time_from[6];
37 28 100       30 @time_from = map { (! defined $_) ? 0 : $_ } @time_from;
  196         268  
38             # use Data::Dumper;
39             # warn Dumper \@time_from, sprintf('%+03d%02d', $time_from[6] / 3600, $time_from[6] % 60 );
40 28         28 my $time_str;
41 28 100       26 if (defined $time_zone_seconds) {
42 25         110 $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         10 $time_str = strftime( '%Y-%m-%d%z', @time_from );
46 3         458 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         73 $_[0]->SUPER::set_value($time_str);
56             }
57             }
58              
59             1;
60