| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (C) 2004 Joshua Hoblitt |
|
2
|
|
|
|
|
|
|
# Copyright (C) 2001 Simon Cozens |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# $Id: Human.pm,v 1.1.1.1 2004/10/17 00:44:32 jhoblitt Exp $ |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package DateTime::Format::Human; |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
273045
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
82
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
12
|
use vars qw( $VERSION ); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
141
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.01'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
2506
|
use DateTime; |
|
|
2
|
|
|
|
|
284258
|
|
|
|
2
|
|
|
|
|
80
|
|
|
14
|
2
|
|
|
2
|
|
19
|
use Params::Validate qw( validate validate_pos SCALAR OBJECT ); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2687
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %templates = ( |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
English => { |
|
19
|
|
|
|
|
|
|
numbers => [ qw(one two three four five six seven eight nine ten eleven twelve) ], |
|
20
|
|
|
|
|
|
|
vagueness=> [ "exactly", "just after", "a little after", "coming up to", "almost" ], |
|
21
|
|
|
|
|
|
|
daytime => [ "in the morning", "in the afternoon", "in the evening", "at night" ], |
|
22
|
|
|
|
|
|
|
minutes => [ "five past", "ten past", "quarter past", "twenty past", |
|
23
|
|
|
|
|
|
|
"twenty-five past", "half past", "twenty-five to", |
|
24
|
|
|
|
|
|
|
"twenty to", "quarter to", "ten to", "five to" ], |
|
25
|
|
|
|
|
|
|
oclock => "o'clock", |
|
26
|
|
|
|
|
|
|
midnight => "midnight", |
|
27
|
|
|
|
|
|
|
midday => "midday", |
|
28
|
|
|
|
|
|
|
format => "%v %m %h %d", |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $language = "English"; |
|
33
|
|
|
|
|
|
|
my $evening = 18; |
|
34
|
|
|
|
|
|
|
my $night = 22; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
|
37
|
49
|
|
|
49
|
1
|
41538
|
my $class = shift; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my %args = validate( @_, |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
|
|
|
|
|
|
evening => { |
|
42
|
|
|
|
|
|
|
type => SCALAR, |
|
43
|
|
|
|
|
|
|
callbacks => { |
|
44
|
3
|
50
|
|
3
|
|
68
|
'is >= 0 <= 23' => sub { $_[0] >= 0 && $_[0] <= 23 }, |
|
45
|
3
|
|
|
3
|
|
19
|
'is integer' => sub { $_[0] =~ /^\d+$/ }, |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
default => $evening, |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
night => { |
|
50
|
|
|
|
|
|
|
type => SCALAR, |
|
51
|
|
|
|
|
|
|
callbacks => { |
|
52
|
3
|
50
|
|
3
|
|
25
|
'is >= 0 <= 23' => sub { $_[0] >= 0 && $_[0] <= 23 }, |
|
53
|
3
|
|
|
3
|
|
36
|
'is integer' => sub { $_[0] =~ /^\d+$/ }, |
|
54
|
|
|
|
|
|
|
}, |
|
55
|
49
|
|
|
|
|
1744
|
default => $night, |
|
56
|
|
|
|
|
|
|
}, |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
}, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
49
|
|
|
|
|
828
|
my $self = { |
|
62
|
|
|
|
|
|
|
language => $language, |
|
63
|
|
|
|
|
|
|
evening => $args{ 'evening' }, |
|
64
|
|
|
|
|
|
|
night => $args{ 'night' }, |
|
65
|
|
|
|
|
|
|
}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
49
|
|
33
|
|
|
341
|
bless $self, ref $class || $class; |
|
68
|
|
|
|
|
|
|
|
|
69
|
49
|
|
|
|
|
191
|
return $self; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub format_datetime { |
|
73
|
48
|
|
|
48
|
1
|
12556
|
my $self = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
48
|
|
|
|
|
816
|
my @args = validate_pos( @_, |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
|
|
|
|
|
|
type => OBJECT, |
|
78
|
|
|
|
|
|
|
can => 'utc_rd_values', |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
48
|
|
|
|
|
2128
|
my $dt = DateTime->from_object( object => $args[0] ); |
|
83
|
48
|
|
|
|
|
23554
|
$dt->set_time_zone( 'local' ); |
|
84
|
|
|
|
|
|
|
|
|
85
|
48
|
|
|
|
|
310093
|
my $hour = $dt->hour; |
|
86
|
48
|
|
|
|
|
440
|
my $minute = $dt->minute; |
|
87
|
|
|
|
|
|
|
|
|
88
|
48
|
|
|
|
|
324
|
my $vague = $minute % 5; |
|
89
|
48
|
|
|
|
|
120
|
my $close_minute = $minute-$vague; |
|
90
|
48
|
|
|
|
|
193
|
my $t = $templates{ $self->{ 'language' } }; |
|
91
|
48
|
|
|
|
|
82
|
my $say_hour; |
|
92
|
48
|
|
|
|
|
94
|
my $daytime =""; |
|
93
|
48
|
100
|
|
|
|
216
|
if ($vague > 2) {$close_minute += 5} |
|
|
2
|
|
|
|
|
6
|
|
|
94
|
48
|
100
|
|
|
|
170
|
if ($close_minute >30) { $hour++; $hour %=24; } |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
9
|
|
|
95
|
48
|
|
|
|
|
102
|
$close_minute /= 5; |
|
96
|
48
|
|
|
|
|
93
|
$close_minute %= 12; |
|
97
|
48
|
100
|
|
|
|
163
|
if ($hour ==0) { |
|
|
|
100
|
|
|
|
|
|
|
98
|
12
|
|
|
|
|
39
|
$say_hour = $t->{midnight}; |
|
99
|
|
|
|
|
|
|
} elsif ($hour == 12) { |
|
100
|
2
|
|
|
|
|
6
|
$say_hour = $t->{midday}; |
|
101
|
|
|
|
|
|
|
} else { |
|
102
|
34
|
|
|
|
|
126
|
$say_hour = $t->{numbers}[$hour%12-1]; |
|
103
|
34
|
100
|
|
|
|
219
|
$daytime = $hour <= 12 ? ($t->{daytime}[0]) : |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$hour >= $self->{ 'night' } ? $t->{daytime}[3] : |
|
105
|
|
|
|
|
|
|
($hour >= $self->{ 'evening' } ? $t->{daytime}[2] : |
|
106
|
|
|
|
|
|
|
$t->{daytime}[1]); # Afternoon |
|
107
|
|
|
|
|
|
|
} |
|
108
|
48
|
100
|
|
|
|
132
|
if ($close_minute==0) { |
|
109
|
34
|
100
|
100
|
|
|
259
|
$say_hour .= " ". $t->{oclock} unless $hour ==0 or $hour == 12; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
48
|
100
|
|
|
|
155
|
my $say_min = $close_minute ==0? "" : $t->{minutes}[$close_minute-1]; |
|
112
|
48
|
|
|
|
|
108
|
my $rv = $t->{format}; |
|
113
|
|
|
|
|
|
|
|
|
114
|
48
|
|
|
|
|
252
|
$rv =~ s/%v/$t->{vagueness}[$vague]/eg; |
|
|
48
|
|
|
|
|
446
|
|
|
115
|
|
|
|
|
|
|
# remove the extra space caused by an empty $say_mih |
|
116
|
48
|
100
|
|
|
|
468
|
$rv =~ s/ %m|%m//g unless $say_min; |
|
117
|
48
|
|
|
|
|
142
|
$rv =~ s/%m/$say_min/g; |
|
118
|
48
|
|
|
|
|
170
|
$rv =~ s/%h/$say_hour/g; |
|
119
|
|
|
|
|
|
|
# remove the extra space caused by an empty $daytime |
|
120
|
48
|
100
|
|
|
|
216
|
$rv =~ s/ %d|%d//g unless $daytime; |
|
121
|
48
|
|
|
|
|
140
|
$rv =~ s/%d/$daytime/g; |
|
122
|
48
|
|
|
|
|
2189
|
return $rv; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |