| 1 |
|
| 2 |
package Date::Language; |
| 3 |
|
| 4 |
use strict; |
| 5 |
use Time::Local; |
| 6 |
use Carp; |
| 7 |
|
| 8 |
require Date::Format; |
| 9 |
|
| 10 |
our $VERSION = '2.35'; # VERSION: generated |
| 11 |
# ABSTRACT: Language specific date formatting and parsing |
| 12 |
|
| 13 |
use base qw(Date::Format::Generic); |
| 14 |
|
| 15 |
sub _build_lookups |
| 16 |
{ |
| 17 |
my $pkg = caller; |
| 18 |
no strict 'refs'; |
| 19 |
@{"${pkg}::MoY"}{@{"${pkg}::MoY"}} = (0 .. scalar(@{"${pkg}::MoY"})); |
| 20 |
@{"${pkg}::MoY"}{@{"${pkg}::MoYs"}} = (0 .. scalar(@{"${pkg}::MoYs"})); |
| 21 |
@{"${pkg}::DoW"}{@{"${pkg}::DoW"}} = (0 .. scalar(@{"${pkg}::DoW"})); |
| 22 |
@{"${pkg}::DoW"}{@{"${pkg}::DoWs"}} = (0 .. scalar(@{"${pkg}::DoWs"})); |
| 23 |
} |
| 24 |
|
| 25 |
sub new |
| 26 |
{ |
| 27 |
my $self = shift; |
| 28 |
my $type = shift || $self; |
| 29 |
|
| 30 |
$type =~ s/^(\w+)$/Date::Language::$1/; |
| 31 |
|
| 32 |
croak "Bad language" |
| 33 |
unless $type =~ /^[\w:]+$/; |
| 34 |
|
| 35 |
eval "require $type" |
| 36 |
or croak $@; |
| 37 |
|
| 38 |
bless [], $type; |
| 39 |
} |
| 40 |
|
| 41 |
# Stop AUTOLOAD being called ;-) |
| 42 |
sub DESTROY {} |
| 43 |
|
| 44 |
sub AUTOLOAD |
| 45 |
{ |
| 46 |
our $AUTOLOAD; |
| 47 |
if($AUTOLOAD =~ /::strptime\Z/o) |
| 48 |
{ |
| 49 |
my $self = $_[0]; |
| 50 |
my $type = ref($self) || $self; |
| 51 |
require Date::Parse; |
| 52 |
|
| 53 |
no strict 'refs'; |
| 54 |
*{"${type}::strptime"} = Date::Parse::gen_parser( |
| 55 |
\%{"${type}::DoW"}, |
| 56 |
\%{"${type}::MoY"}, |
| 57 |
\@{"${type}::Dsuf"}, |
| 58 |
1); |
| 59 |
|
| 60 |
goto &{"${type}::strptime"}; |
| 61 |
} |
| 62 |
|
| 63 |
croak "Undefined method &$AUTOLOAD called"; |
| 64 |
} |
| 65 |
|
| 66 |
sub format_Z { |
| 67 |
my $tz = Date::Format::Generic::format_Z(@_); |
| 68 |
my $pkg = ref($_[0]) || 'Date::Language'; |
| 69 |
no strict 'refs'; |
| 70 |
my $tz_map = \%{"${pkg}::TZ"}; |
| 71 |
return exists $tz_map->{$tz} ? $tz_map->{$tz} : $tz; |
| 72 |
} |
| 73 |
|
| 74 |
sub str2time |
| 75 |
{ |
| 76 |
my $me = shift; |
| 77 |
my @t = $me->strptime(@_); |
| 78 |
|
| 79 |
return undef |
| 80 |
unless @t; |
| 81 |
|
| 82 |
my($ss,$mm,$hh,$day,$month,$year,$zone) = @t; |
| 83 |
my @lt = localtime(time); |
| 84 |
|
| 85 |
$hh ||= 0; |
| 86 |
$mm ||= 0; |
| 87 |
$ss ||= 0; |
| 88 |
|
| 89 |
$month = $lt[4] |
| 90 |
unless(defined $month); |
| 91 |
|
| 92 |
$day = $lt[3] |
| 93 |
unless(defined $day); |
| 94 |
|
| 95 |
$year = ($month > $lt[4]) ? ($lt[5] - 1) : $lt[5] |
| 96 |
unless(defined $year); |
| 97 |
|
| 98 |
return defined $zone ? timegm($ss,$mm,$hh,$day,$month,$year) - $zone |
| 99 |
: timelocal($ss,$mm,$hh,$day,$month,$year); |
| 100 |
} |
| 101 |
|
| 102 |
1; |
| 103 |
|
| 104 |
__END__ |
| 105 |
|
| 106 |
=pod |
| 107 |
|
| 108 |
=encoding UTF-8 |
| 109 |
|
| 110 |
=head1 NAME |
| 111 |
|
| 112 |
Date::Language - Language specific date formatting and parsing |
| 113 |
|
| 114 |
=head1 VERSION |
| 115 |
|
| 116 |
version 2.35 |
| 117 |
|
| 118 |
=head1 SYNOPSIS |
| 119 |
|
| 120 |
use Date::Language; |
| 121 |
|
| 122 |
my $lang = Date::Language->new('German'); |
| 123 |
$lang->time2str("%a %b %e %T %Y\n", time); |
| 124 |
|
| 125 |
=head1 DESCRIPTION |
| 126 |
|
| 127 |
L<Date::Language> provides objects to parse and format dates for specific languages. Available languages are |
| 128 |
|
| 129 |
Afar French Russian_cp1251 |
| 130 |
Amharic Gedeo Russian_koi8r |
| 131 |
Austrian German Sidama |
| 132 |
Brazilian Greek Somali |
| 133 |
Chinese Hungarian Spanish |
| 134 |
Chinese_GB Icelandic Swedish |
| 135 |
Czech Italian Tigrinya |
| 136 |
Danish Norwegian TigrinyaEritrean |
| 137 |
Dutch Oromo TigrinyaEthiopian |
| 138 |
English Romanian Turkish |
| 139 |
Finnish Russian Bulgarian |
| 140 |
Occitan |
| 141 |
|
| 142 |
=head1 NAME |
| 143 |
|
| 144 |
Date::Language - Language specific date formatting and parsing |
| 145 |
|
| 146 |
=head1 METHODS |
| 147 |
|
| 148 |
=over |
| 149 |
|
| 150 |
=item time2str |
| 151 |
|
| 152 |
See L<Date::Format/time2str> |
| 153 |
|
| 154 |
=item strftime |
| 155 |
|
| 156 |
See L<Date::Format/strftime> |
| 157 |
|
| 158 |
=item ctime |
| 159 |
|
| 160 |
See L<Date::Format/ctime> |
| 161 |
|
| 162 |
=item asctime |
| 163 |
|
| 164 |
See L<Date::Format/asctime> |
| 165 |
|
| 166 |
=item str2time |
| 167 |
|
| 168 |
See L<Date::Parse/str2time> |
| 169 |
|
| 170 |
=item strptime |
| 171 |
|
| 172 |
See L<Date::Parse/strptime> |
| 173 |
|
| 174 |
=back |
| 175 |
|
| 176 |
=head1 AUTHOR |
| 177 |
|
| 178 |
Graham <[email protected]> |
| 179 |
|
| 180 |
=head1 COPYRIGHT AND LICENSE |
| 181 |
|
| 182 |
This software is copyright (c) 2020 by Graham Barr. |
| 183 |
|
| 184 |
This is free software; you can redistribute it and/or modify it under |
| 185 |
the same terms as the Perl 5 programming language system itself. |
| 186 |
|
| 187 |
=cut |