| 1 | package DateTime::Format::Czech; | ||||||||||||||||||||||||||||
| 2 | 6 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | $DateTime::Format::Czech::VERSION = '0.2'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=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 | 6 | has show_time => (is => 'ro', isa => 'Bool', default => 0); | |||||||||||||||||||||||||||
| 58 | 6 | has show_date => (is => 'ro', isa => 'Bool', default => 1); | |||||||||||||||||||||||||||
| 59 | 6 | has show_year => (is => 'ro', isa => 'Bool', default => 0); | |||||||||||||||||||||||||||
| 60 | 6 | has show_day_name => (is => 'ro', isa => 'Bool', default => 0); | |||||||||||||||||||||||||||
| 61 | 6 | has show_month_name => (is => 'ro', isa => 'Bool', default => 1); | |||||||||||||||||||||||||||
| 62 | 6 | has compound_format => (is => 'ro', isa => 'Str', default => '%s v %s'); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 6 | my @MONTH_NAMES = qw/ | |||||||||||||||||||||||||||
| 65 | ledna února března dubna | ||||||||||||||||||||||||||||
| 66 | května června července srpna září | ||||||||||||||||||||||||||||
| 67 | října listopadu prosince/; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 6 | 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 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
format_date: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 8 | my ($self, $date) = @_; | |||||||||||||||||||||||||||
| 87 | 8 | ▶ | my $output = $self->show_month_name ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | join('. ', $date->day, $MONTH_NAMES[$date->month_0]) : | ||||||||||||||||||||||||||||
| 89 | sprintf '%i. %i.', $date->day, $date->month; | ||||||||||||||||||||||||||||
| 90 | 8 | ▶ | $output = $DAY_NAMES[$date->wday_0] . ' ' . $output if $self->show_day_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 8 | ▶ | $output .= ' ' . $date->year if $self->show_year; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 8 | 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 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
format_time: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 5 | my ($self, $date) = @_; | |||||||||||||||||||||||||||
| 106 | 5 | 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 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
format_datetime: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 12 | my ($self, $date) = @_; | |||||||||||||||||||||||||||
| 124 | 12 | ▶ | if ($self->show_time && $self->show_date) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->show_time and $self->show_date
MC/DC100%2/2
$self->show_time and $self->show_date
$self->show_time
$self->show_date
Truth table100%3/3
A and B
A= $self->show_timeB= $self->show_date
| |||||||||||||||||||||||||||||
| 125 | 1 | return sprintf $self->compound_format, | |||||||||||||||||||||||||||
| 126 | $self->format_date($date), $self->format_time($date); | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 11 | ▶ | return $self->format_date($date) if $self->show_date; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 4 | return $self->format_time($date); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | ▶ | sub format { | ||||||||||||||||||||||||||
|
Subroutine
format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 1 | return shift->format_datetime(@_); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Tomáš Znamenáček, zoul@fleuron.cz | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 6 | 'SDG'; | |||||||||||||||||||||||||||