line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Range::Birth; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
107692
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
122
|
|
4
|
3
|
|
|
3
|
|
16
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
262
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Date::Range; |
8
|
3
|
|
|
3
|
|
18
|
use base qw(Date::Range); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
2941
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
5932
|
use Date::Calc; |
|
3
|
|
|
|
|
138616
|
|
|
3
|
|
|
|
|
155
|
|
11
|
3
|
|
|
3
|
|
6944
|
use Date::Simple; |
|
3
|
|
|
|
|
6675
|
|
|
3
|
|
|
|
|
1778
|
|
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
53
|
sub _croak { require Carp; Carp::croak(@_) } |
|
3
|
|
|
|
|
722
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
10
|
|
|
10
|
1
|
20688
|
my($class, $age, $date) = @_; |
17
|
10
|
|
66
|
|
|
40
|
$date ||= Date::Simple->new; # default today |
18
|
10
|
100
|
|
|
|
388
|
unless (UNIVERSAL::isa($date, 'Date::Simple')) { |
19
|
1
|
|
|
|
|
6
|
_croak("date should be given as Date::Simple object: $date"); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
9
|
|
|
|
|
15
|
my($start, $end); |
23
|
9
|
100
|
66
|
|
|
79
|
if (ref($age) && ref($age) eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
24
|
5
|
|
|
|
|
18
|
($start, $end) = $class->_from_array($age, $date); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ($age =~ /^\d+$/) { |
27
|
3
|
|
|
|
|
14
|
($start, $end) = $class->_from_age($age, $date); |
28
|
|
|
|
|
|
|
} else { |
29
|
1
|
|
|
|
|
5
|
_croak("invalid argument for Date::Range::Birth: $age"); |
30
|
|
|
|
|
|
|
} |
31
|
7
|
|
|
|
|
231
|
return $class->SUPER::new($start, $end); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _from_age { |
35
|
3
|
|
|
3
|
|
6
|
my($class, $age, $date) = @_; |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
9
|
my @start = Date::Calc::Add_Delta_YMD(_ymd($date), -$age - 1, 0, 1); |
38
|
3
|
|
|
|
|
260
|
my @end = Date::Calc::Add_Delta_YMD(_ymd($date), -$age, 0, 0); |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
183
|
return Date::Simple->new(@start), Date::Simple->new(@end); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _from_array { |
44
|
5
|
|
|
5
|
|
11
|
my($class, $age, $date) = @_; |
45
|
5
|
|
|
|
|
25
|
my @ages = sort { $a <=> $b } @$age; |
|
7
|
|
|
|
|
22
|
|
46
|
5
|
100
|
|
|
|
15
|
@ages == 2 or _croak("Date::Range::Birth: invalid number of args in age"); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# old's start to young's end |
49
|
4
|
|
|
|
|
12
|
my @start = Date::Calc::Add_Delta_YMD(_ymd($date), -$ages[1] - 1, 0, 1); |
50
|
4
|
|
|
|
|
292
|
my @end = Date::Calc::Add_Delta_YMD(_ymd($date), -$ages[0], 0, 0); |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
232
|
return Date::Simple->new(@start), Date::Simple->new(@end); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _ymd { |
56
|
14
|
|
|
14
|
|
16
|
my $date = shift; |
57
|
14
|
|
|
|
|
102
|
return $date->year, $date->month, $date->day; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
__END__ |