line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gedcom::Date; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
189671
|
use strict; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
367
|
|
4
|
7
|
|
|
7
|
|
479315
|
use DateTime::Locale; |
|
7
|
|
|
|
|
743273
|
|
|
7
|
|
|
|
|
244
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
97
|
use vars qw($VERSION); |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
473
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
4800
|
use Gedcom::Date::Simple; |
|
7
|
|
|
|
|
104
|
|
|
7
|
|
|
|
|
248
|
|
11
|
7
|
|
|
7
|
|
4248
|
use Gedcom::Date::Period; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
194
|
|
12
|
7
|
|
|
7
|
|
3758
|
use Gedcom::Date::Range; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
210
|
|
13
|
7
|
|
|
7
|
|
4097
|
use Gedcom::Date::Approximated; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
217
|
|
14
|
7
|
|
|
7
|
|
3994
|
use Gedcom::Date::Interpreted; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
219
|
|
15
|
7
|
|
|
7
|
|
3592
|
use Gedcom::Date::Phrase; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
283
|
|
16
|
|
|
|
|
|
|
|
17
|
7
|
|
|
|
|
71
|
use overload ( fallback => 1, |
18
|
|
|
|
|
|
|
'>' => '_later_than', |
19
|
|
|
|
|
|
|
'<' => '_earlier_than', |
20
|
7
|
|
|
7
|
|
47
|
); |
|
7
|
|
|
|
|
12
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
my $DefaultLocale; |
24
|
|
|
|
|
|
|
sub DefaultLocale { |
25
|
20
|
|
|
20
|
1
|
46
|
my $class = shift; |
26
|
|
|
|
|
|
|
|
27
|
20
|
100
|
|
|
|
78
|
if (my $locale = shift) { |
28
|
7
|
|
|
|
|
57
|
$DefaultLocale = DateTime::Locale->load($locale); |
29
|
|
|
|
|
|
|
} |
30
|
20
|
|
|
|
|
15317
|
return $DefaultLocale; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
__PACKAGE__->DefaultLocale('en_GB'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub parse { |
36
|
50
|
|
|
50
|
1
|
19275
|
my $class = shift; |
37
|
|
|
|
|
|
|
|
38
|
50
|
|
|
|
|
135
|
my ($str) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return |
41
|
50
|
|
66
|
|
|
233
|
Gedcom::Date::Period->parse($str) || |
42
|
|
|
|
|
|
|
Gedcom::Date::Range->parse($str) || |
43
|
|
|
|
|
|
|
Gedcom::Date::Approximated->parse($str) || |
44
|
|
|
|
|
|
|
Gedcom::Date::Interpreted->parse($str) || |
45
|
|
|
|
|
|
|
Gedcom::Date::Simple->parse($str) || |
46
|
|
|
|
|
|
|
Gedcom::Date::Phrase->parse($str); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub from_datetime { |
50
|
1
|
|
|
1
|
1
|
384
|
my ($class, $dt) = @_; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
10
|
return Gedcom::Date::Simple->from_datetime($dt); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub clone { |
56
|
11
|
|
|
11
|
1
|
62
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
11
|
|
|
|
|
15
|
my %clone; |
59
|
11
|
|
|
|
|
37
|
for (keys %$self) { |
60
|
21
|
100
|
|
|
|
51
|
if (ref($self->{$_})) { |
61
|
12
|
|
|
|
|
42
|
$clone{$_} = $self->{$_}->clone; |
62
|
|
|
|
|
|
|
} else { |
63
|
9
|
|
|
|
|
23
|
$clone{$_} = $self->{$_}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
11
|
|
|
|
|
99
|
return bless \%clone, ref $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _later_than { |
71
|
0
|
|
|
0
|
|
0
|
my ($self, $other, $switched) = @_; |
72
|
0
|
0
|
|
|
|
0
|
_earlier_than($other, $self) if $switched; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
0
|
return 1 if $self->earliest > $other->latest; |
75
|
0
|
0
|
|
|
|
0
|
return 0 if $self->latest < $other->earliest; |
76
|
0
|
|
|
|
|
0
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _earlier_than { |
80
|
1
|
|
|
1
|
|
7
|
my ($self, $other, $switched) = @_; |
81
|
1
|
50
|
|
|
|
4
|
_later_than($other, $self) if $switched; |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
6
|
return 0 if $self->earliest > $other->latest; |
84
|
1
|
50
|
|
|
|
96
|
return 1 if $self->latest < $other->earliest; |
85
|
0
|
|
|
|
|
0
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub as_text { |
89
|
39
|
|
|
39
|
1
|
38183
|
my ($self, $locale) = @_; |
90
|
|
|
|
|
|
|
|
91
|
39
|
|
66
|
|
|
178
|
$locale ||= $self->DefaultLocale(); |
92
|
39
|
100
|
|
|
|
198
|
$locale = DateTime::Locale->load($locale) unless ref $locale; |
93
|
39
|
|
|
|
|
4610
|
my $lang = $locale->language_id; |
94
|
|
|
|
|
|
|
|
95
|
39
|
|
|
|
|
826
|
my ($str, @dates) = $self->text_format($lang); |
96
|
|
|
|
|
|
|
|
97
|
39
|
|
|
|
|
242
|
$str =~ s/%(\d+)/ |
98
|
45
|
|
|
|
|
737
|
$dates[$1]->_date_as_text($locale); |
99
|
|
|
|
|
|
|
/ge; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Remove those ugly leading zeroes |
102
|
39
|
|
|
|
|
3829
|
$str =~ s/\b0+\B//g; |
103
|
|
|
|
|
|
|
|
104
|
39
|
|
|
|
|
302
|
return $str; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub add { |
108
|
11
|
|
|
11
|
1
|
5607
|
my $self = shift; |
109
|
|
|
|
|
|
|
|
110
|
11
|
|
|
|
|
75
|
for (qw/date from to bef aft/) { |
111
|
55
|
100
|
|
|
|
178
|
$self->{$_}->add(@_, secret => 1) if $self->{$_}; |
112
|
|
|
|
|
|
|
} |
113
|
11
|
|
|
|
|
25
|
return $self; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |