line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Czech; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
6
|
|
|
6
|
|
606240
|
$DateTime::Format::Czech::VERSION = '0.2'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
2636
|
use utf8; |
|
6
|
|
|
|
|
36
|
|
|
6
|
|
|
|
|
35
|
|
7
|
6
|
|
|
6
|
|
8961
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=encoding utf-8 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Format your DateTime values as usual in Czech. Now also |
14
|
|
|
|
|
|
|
with month names, day names and less sugar! |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $fmt = DateTime::Format::Czech->new; |
19
|
|
|
|
|
|
|
my $date = DateTime->new(year => 2010, month => 6, day => 13); |
20
|
|
|
|
|
|
|
say $fmt->format_datetime($date); # 13. Äervna 2010 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=over 4 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=item B<show_time> |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Include time in the output. Off by default. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item B<show_date> |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Include date in the output. On by default. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item B<show_year> |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Include year in the date output (â1. 12. 2010â). Off by default. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item B<show_day_name> |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Include day name in date output (ânedÄle 13. 6.â). Off by |
41
|
|
|
|
|
|
|
default. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item B<show_month_name> |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Use month name instead of its number (â1. prosince 2010â). |
46
|
|
|
|
|
|
|
On by default. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item B<compound_format> |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The C<sprintf> pattern used to glue the time and date parts. |
51
|
|
|
|
|
|
|
The default value is C<%s v %s> (â5. 6. v 16.30â). |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=back |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has show_time => (is => 'ro', isa => 'Bool', default => 0); |
58
|
|
|
|
|
|
|
has show_date => (is => 'ro', isa => 'Bool', default => 1); |
59
|
|
|
|
|
|
|
has show_year => (is => 'ro', isa => 'Bool', default => 0); |
60
|
|
|
|
|
|
|
has show_day_name => (is => 'ro', isa => 'Bool', default => 0); |
61
|
|
|
|
|
|
|
has show_month_name => (is => 'ro', isa => 'Bool', default => 1); |
62
|
|
|
|
|
|
|
has compound_format => (is => 'ro', isa => 'Str', default => '%s v %s'); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my @MONTH_NAMES = qw/ |
65
|
|
|
|
|
|
|
ledna února bÅezna dubna |
66
|
|
|
|
|
|
|
kvÄtna Äervna Äervence srpna záÅà |
67
|
|
|
|
|
|
|
ÅÃjna listopadu prosince/; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my @DAY_NAMES = qw/ |
70
|
|
|
|
|
|
|
pondÄlà úterý stÅeda Ätvrtek |
71
|
|
|
|
|
|
|
pátek sobota nedÄle/; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item B<format_date> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Takes a L<DateTime> value, returns a string representation |
80
|
|
|
|
|
|
|
of its date part. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub format_date |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
my ($self, $date) = @_; |
87
|
|
|
|
|
|
|
my $output = $self->show_month_name ? |
88
|
|
|
|
|
|
|
join('. ', $date->day, $MONTH_NAMES[$date->month_0]) : |
89
|
|
|
|
|
|
|
sprintf '%i. %i.', $date->day, $date->month; |
90
|
|
|
|
|
|
|
$output = $DAY_NAMES[$date->wday_0] . ' ' . $output if $self->show_day_name; |
91
|
|
|
|
|
|
|
$output .= ' ' . $date->year if $self->show_year; |
92
|
|
|
|
|
|
|
return $output; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item B<format_time> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Takes a L<DateTime> value, returns a string representation |
98
|
|
|
|
|
|
|
of its time part in 24-hour time system. Minutes are zero-padded |
99
|
|
|
|
|
|
|
if needed (â13.00â, â19.01â). |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub format_time |
104
|
|
|
|
|
|
|
{ |
105
|
|
|
|
|
|
|
my ($self, $date) = @_; |
106
|
|
|
|
|
|
|
return sprintf '%i.%02i', $date->hour, $date->minute; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item B<format_datetime> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Formats a given L<DateTime> value, returning date and time parts |
112
|
|
|
|
|
|
|
as configured by the C<show_date> and C<show_time> attributes. The |
113
|
|
|
|
|
|
|
date and time parts are glued together using the C<compound_format> |
114
|
|
|
|
|
|
|
pattern. You can also call this method using the shorter C<format> |
115
|
|
|
|
|
|
|
name. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub format_datetime |
122
|
|
|
|
|
|
|
{ |
123
|
|
|
|
|
|
|
my ($self, $date) = @_; |
124
|
|
|
|
|
|
|
if ($self->show_time && $self->show_date) { |
125
|
|
|
|
|
|
|
return sprintf $self->compound_format, |
126
|
|
|
|
|
|
|
$self->format_date($date), $self->format_time($date); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
return $self->format_date($date) if $self->show_date; |
129
|
|
|
|
|
|
|
return $self->format_time($date); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub format { |
133
|
|
|
|
|
|
|
return shift->format_datetime(@_); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Tomáš ZnamenáÄek, zoul@fleuron.cz |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
'SDG'; |