| 1 | package DateTime::Format::Duration::XSD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use DateTime::Duration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use DateTime::Format::Duration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = 0.01; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | return bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | fmt => DateTime::Format::Duration->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | pattern => '%PP%YY%mM%dDT%HH%MM%S.%NS', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | normalize => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | sub parse_duration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_duration: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | my ($self, $xs_duration) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | my ($neg, $year, $mounth, $day, $hour, $min, $sec, $fsec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | ▶ | if ($xs_duration =~ /^(-)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | P | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ((\d+)Y)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ((\d+)M)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ((\d+)D)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | T | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ((\d+)H)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ((\d+)M)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | (((\d+)(\.(\d+))?)S)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $/x) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ($neg, $year, $mounth, $day, $hour, $min, $sec, $fsec) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ($1, $3, $5, $7, $10, $12, $15, $17); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | unless (grep {defined} ($year, $mounth, $day, $hour, $min, $sec)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | croak "duration contains no data '$xs_duration'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | croak "duration string does not match standart: '$xs_duration'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | ▶ | my $dt = DateTime::Duration->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%12/12
$year || 0
$mounth || 0
$day || 0
$hour || 0
$min || 0
$sec || 0
MC/DC100%1/1
$year || 0
$year
MC/DC100%1/1
$mounth || 0
$mounth
MC/DC100%1/1
$day || 0
$day
MC/DC100%1/1
$hour || 0
$hour
MC/DC100%1/1
$min || 0
$min
MC/DC100%1/1
$sec || 0
$sec
Truth table100%2/2
A
A= $year
Truth table100%2/2
A
A= $mounth
Truth table100%2/2
A
A= $day
Truth table100%2/2
A
A= $hour
Truth table100%2/2
A
A= $min
Truth table100%2/2
A
A= $sec
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | years => $year || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | months => $mounth || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | days => $day || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | hours => $hour || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | minutes => $min || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | seconds => $sec || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | nanoseconds => ($fsec ? "0.$fsec" * 1E9 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | return defined $neg ? $dt->inverse : $dt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub format_duration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_duration: called CC=13 SCAR=28.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | my ($self, $duration) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | my %deltas = $self->{fmt}->normalize($duration); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | if (exists $deltas{seconds} or exists $deltas{nanoseconds}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $deltas{"seconds"} or exists $deltas{"nanoseconds"}
MC/DC0%0/2
exists $deltas{"seconds"} or exists $deltas{"nanoseconds"}
exists $deltas{"seconds"}
exists $deltas{"nanoseconds"}
Truth table33%1/3
A or B
A= exists $deltas{"seconds"}B= exists $deltas{"nanoseconds"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $deltas{seconds} = ($deltas{seconds} || 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | ▶ | + (exists $deltas{nanoseconds} ? $deltas{nanoseconds} / 1E9 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$deltas{'seconds'} || 0
MC/DC100%1/1
$deltas{'seconds'} || 0
$deltas{'seconds'}
Truth table100%2/2
A
A= $deltas{'seconds'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | my $str = $deltas{negative} ? "-P" : "P"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | $str .= "$deltas{years}Y" if exists $deltas{years}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | $str .= "$deltas{months}M" if exists $deltas{months}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | ▶ | $str .= "$deltas{days}D" if exists $deltas{days}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | $str .= "T" if grep {exists $deltas{$_}} qw(hours minutes seconds); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | ▶ | $str .= "$deltas{hours}H" if exists $deltas{hours}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | $str .= "$deltas{minutes}M" if exists $deltas{minutes}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | ▶ | $str .= "$deltas{seconds}S" if exists $deltas{seconds}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | DateTime::Format::Duration::XSD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | use DateTime::Format::Duration::XSD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | my $dfdx = DateTime::Format::Duration::XSD->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | my $duration_object = $dfdx->parse_duration('-P1Y2M3DT1H2M3.33S'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | my $xsd_duration = $dfdx->format_duration($duration_object); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | DateTime::Format::Duration::XSD - Formats and parses DateTime::Duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | according to xs:duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | L<DateTime>, L<DateTime::Duration>, L<DateTime::Format::XSD> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | The XML Schema speficitation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | Smal D A, E<lt>mialinx@gmail.comE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | Copyright (C) 2009 by Smal D A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||