line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Span::Birthdate; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1458
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
106
|
|
4
|
3
|
|
|
3
|
|
15
|
use base qw( DateTime::Span ); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
954
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
465095
|
use Carp; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
199
|
|
8
|
3
|
|
|
3
|
|
16
|
use DateTime; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
71
|
|
9
|
3
|
|
|
3
|
|
17
|
use DateTime::Span; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
900
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
9
|
|
|
9
|
0
|
21
|
my $class = shift; |
13
|
9
|
|
|
|
|
38
|
my %p = @_; |
14
|
|
|
|
|
|
|
|
15
|
9
|
|
33
|
|
|
52
|
$p{on} ||= DateTime->now; |
16
|
|
|
|
|
|
|
|
17
|
9
|
|
|
|
|
470
|
my @dates; |
18
|
9
|
100
|
66
|
|
|
60
|
if ($p{from} && $p{to}) { |
|
|
100
|
|
|
|
|
|
19
|
4
|
|
|
|
|
27
|
@dates = $class->_from_array($p{from}, $p{to}, $p{on}); |
20
|
|
|
|
|
|
|
} elsif ($p{age}) { |
21
|
4
|
|
|
|
|
20
|
@dates = $class->_from_age($p{age}, $p{on}); |
22
|
|
|
|
|
|
|
} else { |
23
|
1
|
|
|
|
|
253
|
croak "DateTime::Span::Birthdate->new() requires from, to or age parameter"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
77
|
return $class->from_datetimes( start => $dates[0], end => $dates[1] ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _from_array { |
30
|
4
|
|
|
4
|
|
10
|
my($class, $from, $to, $dt) = @_; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
19
|
my $start = $dt->clone->subtract(years => $to + 1, days => -1); |
33
|
4
|
|
|
|
|
3393
|
my $end = $dt->clone->subtract(years => $from); |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
2763
|
return ($start, $end); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _from_age { |
39
|
4
|
|
|
4
|
|
9
|
my($class, $age, $dt) = @_; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
20
|
my $start = $dt->clone->subtract(years => $age + 1, days => -1); |
42
|
4
|
|
|
|
|
3830
|
my $end = $dt->clone->subtract(years => $age); |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
2961
|
return ($start, $end); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
__END__ |