diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-12-27 19:01:41 -0800 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-12-27 19:01:41 -0800 |
commit | 8511956c25f92ccd6094dca45824697ad21cfdd4 (patch) | |
tree | 339c6be9e55fc02eae92912dcde3aec10bb2dbe5 /lib | |
download | perl-TimeDate-8511956c25f92ccd6094dca45824697ad21cfdd4.tar.gz perl-TimeDate-8511956c25f92ccd6094dca45824697ad21cfdd4.tar.bz2 perl-TimeDate-8511956c25f92ccd6094dca45824697ad21cfdd4.zip |
Imported Upstream version 1.20upstream/1.20
Diffstat (limited to 'lib')
36 files changed, 2803 insertions, 0 deletions
diff --git a/lib/Date/Format.pm b/lib/Date/Format.pm new file mode 100644 index 0000000..3a1ea90 --- /dev/null +++ b/lib/Date/Format.pm @@ -0,0 +1,403 @@ +# Copyright (c) 1995-2009 Graham Barr. This program is free +# software; you can redistribute it and/or modify it under the same terms +# as Perl itself. + +package Date::Format; + +use strict; +use vars qw(@EXPORT @ISA $VERSION); +require Exporter; + +$VERSION = "2.24"; +@ISA = qw(Exporter); +@EXPORT = qw(time2str strftime ctime asctime); + +sub time2str ($;$$) +{ + Date::Format::Generic->time2str(@_); +} + +sub strftime ($\@;$) +{ + Date::Format::Generic->strftime(@_); +} + +sub ctime ($;$) +{ + my($t,$tz) = @_; + Date::Format::Generic->time2str("%a %b %e %T %Y\n", $t, $tz); +} + +sub asctime (\@;$) +{ + my($t,$tz) = @_; + Date::Format::Generic->strftime("%a %b %e %T %Y\n", $t, $tz); +} + +## +## +## + +package Date::Format::Generic; + +use vars qw($epoch $tzname); +use Time::Zone; +use Time::Local; + +sub ctime +{ + my($me,$t,$tz) = @_; + $me->time2str("%a %b %e %T %Y\n", $t, $tz); +} + +sub asctime +{ + my($me,$t,$tz) = @_; + $me->strftime("%a %b %e %T %Y\n", $t, $tz); +} + +sub _subs +{ + my $fn; + $_[1] =~ s/ + %(O?[%a-zA-Z]) + / + ($_[0]->can("format_$1") || sub { $1 })->($_[0]); + /sgeox; + + $_[1]; +} + +sub strftime +{ + my($pkg,$fmt,$time); + + ($pkg,$fmt,$time,$tzname) = @_; + + my $me = ref($pkg) ? $pkg : bless []; + + if(defined $tzname) + { + $tzname = uc $tzname; + + $tzname = sprintf("%+05d",$tzname) + unless($tzname =~ /\D/); + + $epoch = timegm(@{$time}[0..5]); + + @$me = gmtime($epoch + tz_offset($tzname) - tz_offset()); + } + else + { + @$me = @$time; + undef $epoch; + } + + _subs($me,$fmt); +} + +sub time2str +{ + my($pkg,$fmt,$time); + + ($pkg,$fmt,$time,$tzname) = @_; + + my $me = ref($pkg) ? $pkg : bless [], $pkg; + + $epoch = $time; + + if(defined $tzname) + { + $tzname = uc $tzname; + + $tzname = sprintf("%+05d",$tzname) + unless($tzname =~ /\D/); + + $time += tz_offset($tzname); + @$me = gmtime($time); + } + else + { + @$me = localtime($time); + } + $me->[9] = $time; + _subs($me,$fmt); +} + +my(@DoW,@MoY,@DoWs,@MoYs,@AMPM,%format,@Dsuf); + +@DoW = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); + +@MoY = qw(January February March April May June + July August September October November December); + +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; + +@AMPM = qw(AM PM); + +@Dsuf = (qw(th st nd rd th th th th th th)) x 3; +@Dsuf[11,12,13] = qw(th th th); +@Dsuf[30,31] = qw(th st); + +%format = ('x' => "%m/%d/%y", + 'C' => "%a %b %e %T %Z %Y", + 'X' => "%H:%M:%S", + ); + +my @locale; +my $locale = "/usr/share/lib/locale/LC_TIME/default"; +local *LOCALE; + +if(open(LOCALE,"$locale")) + { + chop(@locale = <LOCALE>); + close(LOCALE); + + @MoYs = @locale[0 .. 11]; + @MoY = @locale[12 .. 23]; + @DoWs = @locale[24 .. 30]; + @DoW = @locale[31 .. 37]; + @format{"X","x","C"} = @locale[38 .. 40]; + @AMPM = @locale[41 .. 42]; + } + +sub wkyr { + my($wstart, $wday, $yday) = @_; + $wday = ($wday + 7 - $wstart) % 7; + return int(($yday - $wday + 13) / 7 - 1); +} + +## +## these 6 formatting routins need to be *copied* into the language +## specific packages +## + +my @roman = ('',qw(I II III IV V VI VII VIII IX)); +sub roman { + my $n = shift; + + $n =~ s/(\d)$//; + my $r = $roman[ $1 ]; + + if($n =~ s/(\d)$//) { + (my $t = $roman[$1]) =~ tr/IVX/XLC/; + $r = $t . $r; + } + if($n =~ s/(\d)$//) { + (my $t = $roman[$1]) =~ tr/IVX/CDM/; + $r = $t . $r; + } + if($n =~ s/(\d)$//) { + (my $t = $roman[$1]) =~ tr/IVX/M../; + $r = $t . $r; + } + $r; +} + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_P { lc($_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0]) } + +sub format_d { sprintf("%02d",$_[0]->[3]) } +sub format_e { sprintf("%2d",$_[0]->[3]) } +sub format_H { sprintf("%02d",$_[0]->[2]) } +sub format_I { sprintf("%02d",$_[0]->[2] % 12 || 12)} +sub format_j { sprintf("%03d",$_[0]->[7] + 1) } +sub format_k { sprintf("%2d",$_[0]->[2]) } +sub format_l { sprintf("%2d",$_[0]->[2] % 12 || 12)} +sub format_L { $_[0]->[4] + 1 } +sub format_m { sprintf("%02d",$_[0]->[4] + 1) } +sub format_M { sprintf("%02d",$_[0]->[1]) } +sub format_q { sprintf("%01d",int($_[0]->[4] / 3) + 1) } +sub format_s { + $epoch = timelocal(@{$_[0]}[0..5]) + unless defined $epoch; + sprintf("%d",$epoch) +} +sub format_S { sprintf("%02d",$_[0]->[0]) } +sub format_U { wkyr(0, $_[0]->[6], $_[0]->[7]) } +sub format_w { $_[0]->[6] } +sub format_W { wkyr(1, $_[0]->[6], $_[0]->[7]) } +sub format_y { sprintf("%02d",$_[0]->[5] % 100) } +sub format_Y { sprintf("%04d",$_[0]->[5] + 1900) } + +sub format_Z { + my $o = tz_local_offset(timelocal(@{$_[0]}[0..5])); + defined $tzname ? $tzname : uc tz_name($o, $_[0]->[8]); +} + +sub format_z { + my $t = timelocal(@{$_[0]}[0..5]); + my $o = defined $tzname ? tz_offset($tzname, $t) : tz_offset(undef,$t); + sprintf("%+03d%02d", int($o / 3600), int(abs($o) % 3600) / 60); +} + +sub format_c { &format_x . " " . &format_X } +sub format_D { &format_m . "/" . &format_d . "/" . &format_y } +sub format_r { &format_I . ":" . &format_M . ":" . &format_S . " " . &format_p } +sub format_R { &format_H . ":" . &format_M } +sub format_T { &format_H . ":" . &format_M . ":" . &format_S } +sub format_t { "\t" } +sub format_n { "\n" } +sub format_o { sprintf("%2d%s",$_[0]->[3],$Dsuf[$_[0]->[3]]) } +sub format_x { my $f = $format{'x'}; _subs($_[0],$f); } +sub format_X { my $f = $format{'X'}; _subs($_[0],$f); } +sub format_C { my $f = $format{'C'}; _subs($_[0],$f); } + +sub format_Od { roman(format_d(@_)) } +sub format_Oe { roman(format_e(@_)) } +sub format_OH { roman(format_H(@_)) } +sub format_OI { roman(format_I(@_)) } +sub format_Oj { roman(format_j(@_)) } +sub format_Ok { roman(format_k(@_)) } +sub format_Ol { roman(format_l(@_)) } +sub format_Om { roman(format_m(@_)) } +sub format_OM { roman(format_M(@_)) } +sub format_Oq { roman(format_q(@_)) } +sub format_Oy { roman(format_y(@_)) } +sub format_OY { roman(format_Y(@_)) } + +sub format_G { int(($_[0]->[9] - 315993600) / 604800) } + +1; +__END__ + +=head1 NAME + +Date::Format - Date formating subroutines + +=head1 SYNOPSIS + + use Date::Format; + + @lt = localtime(time); + + print time2str($template, time); + print strftime($template, @lt); + + print time2str($template, time, $zone); + print strftime($template, @lt, $zone); + + print ctime(time); + print asctime(@lt); + + print ctime(time, $zone); + print asctime(@lt, $zone); + +=head1 DESCRIPTION + +This module provides routines to format dates into ASCII strings. They +correspond to the C library routines C<strftime> and C<ctime>. + +=over 4 + +=item time2str(TEMPLATE, TIME [, ZONE]) + +C<time2str> converts C<TIME> into an ASCII string using the conversion +specification given in C<TEMPLATE>. C<ZONE> if given specifies the zone +which the output is required to be in, C<ZONE> defaults to your current zone. + + +=item strftime(TEMPLATE, TIME [, ZONE]) + +C<strftime> is similar to C<time2str> with the exception that the time is +passed as an array, such as the array returned by C<localtime>. + +=item ctime(TIME [, ZONE]) + +C<ctime> calls C<time2str> with the given arguments using the +conversion specification C<"%a %b %e %T %Y\n"> + +=item asctime(TIME [, ZONE]) + +C<asctime> calls C<time2str> with the given arguments using the +conversion specification C<"%a %b %e %T %Y\n"> + +=back + +=head1 MULTI-LANGUAGE SUPPORT + +Date::Format is capable of formating into several languages by creating +a language specific object and calling methods, see L<Date::Language> + + my $lang = Date::Language->new('German'); + $lang->time2str("%a %b %e %T %Y\n", time); + +I am open to suggestions on this. + +=head1 CONVERSION SPECIFICATION + +Each conversion specification is replaced by appropriate +characters as described in the following list. The +appropriate characters are determined by the LC_TIME +category of the program's locale. + + %% PERCENT + %a day of the week abbr + %A day of the week + %b month abbr + %B month + %c MM/DD/YY HH:MM:SS + %C ctime format: Sat Nov 19 21:05:57 1994 + %d numeric day of the month, with leading zeros (eg 01..31) + %e like %d, but a leading zero is replaced by a space (eg 1..32) + %D MM/DD/YY + %G GPS week number (weeks since January 6, 1980) + %h month abbr + %H hour, 24 hour clock, leading 0's) + %I hour, 12 hour clock, leading 0's) + %j day of the year + %k hour + %l hour, 12 hour clock + %L month number, starting with 1 + %m month number, starting with 01 + %M minute, leading 0's + %n NEWLINE + %o ornate day of month -- "1st", "2nd", "25th", etc. + %p AM or PM + %P am or pm (Yes %p and %P are backwards :) + %q Quarter number, starting with 1 + %r time format: 09:05:57 PM + %R time format: 21:05 + %s seconds since the Epoch, UCT + %S seconds, leading 0's + %t TAB + %T time format: 21:05:57 + %U week number, Sunday as first day of week + %w day of the week, numerically, Sunday == 0 + %W week number, Monday as first day of week + %x date format: 11/19/94 + %X time format: 21:05:57 + %y year (2 digits) + %Y year (4 digits) + %Z timezone in ascii. eg: PST + %z timezone in format -/+0000 + +C<%d>, C<%e>, C<%H>, C<%I>, C<%j>, C<%k>, C<%l>, C<%m>, C<%M>, C<%q>, +C<%y> and C<%Y> can be output in Roman numerals by prefixing the letter +with C<O>, e.g. C<%OY> will output the year as roman numerals. + +=head1 LIMITATION + +The functions in this module are limited to the time range that can be +represented by the time_t data type, i.e. 1901-12-13 20:45:53 GMT to +2038-01-19 03:14:07 GMT. + +=head1 AUTHOR + +Graham Barr <gbarr@pobox.com> + +=head1 COPYRIGHT + +Copyright (c) 1995-2009 Graham Barr. This program is free +software; you can redistribute it and/or modify it under the same terms +as Perl itself. + +=cut + + diff --git a/lib/Date/Language.pm b/lib/Date/Language.pm new file mode 100644 index 0000000..229a1c0 --- /dev/null +++ b/lib/Date/Language.pm @@ -0,0 +1,144 @@ + +package Date::Language; + +use strict; +use Time::Local; +use Carp; +use vars qw($VERSION @ISA); +require Date::Format; + +$VERSION = "1.10"; +@ISA = qw(Date::Format::Generic); + +sub new +{ + my $self = shift; + my $type = shift || $self; + + $type =~ s/^(\w+)$/Date::Language::$1/; + + croak "Bad language" + unless $type =~ /^[\w:]+$/; + + eval "require $type" + or croak $@; + + bless [], $type; +} + +# Stop AUTOLOAD being called ;-) +sub DESTROY {} + +sub AUTOLOAD +{ + use vars qw($AUTOLOAD); + + if($AUTOLOAD =~ /::strptime\Z/o) + { + my $self = $_[0]; + my $type = ref($self) || $self; + require Date::Parse; + + no strict 'refs'; + *{"${type}::strptime"} = Date::Parse::gen_parser( + \%{"${type}::DoW"}, + \%{"${type}::MoY"}, + \@{"${type}::Dsuf"}, + 1); + + goto &{"${type}::strptime"}; + } + + croak "Undefined method &$AUTOLOAD called"; +} + +sub str2time +{ + my $me = shift; + my @t = $me->strptime(@_); + + return undef + unless @t; + + my($ss,$mm,$hh,$day,$month,$year,$zone) = @t; + my @lt = localtime(time); + + $hh ||= 0; + $mm ||= 0; + $ss ||= 0; + + $month = $lt[4] + unless(defined $month); + + $day = $lt[3] + unless(defined $day); + + $year = ($month > $lt[4]) ? ($lt[5] - 1) : $lt[5] + unless(defined $year); + + return defined $zone ? timegm($ss,$mm,$hh,$day,$month,$year) - $zone + : timelocal($ss,$mm,$hh,$day,$month,$year); +} + +1; + +__END__ + + +=head1 NAME + +Date::Language - Language specific date formating and parsing + +=head1 SYNOPSIS + + use Date::Language; + + my $lang = Date::Language->new('German'); + $lang->time2str("%a %b %e %T %Y\n", time); + +=head1 DESCRIPTION + +L<Date::Language> provides objects to parse and format dates for specific languages. Available languages are + + Afar French Russian_cp1251 + Amharic Gedeo Russian_koi8r + Austrian German Sidama + Brazilian Greek Somali + Chinese Hungarian Spanish + Chinese_GB Icelandic Swedish + Czech Italian Tigrinya + Danish Norwegian TigrinyaEritrean + Dutch Oromo TigrinyaEthiopian + English Romanian Turkish + Finnish Russian + +=head1 METHODS + +=over + +=item time2str + +See L<Date::Format/time2str> + +=item strftime + +See L<Date::Format/strftime> + +=item ctime + +See L<Date::Format/ctime> + +=item asctime + +See L<Date::Format/asctime> + +=item str2time + +See L<Date::Parse/str2time> + +=item strptime + +See L<Date::Parse/strptime> + +=back + diff --git a/lib/Date/Language/Afar.pm b/lib/Date/Language/Afar.pm new file mode 100644 index 0000000..f67cf37 --- /dev/null +++ b/lib/Date/Language/Afar.pm @@ -0,0 +1,49 @@ +## +## Afar tables +## + +package Date::Language::Afar; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "0.99"; + +@DoW = qw(Acaada Etleeni Talaata Arbaqa Kamiisi Gumqata Sabti); +@MoY = ( +"Qunxa Garablu", +"Kudo", +"Ciggilta Kudo", +"Agda Baxis", +"Caxah Alsa", +"Qasa Dirri", +"Qado Dirri", +"Liiqen", +"Waysu", +"Diteli", +"Ximoli", +"Kaxxa Garablu" +); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(saaku carra); + +@Dsuf = (qw(th st nd rd th th th th th th)) x 3; +@Dsuf[11,12,13] = qw(th th th); +@Dsuf[30,31] = qw(th st); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Amharic.pm b/lib/Date/Language/Amharic.pm new file mode 100644 index 0000000..a79984e --- /dev/null +++ b/lib/Date/Language/Amharic.pm @@ -0,0 +1,87 @@ +## +## Amharic tables +## + +package Date::Language::Amharic; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.00"; + +if ( $] >= 5.006 ) { +@DoW = ( +"\x{12a5}\x{1211}\x{12f5}", +"\x{1230}\x{129e}", +"\x{121b}\x{12ad}\x{1230}\x{129e}", +"\x{1228}\x{1261}\x{12d5}", +"\x{1210}\x{1219}\x{1235}", +"\x{12d3}\x{122d}\x{1265}", +"\x{1245}\x{12f3}\x{121c}" +); +@MoY = ( +"\x{1303}\x{1295}\x{12e9}\x{12c8}\x{122a}", +"\x{134c}\x{1265}\x{1229}\x{12c8}\x{122a}", +"\x{121b}\x{122d}\x{127d}", +"\x{12a4}\x{1355}\x{1228}\x{120d}", +"\x{121c}\x{12ed}", +"\x{1301}\x{1295}", +"\x{1301}\x{120b}\x{12ed}", +"\x{12a6}\x{1308}\x{1235}\x{1275}", +"\x{1234}\x{1355}\x{1274}\x{121d}\x{1260}\x{122d}", +"\x{12a6}\x{12ad}\x{1270}\x{12cd}\x{1260}\x{122d}", +"\x{1296}\x{126c}\x{121d}\x{1260}\x{122d}", +"\x{12f2}\x{1234}\x{121d}\x{1260}\x{122d}" +); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = ( "\x{1320}\x{12cb}\x{1275}", "\x{12a8}\x{1230}\x{12d3}\x{1275}" ); + +@Dsuf = ("\x{129b}" x 31); +} +else { +@DoW = ( +"እሑድ", +"ሰኞ", +"ማክሰኞ", +"ረቡዕ", +"ሐሙስ", +"ዓርብ", +"ቅዳሜ" +); +@MoY = ( +"ጃንዩወሪ", +"ፌብሩወሪ", +"ማርች", +"ኤፕረል", +"ሜይ", +"ጁን", +"ጁላይ", +"ኦገስት", +"ሴፕቴምበር", +"ኦክተውበር", +"ኖቬምበር", +"ዲሴምበር" +); +@DoWs = map { substr($_,0,9) } @DoW; +@MoYs = map { substr($_,0,9) } @MoY; +@AMPM = ( "ጠዋት", "ከሰዓት" ); + +@Dsuf = ("ኛ" x 31); +} + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Austrian.pm b/lib/Date/Language/Austrian.pm new file mode 100644 index 0000000..8ff398b --- /dev/null +++ b/lib/Date/Language/Austrian.pm @@ -0,0 +1,36 @@ +## +## Austrian tables +## + +package Date::Language::Austrian; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@MoY = qw(Jnner Feber Mrz April Mai Juni + Juli August September Oktober November Dezember); +@MoYs = qw(Jn Feb Mr Apr Mai Jun Jul Aug Sep Oct Nov Dez); +@DoW = qw(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag); +@DoWs = qw(Son Mon Die Mit Don Fre Sam); + +use Date::Language::English (); +@AMPM = @{Date::Language::English::AMPM}; +@Dsuf = @{Date::Language::English::Dsuf}; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Brazilian.pm b/lib/Date/Language/Brazilian.pm new file mode 100644 index 0000000..fa4d15f --- /dev/null +++ b/lib/Date/Language/Brazilian.pm @@ -0,0 +1,35 @@ +## +## Brazilian tables, contributed by Christian Tosta (tosta@cce.ufmg.br) +## + +package Date::Language::Brazilian; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@DoW = qw(Domingo Segunda Tera Quarta Quinta Sexta Sbado); +@MoY = qw(Janeiro Fevereiro Maro Abril Maio Junho + Julho Agosto Setembro Outubro Novembro Dezembro); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(AM PM); + +@Dsuf = (qw(mo ro do ro to to to mo vo no)) x 3; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Chinese.pm b/lib/Date/Language/Chinese.pm new file mode 100644 index 0000000..abfb3c0 --- /dev/null +++ b/lib/Date/Language/Chinese.pm @@ -0,0 +1,36 @@ +## +## English tables +## + +package Date::Language::Chinese; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.00"; + +@DoW = qw(星期日 星期一 星期二 星期三 星期四 星期五 星期六); +@MoY = qw(一月 二月 三月 四月 五月 六月 + 七月 八月 九月 十月 十一月 十二月); +@DoWs = map { $_ } @DoW; +@MoYs = map { $_ } @MoY; +@AMPM = qw(上午 下午); + +@Dsuf = (qw(日 日 日 日 日 日 日 日 日 日)) x 3; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +sub format_o { sprintf("%2d%s",$_[0]->[3],"日") } +1; diff --git a/lib/Date/Language/Chinese_GB.pm b/lib/Date/Language/Chinese_GB.pm new file mode 100644 index 0000000..7be0555 --- /dev/null +++ b/lib/Date/Language/Chinese_GB.pm @@ -0,0 +1,36 @@ +## +## English tables +## + +package Date::Language::Chinese_GB; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@DoW = qw( һ ڶ ); +@MoY = qw(һ + ʮ ʮһ ʮ); +@DoWs = map { $_ } @DoW; +@MoYs = map { $_ } @MoY; +@AMPM = qw( ); + +@Dsuf = (qw( )) x 3; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +sub format_o { sprintf("%2d%s",$_[0]->[3],"") } +1; diff --git a/lib/Date/Language/Czech.pm b/lib/Date/Language/Czech.pm new file mode 100644 index 0000000..756f5c5 --- /dev/null +++ b/lib/Date/Language/Czech.pm @@ -0,0 +1,58 @@ +## +## Czech tables +## +## Contributed by Honza Pazdziora + +package Date::Language::Czech; + +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @MoY2 @AMPM %MoY %DoW $VERSION); +@ISA = qw(Date::Language Date::Format::Generic); +$VERSION = "1.01"; + +@MoY = qw(leden nor bezen duben kvten erven ervenec srpen z + jen listopad prosinec); +@MoYs = qw(led nor be dub kv vn ec srp z j lis pro); +@MoY2 = @MoY; +for (@MoY2) + { s!en$!na! or s!ec$!ce! or s!ad$!adu! or s!or$!ora!; } + +@DoW = qw(nedle pondl ter steda tvrtek ptek sobota); +@DoWs = qw(Ne Po t St t P So); + +@AMPM = qw(dop. odp.); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +sub format_d { $_[0]->[3] } +sub format_m { $_[0]->[4] + 1 } +sub format_o { $_[0]->[3] . '.' } + +sub format_Q { $MoY2[$_[0]->[4]] } + +sub time2str { + my $ref = shift; + my @a = @_; + $a[0] =~ s/(%[do]\.?\s?)%B/$1%Q/; + $ref->SUPER::time2str(@a); + } + +sub strftime { + my $ref = shift; + my @a = @_; + $a[0] =~ s/(%[do]\.?\s?)%B/$1%Q/; + $ref->SUPER::time2str(@a); + } + +1; diff --git a/lib/Date/Language/Danish.pm b/lib/Date/Language/Danish.pm new file mode 100644 index 0000000..c43d085 --- /dev/null +++ b/lib/Date/Language/Danish.pm @@ -0,0 +1,36 @@ +##
+## Danish tables
+##
+
+package Date::Language::Danish;
+
+use Date::Language ();
+use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION);
+@ISA = qw(Date::Language);
+$VERSION = "1.01";
+
+@MoY = qw(Januar Februar Marts April Maj Juni
+ Juli August September Oktober November December);
+@MoYs = qw(Jan Feb Mar Apr Maj Jun Jul Aug Sep Okt Nov Dec);
+@DoW = qw(Sndag Mandag Tirsdag Onsdag Torsdag Fredag Lrdag Sndag);
+@DoWs = qw(Sn Man Tir Ons Tor Fre Lr Sn);
+
+use Date::Language::English ();
+@AMPM = @{Date::Language::English::AMPM};
+@Dsuf = @{Date::Language::English::Dsuf};
+
+@MoY{@MoY} = (0 .. scalar(@MoY));
+@MoY{@MoYs} = (0 .. scalar(@MoYs));
+@DoW{@DoW} = (0 .. scalar(@DoW));
+@DoW{@DoWs} = (0 .. scalar(@DoWs));
+
+# Formatting routines
+
+sub format_a { $DoWs[$_[0]->[6]] }
+sub format_A { $DoW[$_[0]->[6]] }
+sub format_b { $MoYs[$_[0]->[4]] }
+sub format_B { $MoY[$_[0]->[4]] }
+sub format_h { $MoYs[$_[0]->[4]] }
+sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] }
+
+1;
diff --git a/lib/Date/Language/Dutch.pm b/lib/Date/Language/Dutch.pm new file mode 100644 index 0000000..219758b --- /dev/null +++ b/lib/Date/Language/Dutch.pm @@ -0,0 +1,40 @@ +## +## Dutch tables +## Contributed by Johannes la Poutre <jlpoutre@corp.nl.home.com> +## + +package Date::Language::Dutch; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.02"; + +@MoY = qw(januari februari maart april mei juni juli + augustus september oktober november december); +@MoYs = map(substr($_, 0, 3), @MoY); +$MoYs[2] = 'mrt'; # mrt is more common (Frank Maas) +@DoW = map($_ . "dag", qw(zon maan dins woens donder vrij zater)); +@DoWs = map(substr($_, 0, 2), @DoW); + +# these aren't normally used... +@AMPM = qw(VM NM); +@Dsuf = ('e') x 31; + + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_o { sprintf("%2de",$_[0]->[3]) } + +1; diff --git a/lib/Date/Language/English.pm b/lib/Date/Language/English.pm new file mode 100644 index 0000000..638cb3c --- /dev/null +++ b/lib/Date/Language/English.pm @@ -0,0 +1,37 @@ +## +## English tables +## + +package Date::Language::English; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@DoW = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); +@MoY = qw(January February March April May June + July August September October November December); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(AM PM); + +@Dsuf = (qw(th st nd rd th th th th th th)) x 3; +@Dsuf[11,12,13] = qw(th th th); +@Dsuf[30,31] = qw(th st); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Finnish.pm b/lib/Date/Language/Finnish.pm new file mode 100644 index 0000000..415b50c --- /dev/null +++ b/lib/Date/Language/Finnish.pm @@ -0,0 +1,45 @@ +## +## Finnish tables +## Contributed by Matthew Musgrove <muskrat@mindless.com> +## Corrected by roke +## + +package Date::Language::Finnish; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +# In Finnish, the names of the months and days are only capitalized at the beginning of sentences. +@MoY = map($_ . "kuu", qw(tammi helmi maalis huhti touko kes hein elo syys loka marras joulu)); +@DoW = qw(sunnuntai maanantai tiistai keskiviikko torstai perjantai lauantai); + +# it is not customary to use abbreviated names of months or days +# per Graham's suggestion: +@MoYs = @MoY; +@DoWs = @DoW; + +# the short form of ordinals +@Dsuf = ('.') x 31; + +# doesn't look like this is normally used... +@AMPM = qw(ap ip); + + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_o { sprintf("%2de",$_[0]->[3]) } + +1;
\ No newline at end of file diff --git a/lib/Date/Language/French.pm b/lib/Date/Language/French.pm new file mode 100644 index 0000000..91b414c --- /dev/null +++ b/lib/Date/Language/French.pm @@ -0,0 +1,36 @@ +## +## French tables, contributed by Emmanuel Bataille (bem@residents.frmug.org) +## + +package Date::Language::French; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.04"; + +@DoW = qw(dimanche lundi mardi mercredi jeudi vendredi samedi); +@MoY = qw(janvier fvrier mars avril mai juin + juillet aot septembre octobre novembre dcembre); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +$MoYs[6] = 'jul'; +@AMPM = qw(AM PM); + +@Dsuf = ((qw(er e e e e e e e e e)) x 3, 'er'); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Gedeo.pm b/lib/Date/Language/Gedeo.pm new file mode 100644 index 0000000..c18ad8c --- /dev/null +++ b/lib/Date/Language/Gedeo.pm @@ -0,0 +1,51 @@ +## +## Gedeo tables +## + +package Date::Language::Gedeo; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "0.99"; + +@DoW = qw( Sanbbattaa Sanno Masano Roobe Hamusse Arbe Qiddamme); +@MoY = ( +"Oritto", +"Birre'a", +"Onkkollessa", +"Saddasa", +"Arrasa", +"Qammo", +"Ella", +"Waacibajje", +"Canissa", +"Addolessa", +"Bittitotessa", +"Hegeya" +); +@DoWs = map { substr($_,0,3) } @DoW; +$DoWs[0] = "Snb"; +$DoWs[1] = "Sno"; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(gorsa warreti-udumma); + +@Dsuf = (qw(th st nd rd th th th th th th)) x 3; +@Dsuf[11,12,13] = qw(th th th); +@Dsuf[30,31] = qw(th st); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/German.pm b/lib/Date/Language/German.pm new file mode 100644 index 0000000..11242c4 --- /dev/null +++ b/lib/Date/Language/German.pm @@ -0,0 +1,37 @@ +## +## German tables +## + +package Date::Language::German; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.02"; + +@MoY = qw(Januar Februar Mrz April Mai Juni + Juli August September Oktober November Dezember); +@MoYs = qw(Jan Feb Mr Apr Mai Jun Jul Aug Sep Okt Nov Dez); +@DoW = qw(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag); +@DoWs = qw(Son Mon Die Mit Don Fre Sam); + +use Date::Language::English (); +@AMPM = @{Date::Language::English::AMPM}; +@Dsuf = @{Date::Language::English::Dsuf}; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_o { sprintf("%2d.",$_[0]->[3]) } + +1; diff --git a/lib/Date/Language/Greek.pm b/lib/Date/Language/Greek.pm new file mode 100644 index 0000000..00f917c --- /dev/null +++ b/lib/Date/Language/Greek.pm @@ -0,0 +1,91 @@ +## +## Greek tables +## +## Traditional date format is: DoW DD{eta} MoY Year (%A %o %B %Y) +## +## Matthew Musgrove <muskrat@mindless.com> +## Translations gratiously provided by Menelaos Stamatelos <men@kwsn.net> +## This module returns unicode (utf8) encoded characters. You will need to +## take the necessary steps for this to display correctly. +## + +package Date::Language::Greek; + +use utf8; +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.00"; + +@DoW = ( +"\x{039a}\x{03c5}\x{03c1}\x{03b9}\x{03b1}\x{03ba}\x{03ae}", +"\x{0394}\x{03b5}\x{03c5}\x{03c4}\x{03ad}\x{03c1}\x{03b1}", +"\x{03a4}\x{03c1}\x{03af}\x{03c4}\x{03b7}", +"\x{03a4}\x{03b5}\x{03c4}\x{03ac}\x{03c1}\x{03c4}\x{03b7}", +"\x{03a0}\x{03ad}\x{03bc}\x{03c0}\x{03c4}\x{03b7}", +"\x{03a0}\x{03b1}\x{03c1}\x{03b1}\x{03c3}\x{03ba}\x{03b5}\x{03c5}\x{03ae}", +"\x{03a3}\x{03ac}\x{03b2}\x{03b2}\x{03b1}\x{03c4}\x{03bf}", +); + +@MoY = ( +"\x{0399}\x{03b1}\x{03bd}\x{03bf}\x{03c5}\x{03b1}\x{03c1}\x{03af}\x{03bf}\x{03c5}", +"\x{03a6}\x{03b5}\x{03b2}\x{03c1}\x{03bf}\x{03c5}\x{03b1}\x{03c1}\x{03af}\x{03bf}\x{03c5}", +"\x{039c}\x{03b1}\x{03c1}\x{03c4}\x{03af}\x{03bf}\x{03c5}", +"\x{0391}\x{03c0}\x{03c1}\x{03b9}\x{03bb}\x{03af}\x{03c5}", +"\x{039c}\x{03b1}\x{0390}\x{03bf}\x{03c5}", +"\x{0399}\x{03bf}\x{03c5}\x{03bd}\x{03af}\x{03bf}\x{03c5}", +"\x{0399}\x{03bf}\x{03c5}\x{03bb}\x{03af}\x{03bf}\x{03c5}", +"\x{0391}\x{03c5}\x{03b3}\x{03bf}\x{03cd}\x{03c3}\x{03c4}\x{03bf}\x{03c5}", +"\x{03a3}\x{03b5}\x{03c0}\x{03c4}\x{03b5}\x{03bc}\x{03c4}\x{03bf}\x{03c5}", +"\x{039f}\x{03ba}\x{03c4}\x{03c9}\x{03b2}\x{03c1}\x{03af}\x{03bf}\x{03c5}", +"\x{039d}\x{03bf}\x{03b5}\x{03bc}\x{03b2}\x{03c1}\x{03af}\x{03bf}\x{03c5}", +"\x{0394}\x{03b5}\x{03ba}\x{03b5}\x{03bc}\x{03b2}\x{03c1}\x{03bf}\x{03c5}", +); + +@DoWs = ( +"\x{039a}\x{03c5}", +"\x{0394}\x{03b5}", +"\x{03a4}\x{03c1}", +"\x{03a4}\x{03b5}", +"\x{03a0}\x{03b5}", +"\x{03a0}\x{03b1}", +"\x{03a3}\x{03b1}", +); +@MoYs = ( +"\x{0399}\x{03b1}\x{03bd}", +"\x{03a6}\x{03b5}", +"\x{039c}\x{03b1}\x{03c1}", +"\x{0391}\x{03c0}\x{03c1}", +"\x{039c}\x{03b1}", +"\x{0399}\x{03bf}\x{03c5}\x{03bd}", +"\x{0399}\x{03bf}\x{03c5}\x{03bb}", +"\x{0391}\x{03c5}\x{03b3}", +"\x{03a3}\x{03b5}\x{03c0}", +"\x{039f}\x{03ba}", +"\x{039d}\x{03bf}", +"\x{0394}\x{03b5}", +); + +@AMPM = ("\x{03c0}\x{03bc}", "\x{03bc}\x{03bc}"); + +@Dsuf = ("\x{03b7}" x 31); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_o { sprintf("%2d%s",$_[0]->[3],"\x{03b7}") } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; + + + diff --git a/lib/Date/Language/Hungarian.pm b/lib/Date/Language/Hungarian.pm new file mode 100644 index 0000000..d9c838d --- /dev/null +++ b/lib/Date/Language/Hungarian.pm @@ -0,0 +1,88 @@ +## +## Hungarian tables based on English +## +# +# This is a just-because-I-stumbled-across-it +# -and-my-wife-is-Hungarian release: if Graham or +# someone adds to docs to Date::Format, I'd be +# glad to correct bugs and extend as neeed. +# + +package Date::Language::Hungarian; + +=head1 NAME + +Date::Language::Hungarian - Magyar format for Date::Format + +=head1 SYNOPSIS + + my $lang = Date::Language->new('Hungarian'); + print $lang->time2str("%a %b %e %T %Y", time); + + @lt = localtime(time); + print $lang->time2str($template, time); + print $lang->strftime($template, @lt); + + print $lang->time2str($template, time, $zone); + print $lang->strftime($template, @lt, $zone); + + print $lang->ctime(time); + print $lang->asctime(@lt); + + print $lang->ctime(time, $zone); + print $lang->asctime(@lt, $zone); + +See L<Date::Format>. + +=head1 AUTHOR + +Paula Goddard (paula -at- paulacska -dot- com) + +=head1 LICENCE + +Made available under the same terms as Perl itself. + +=cut + +use strict; +use warnings; +use base "Date::Language"; +use vars qw( @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +$VERSION = "1.01"; + +@DoW = qw(Vasrnap Htf Kedd Szerda Cstrtk Pntek Szombat); +@MoY = qw(Janur Februr Mrcius prilis Mjus Jnius + Jlius Augusztus Szeptember Oktber November December); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(DE. DU.); + +# There is no 'th or 'nd in Hungarian, just a dot +@Dsuf = (".") x 31; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_P { lc($_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0]) } +sub format_o { $_[0]->[3].'.' } + + + +sub format_D { &format_y . "." . &format_m . "." . &format_d } + +sub format_y { sprintf("%02d",$_[0]->[5] % 100) } +sub format_d { sprintf("%02d",$_[0]->[3]) } +sub format_m { sprintf("%02d",$_[0]->[4] + 1) } + + +1; diff --git a/lib/Date/Language/Icelandic.pm b/lib/Date/Language/Icelandic.pm new file mode 100644 index 0000000..5ca3ee3 --- /dev/null +++ b/lib/Date/Language/Icelandic.pm @@ -0,0 +1,36 @@ +## +## Icelandic tables +## + +package Date::Language::Icelandic; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@MoY = qw(Janar Febrar Mars Aprl Ma Jni + Jli gst September Oktber Nvember Desember); +@MoYs = qw(Jan Feb Mar Apr Ma Jn Jl g Sep Okt Nv Des); +@DoW = qw(Sunnudagur Mnudagur rijudagur Mivikudagur Fimmtudagur Fstudagur Laugardagur Sunnudagur); +@DoWs = qw(Sun Mn ri Mi Fim Fs Lau Sun); + +use Date::Language::English (); +@AMPM = @{Date::Language::English::AMPM}; +@Dsuf = @{Date::Language::English::Dsuf}; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Italian.pm b/lib/Date/Language/Italian.pm new file mode 100644 index 0000000..6db0a8e --- /dev/null +++ b/lib/Date/Language/Italian.pm @@ -0,0 +1,36 @@ +## +## Italian tables +## + +package Date::Language::Italian; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@MoY = qw(Gennaio Febbraio Marzo Aprile Maggio Giugno + Luglio Agosto Settembre Ottobre Novembre Dicembre); +@MoYs = qw(Gen Feb Mar Apr Mag Giu Lug Ago Set Ott Nov Dic); +@DoW = qw(Domenica Lunedi Martedi Mercoledi Giovedi Venerdi Sabato); +@DoWs = qw(Dom Lun Mar Mer Gio Ven Sab); + +use Date::Language::English (); +@AMPM = @{Date::Language::English::AMPM}; +@Dsuf = @{Date::Language::English::Dsuf}; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Norwegian.pm b/lib/Date/Language/Norwegian.pm new file mode 100644 index 0000000..bbd997f --- /dev/null +++ b/lib/Date/Language/Norwegian.pm @@ -0,0 +1,36 @@ +## +## Norwegian tables +## + +package Date::Language::Norwegian; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@MoY = qw(Januar Februar Mars April Mai Juni + Juli August September Oktober November Desember); +@MoYs = qw(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Des); +@DoW = qw(Sndag Mandag Tirsdag Onsdag Torsdag Fredag Lrdag Sndag); +@DoWs = qw(Sn Man Tir Ons Tor Fre Lr Sn); + +use Date::Language::English (); +@AMPM = @{Date::Language::English::AMPM}; +@Dsuf = @{Date::Language::English::Dsuf}; + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Oromo.pm b/lib/Date/Language/Oromo.pm new file mode 100644 index 0000000..b6a6230 --- /dev/null +++ b/lib/Date/Language/Oromo.pm @@ -0,0 +1,37 @@ +## +## Oromo tables +## + +package Date::Language::Oromo; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "0.99"; + +@DoW = qw(Dilbata Wiixata Qibxata Roobii Kamiisa Jimaata Sanbata); +@MoY = qw(Amajjii Guraandhala Bitooteessa Elba Caamsa Waxabajjii + Adooleessa Hagayya Fuulbana Onkololeessa Sadaasa Muddee); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(WD WB); + +@Dsuf = (qw(th st nd rd th th th th th th)) x 3; +@Dsuf[11,12,13] = qw(th th th); +@Dsuf[30,31] = qw(th st); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Romanian.pm b/lib/Date/Language/Romanian.pm new file mode 100644 index 0000000..cbd2c8c --- /dev/null +++ b/lib/Date/Language/Romanian.pm @@ -0,0 +1,37 @@ +## +## Italian tables +## + +package Date::Language::Romanian; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@MoY = qw(ianuarie februarie martie aprilie mai iunie + iulie august septembrie octombrie noembrie decembrie); +@DoW = qw(duminica luni marti miercuri joi vineri sambata); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; + +@AMPM = qw(AM PM); + +@Dsuf = ('') x 31; + + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Russian.pm b/lib/Date/Language/Russian.pm new file mode 100644 index 0000000..ca9f414 --- /dev/null +++ b/lib/Date/Language/Russian.pm @@ -0,0 +1,49 @@ +## +## Russian tables +## +## Contributed by Danil Pismenny <dapi@mail.ru> + +package Date::Language::Russian; + +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @MoY2 @AMPM %MoY %DoW $VERSION); +@ISA = qw(Date::Language Date::Format::Generic); +$VERSION = "1.01"; + +@MoY = qw( ); +@MoY2 = qw( ); +@MoYs = qw( ); + +@DoW = qw( ); +@DoWs = qw( ); +@DoWs2 = qw( ); + +@AMPM = qw( ); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +sub format_d { $_[0]->[3] } +sub format_m { $_[0]->[4] + 1 } +sub format_o { $_[0]->[3] . '.' } + +sub format_Q { $MoY2[$_[0]->[4]] } + +sub str2time { + my ($self,$value) = @_; + map {$value=~s/(\s|^)$DoWs2[$_](\s)/$DoWs[$_]$2/ig} (0..6); + $value=~s/(\s+|^)(\s+)/$1$2/; + return $self->SUPER::str2time($value); +} + +1; diff --git a/lib/Date/Language/Russian_cp1251.pm b/lib/Date/Language/Russian_cp1251.pm new file mode 100755 index 0000000..cc28e6e --- /dev/null +++ b/lib/Date/Language/Russian_cp1251.pm @@ -0,0 +1,39 @@ +## +## Russian cp1251 +## + +package Date::Language::Russian_cp1251; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@DoW = qw( ); +@MoY = qw( + ); +@DoWs = qw( ); +#@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(AM PM); + +@Dsuf = ('e') x 31; +#@Dsuf[11,12,13] = qw( ); +#@Dsuf[30,31] = qw( ); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_o { sprintf("%2de",$_[0]->[3]) } + +1; diff --git a/lib/Date/Language/Russian_koi8r.pm b/lib/Date/Language/Russian_koi8r.pm new file mode 100755 index 0000000..53de8d0 --- /dev/null +++ b/lib/Date/Language/Russian_koi8r.pm @@ -0,0 +1,39 @@ +## +## Russian koi8r +## + +package Date::Language::Russian_koi8r; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@DoW = qw( ); +@MoY = qw( + ); +@DoWs = qw( ); +#@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(AM PM); + +@Dsuf = ('e') x 31; +#@Dsuf[11,12,13] = qw( ); +#@Dsuf[30,31] = qw( ); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_o { sprintf("%2de",$_[0]->[3]) } + +1; diff --git a/lib/Date/Language/Sidama.pm b/lib/Date/Language/Sidama.pm new file mode 100644 index 0000000..bc26d7c --- /dev/null +++ b/lib/Date/Language/Sidama.pm @@ -0,0 +1,37 @@ +## +## Sidama tables +## + +package Date::Language::Sidama; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "0.99"; + +@DoW = qw(Sambata Sanyo Maakisanyo Roowe Hamuse Arbe Qidaame); +@MoY = qw(January February March April May June + July August September October November December); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(soodo hawwaro); + +@Dsuf = (qw(th st nd rd th th th th th th)) x 3; +@Dsuf[11,12,13] = qw(th th th); +@Dsuf[30,31] = qw(th st); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Somali.pm b/lib/Date/Language/Somali.pm new file mode 100644 index 0000000..5b24961 --- /dev/null +++ b/lib/Date/Language/Somali.pm @@ -0,0 +1,62 @@ +## +## Somali tables +## + +package Date::Language::Somali; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "0.99"; + +@DoW = qw(Axad Isniin Salaaso Arbaco Khamiis Jimco Sabti); +@MoY = ( +"Bisha Koobaad", +"Bisha Labaad", +"Bisha Saddexaad", +"Bisha Afraad", +"Bisha Shanaad", +"Bisha Lixaad", +"Bisha Todobaad", +"Bisha Sideedaad", +"Bisha Sagaalaad", +"Bisha Tobnaad", +"Bisha Kow iyo Tobnaad", +"Bisha Laba iyo Tobnaad" +); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = ( +"Kob", +"Lab", +"Sad", +"Afr", +"Sha", +"Lix", +"Tod", +"Sid", +"Sag", +"Tob", +"KIT", +"LIT" +); +@AMPM = qw(SN GN); + +@Dsuf = (qw(th st nd rd th th th th th th)) x 3; +@Dsuf[11,12,13] = qw(th th th); +@Dsuf[30,31] = qw(th st); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Spanish.pm b/lib/Date/Language/Spanish.pm new file mode 100644 index 0000000..d464ae7 --- /dev/null +++ b/lib/Date/Language/Spanish.pm @@ -0,0 +1,35 @@ +## +## Spanish tables +## + +package Date::Language::Spanish; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.00"; + +@DoW = qw(domingo lunes martes mircoles jueves viernes sbado); +@MoY = qw(enero febrero marzo abril mayo junio + julio agosto septiembre octubre noviembre diciembre); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = qw(AM PM); + +@Dsuf = ((qw(ro do ro to to to mo vo no mo)) x 3, 'ro'); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Swedish.pm b/lib/Date/Language/Swedish.pm new file mode 100644 index 0000000..8f16594 --- /dev/null +++ b/lib/Date/Language/Swedish.pm @@ -0,0 +1,41 @@ +## +## Swedish tables +## Contributed by Matthew Musgrove <muskrat@mindless.com> +## Corrected by dempa +## + +package Date::Language::Swedish; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.01"; + +@MoY = qw(januari februari mars april maj juni juli augusti september oktober november december); +@MoYs = map { substr($_,0,3) } @MoY; +@DoW = map($_ . "dagen", qw(sn mn tis ons tors fre lr)); +@DoWs = map { substr($_,0,2) } @DoW; + +# the ordinals are not typically used in modern times +@Dsuf = ('a' x 2, 'e' x 29); + +use Date::Language::English (); +@AMPM = @{Date::Language::English::AMPM}; + + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } +sub format_o { sprintf("%2de",$_[0]->[3]) } + +1; diff --git a/lib/Date/Language/Tigrinya.pm b/lib/Date/Language/Tigrinya.pm new file mode 100644 index 0000000..ce4fcb3 --- /dev/null +++ b/lib/Date/Language/Tigrinya.pm @@ -0,0 +1,58 @@ +## +## Tigrinya tables +## + +package Date::Language::Tigrinya; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.00"; + +@DoW = ( +"\x{1230}\x{1295}\x{1260}\x{1275}", +"\x{1230}\x{1291}\x{12ed}", +"\x{1230}\x{1209}\x{1235}", +"\x{1228}\x{1261}\x{12d5}", +"\x{1213}\x{1219}\x{1235}", +"\x{12d3}\x{122d}\x{1262}", +"\x{1240}\x{12f3}\x{121d}" +); +@MoY = ( +"\x{1303}\x{1295}\x{12e9}\x{12c8}\x{122a}", +"\x{134c}\x{1265}\x{1229}\x{12c8}\x{122a}", +"\x{121b}\x{122d}\x{127d}", +"\x{12a4}\x{1355}\x{1228}\x{120d}", +"\x{121c}\x{12ed}", +"\x{1301}\x{1295}", +"\x{1301}\x{120b}\x{12ed}", +"\x{12a6}\x{1308}\x{1235}\x{1275}", +"\x{1234}\x{1355}\x{1274}\x{121d}\x{1260}\x{122d}", +"\x{12a6}\x{12ad}\x{1270}\x{12cd}\x{1260}\x{122d}", +"\x{1296}\x{126c}\x{121d}\x{1260}\x{122d}", +"\x{12f2}\x{1234}\x{121d}\x{1260}\x{122d}" +); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = ( +"\x{1295}/\x{1230}", +"\x{12F5}/\x{1230}" +); + +@Dsuf = ("\x{12ed}" x 31); + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/TigrinyaEritrean.pm b/lib/Date/Language/TigrinyaEritrean.pm new file mode 100644 index 0000000..7ab8d0f --- /dev/null +++ b/lib/Date/Language/TigrinyaEritrean.pm @@ -0,0 +1,93 @@ +## +## Tigrinya-Eritrean tables +## + +package Date::Language::TigrinyaEritrean; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.00"; + +if ( $] >= 5.006 ) { +@DoW = ( +"\x{1230}\x{1295}\x{1260}\x{1275}", +"\x{1230}\x{1291}\x{12ed}", +"\x{1230}\x{1209}\x{1235}", +"\x{1228}\x{1261}\x{12d5}", +"\x{1213}\x{1219}\x{1235}", +"\x{12d3}\x{122d}\x{1262}", +"\x{1240}\x{12f3}\x{121d}" +); +@MoY = ( +"\x{1303}\x{1295}\x{12e9}\x{12c8}\x{122a}", +"\x{134c}\x{1265}\x{1229}\x{12c8}\x{122a}", +"\x{121b}\x{122d}\x{127d}", +"\x{12a4}\x{1355}\x{1228}\x{120d}", +"\x{121c}\x{12ed}", +"\x{1301}\x{1295}", +"\x{1301}\x{120b}\x{12ed}", +"\x{12a6}\x{1308}\x{1235}\x{1275}", +"\x{1234}\x{1355}\x{1274}\x{121d}\x{1260}\x{122d}", +"\x{12a6}\x{12ad}\x{1270}\x{12cd}\x{1260}\x{122d}", +"\x{1296}\x{126c}\x{121d}\x{1260}\x{122d}", +"\x{12f2}\x{1234}\x{121d}\x{1260}\x{122d}" +); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = ( +"\x{1295}/\x{1230}", +"\x{12F5}/\x{1230}" +); + +@Dsuf = ("\x{12ed}" x 31); +} +else { +@DoW = ( +"ሰንበት", +"ሰኑይ", +"ሰሉስ", +"ረቡዕ", +"ሓሙስ", +"ዓርቢ", +"ቀዳም" +); +@MoY = ( +"ጥሪ", +"ለካቲት", +"መጋቢት", +"ሚያዝያ", +"ግንቦት", +"ሰነ", +"ሓምለ", +"ነሓሰ", +"መስከረም", +"ጥቅምቲ", +"ሕዳር", +"ታሕሳስ" +); +@DoWs = map { substr($_,0,9) } @DoW; +@MoYs = map { substr($_,0,9) } @MoY; +@AMPM = ( +"ን/ሰ", +"ድ/ሰ" +); + +@Dsuf = ("ይ" x 31); +} + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/TigrinyaEthiopian.pm b/lib/Date/Language/TigrinyaEthiopian.pm new file mode 100644 index 0000000..84fb723 --- /dev/null +++ b/lib/Date/Language/TigrinyaEthiopian.pm @@ -0,0 +1,93 @@ +## +## Tigrinya-Ethiopian tables +## + +package Date::Language::TigrinyaEthiopian; + +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION); +@ISA = qw(Date::Language); +$VERSION = "1.00"; + +if ( $] >= 5.006 ) { +@DoW = ( +"\x{1230}\x{1295}\x{1260}\x{1275}", +"\x{1230}\x{1291}\x{12ed}", +"\x{1230}\x{1209}\x{1235}", +"\x{1228}\x{1261}\x{12d5}", +"\x{1213}\x{1219}\x{1235}", +"\x{12d3}\x{122d}\x{1262}", +"\x{1240}\x{12f3}\x{121d}" +); +@MoY = ( +"\x{1303}\x{1295}\x{12e9}\x{12c8}\x{122a}", +"\x{134c}\x{1265}\x{1229}\x{12c8}\x{122a}", +"\x{121b}\x{122d}\x{127d}", +"\x{12a4}\x{1355}\x{1228}\x{120d}", +"\x{121c}\x{12ed}", +"\x{1301}\x{1295}", +"\x{1301}\x{120b}\x{12ed}", +"\x{12a6}\x{1308}\x{1235}\x{1275}", +"\x{1234}\x{1355}\x{1274}\x{121d}\x{1260}\x{122d}", +"\x{12a6}\x{12ad}\x{1270}\x{12cd}\x{1260}\x{122d}", +"\x{1296}\x{126c}\x{121d}\x{1260}\x{122d}", +"\x{12f2}\x{1234}\x{121d}\x{1260}\x{122d}" +); +@DoWs = map { substr($_,0,3) } @DoW; +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = ( +"\x{1295}/\x{1230}", +"\x{12F5}/\x{1230}" +); + +@Dsuf = ("\x{12ed}" x 31); +} +else { +@DoW = ( +"ሰንበት", +"ሰኑይ", +"ሰሉስ", +"ረቡዕ", +"ሓሙስ", +"ዓርቢ", +"ቀዳም" +); +@MoY = ( +"ጃንዩወሪ", +"ፌብሩወሪ", +"ማርች", +"ኤፕረል", +"ሜይ", +"ጁን", +"ጁላይ", +"ኦገስት", +"ሴፕቴምበር", +"ኦክተውበር", +"ኖቬምበር", +"ዲሴምበር" +); +@DoWs = map { substr($_,0,9) } @DoW; +@MoYs = map { substr($_,0,9) } @MoY; +@AMPM = ( +"ን/ሰ", +"ድ/ሰ" +); + +@Dsuf = ("ይ" x 31); +} + +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[$_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[$_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } + +1; diff --git a/lib/Date/Language/Turkish.pm b/lib/Date/Language/Turkish.pm new file mode 100755 index 0000000..593e209 --- /dev/null +++ b/lib/Date/Language/Turkish.pm @@ -0,0 +1,59 @@ +#----------------------------------------------------# +# +# Turkish tables +# Burak Grsoy <burak@cpan.org> +# Last modified: Sat Nov 15 20:28:32 2003 +# +# use Date::Language; +# my $turkish = Date::Language->new('Turkish'); +# print $turkish->time2str("%e %b %Y, %a %T\n", time); +# print $turkish->str2time("25 Haz 1996 21:09:55 +0100"); +#----------------------------------------------------# + +package Date::Language::Turkish; +use Date::Language (); +use vars qw(@ISA @DoW @DoWs @MoY @MoYs @AMPM @Dsuf %MoY %DoW $VERSION %DsufMAP); +@ISA = qw(Date::Language); +$VERSION = "1.0"; + +@DoW = qw(Pazar Pazartesi Sal aramba Perembe Cuma Cumartesi); +@MoY = qw(Ocak ubat Mart Nisan Mays Haziran Temmuz Austos Eyll Ekim Kasm Aralk); +@DoWs = map { substr($_,0,3) } @DoW; +$DoWs[1] = 'Pzt'; # Since we'll get two 'Paz' s +$DoWs[-1] = 'Cmt'; # Since we'll get two 'Cum' s +@MoYs = map { substr($_,0,3) } @MoY; +@AMPM = ('',''); # no am-pm thingy + +# not easy as in english... maybe we can just use a dot "." ? :) +%DsufMAP = ( +(map {$_ => 'inci', $_+10 => 'inci', $_+20 => 'inci' } 1,2,5,8 ), +(map {$_ => 'nci', $_+10 => 'nci', $_+20 => 'nci' } 7 ), +(map {$_ => 'nci', $_+10 => 'nci', $_+20 => 'nci' } 2 ), +(map {$_ => 'nc', $_+10 => 'nc', $_+20 => 'nc' } 3,4 ), +(map {$_ => 'uncu', $_+10 => 'uncu', $_+20 => 'uncu' } 9 ), +(map {$_ => 'nc', $_+10 => 'nc', $_+20 => 'nc' } 6 ), +(map {$_ => 'uncu', } 10,30 ), + 20 => 'nci', + 31 => 'inci', +); + +@Dsuf = map{ $DsufMAP{$_} } sort {$a <=> $b} keys %DsufMAP; +@MoY{@MoY} = (0 .. scalar(@MoY)); +@MoY{@MoYs} = (0 .. scalar(@MoYs)); +@DoW{@DoW} = (0 .. scalar(@DoW)); +@DoW{@DoWs} = (0 .. scalar(@DoWs)); + +# Formatting routines + +sub format_a { $DoWs[$_[0]->[6]] } +sub format_A { $DoW[ $_[0]->[6]] } +sub format_b { $MoYs[$_[0]->[4]] } +sub format_B { $MoY[ $_[0]->[4]] } +sub format_h { $MoYs[$_[0]->[4]] } +sub format_p { '' } # disable +sub format_P { '' } # disable +sub format_o { sprintf("%2d%s",$_[0]->[3],$Dsuf[$_[0]->[3]-1]) } + +1; + +__END__ diff --git a/lib/Date/Parse.pm b/lib/Date/Parse.pm new file mode 100644 index 0000000..12b04c1 --- /dev/null +++ b/lib/Date/Parse.pm @@ -0,0 +1,380 @@ +# Copyright (c) 1995-2009 Graham Barr. This program is free +# software; you can redistribute it and/or modify it under the same terms +# as Perl itself. + +package Date::Parse; + +require 5.000; +use strict; +use vars qw($VERSION @ISA @EXPORT); +use Time::Local; +use Carp; +use Time::Zone; +use Exporter; + +@ISA = qw(Exporter); +@EXPORT = qw(&strtotime &str2time &strptime); + +$VERSION = "2.30"; + +my %month = ( + january => 0, + february => 1, + march => 2, + april => 3, + may => 4, + june => 5, + july => 6, + august => 7, + september => 8, + sept => 8, + october => 9, + november => 10, + december => 11, + ); + +my %day = ( + sunday => 0, + monday => 1, + tuesday => 2, + tues => 2, + wednesday => 3, + wednes => 3, + thursday => 4, + thur => 4, + thurs => 4, + friday => 5, + saturday => 6, + ); + +my @suf = (qw(th st nd rd th th th th th th)) x 3; +@suf[11,12,13] = qw(th th th); + +#Abbreviations + +map { $month{substr($_,0,3)} = $month{$_} } keys %month; +map { $day{substr($_,0,3)} = $day{$_} } keys %day; + +my $strptime = <<'ESQ'; + my %month = map { lc $_ } %$mon_ref; + my $daypat = join("|", map { lc $_ } reverse sort keys %$day_ref); + my $monpat = join("|", reverse sort keys %month); + my $sufpat = join("|", reverse sort map { lc $_ } @$suf_ref); + + my %ampm = ( + 'a' => 0, # AM + 'p' => 12, # PM + ); + + my($AM, $PM) = (0,12); + +sub { + + my $dtstr = lc shift; + my $merid = 24; + + my($year,$month,$day,$hh,$mm,$ss,$zone,$dst,$frac); + + $zone = tz_offset(shift) if @_; + + 1 while $dtstr =~ s#\([^\(\)]*\)# #o; + + $dtstr =~ s#(\A|\n|\Z)# #sog; + + # ignore day names + $dtstr =~ s#([\d\w\s])[\.\,]\s#$1 #sog; + $dtstr =~ s/,/ /g; + $dtstr =~ s#($daypat)\s*(den\s)?\b# #o; + # Time: 12:00 or 12:00:00 with optional am/pm + + return unless $dtstr =~ /\S/; + + if ($dtstr =~ s/\s(\d{4})([-:]?)(\d\d?)\2(\d\d?)(?:[-Tt ](\d\d?)(?:([-:]?)(\d\d?)(?:\6(\d\d?)(?:[.,](\d+))?)?)?)?(?=\D)/ /) { + ($year,$month,$day,$hh,$mm,$ss,$frac) = ($1,$3-1,$4,$5,$7,$8,$9); + } + + unless (defined $hh) { + if ($dtstr =~ s#[:\s](\d\d?):(\d\d?)(:(\d\d?)(?:\.\d+)?)?(z)?\s*(?:([ap])\.?m?\.?)?\s# #o) { + ($hh,$mm,$ss) = ($1,$2,$4); + $zone = 0 if $5; + $merid = $ampm{$6} if $6; + } + + # Time: 12 am + + elsif ($dtstr =~ s#\s(\d\d?)\s*([ap])\.?m?\.?\s# #o) { + ($hh,$mm,$ss) = ($1,0,0); + $merid = $ampm{$2}; + } + } + + if (defined $hh and $hh <= 12 and $dtstr =~ s# ([ap])\.?m?\.?\s# #o) { + $merid = $ampm{$1}; + } + + + unless (defined $year) { + # Date: 12-June-96 (using - . or /) + + if ($dtstr =~ s#\s(\d\d?)([\-\./])($monpat)(\2(\d\d+))?\s# #o) { + ($month,$day) = ($month{$3},$1); + $year = $5 if $5; + } + + # Date: 12-12-96 (using '-', '.' or '/' ) + + elsif ($dtstr =~ s#\s(\d+)([\-\./])(\d\d?)(\2(\d+))?\s# #o) { + ($month,$day) = ($1 - 1,$3); + + if ($5) { + $year = $5; + # Possible match for 1995-01-24 (short mainframe date format); + ($year,$month,$day) = ($1, $3 - 1, $5) if $month > 12; + return if length($year) > 2 and $year < 1901; + } + } + elsif ($dtstr =~ s#\s(\d+)\s*($sufpat)?\s*($monpat)# #o) { + ($month,$day) = ($month{$3},$1); + } + elsif ($dtstr =~ s#($monpat)\s*(\d+)\s*($sufpat)?\s# #o) { + ($month,$day) = ($month{$1},$2); + } + elsif ($dtstr =~ s#($monpat)([\/-])(\d+)[\/-]# #o) { + ($month,$day) = ($month{$1},$3); + } + + # Date: 961212 + + elsif ($dtstr =~ s#\s(\d\d)(\d\d)(\d\d)\s# #o) { + ($year,$month,$day) = ($1,$2-1,$3); + } + + $year = $1 if !defined($year) and $dtstr =~ s#\s(\d{2}(\d{2})?)[\s\.,]# #o; + + } + + # Zone + + $dst = 1 if $dtstr =~ s#\bdst\b##o; + + if ($dtstr =~ s#\s"?([a-z]{3,4})(dst|\d+[a-z]*|_[a-z]+)?"?\s# #o) { + $dst = 1 if $2 and $2 eq 'dst'; + $zone = tz_offset($1); + return unless defined $zone; + } + elsif ($dtstr =~ s#\s([a-z]{3,4})?([\-\+]?)-?(\d\d?):?(\d\d)?(00)?\s# #o) { + my $m = defined($4) ? "$2$4" : 0; + my $h = "$2$3"; + $zone = defined($1) ? tz_offset($1) : 0; + return unless defined $zone; + $zone += 60 * ($m + (60 * $h)); + } + + if ($dtstr =~ /\S/) { + # now for some dumb dates + if ($dtstr =~ s/^\s*(ut?|z)\s*$//) { + $zone = 0; + } + elsif ($dtstr =~ s#\s([a-z]{3,4})?([\-\+]?)-?(\d\d?)(\d\d)?(00)?\s# #o) { + my $m = defined($4) ? "$2$4" : 0; + my $h = "$2$3"; + $zone = defined($1) ? tz_offset($1) : 0; + return unless defined $zone; + $zone += 60 * ($m + (60 * $h)); + } + + return if $dtstr =~ /\S/o; + } + + if (defined $hh) { + if ($hh == 12) { + $hh = 0 if $merid == $AM; + } + elsif ($merid == $PM) { + $hh += 12; + } + } + + $year -= 1900 if defined $year && $year > 1900; + + $zone += 3600 if defined $zone && $dst; + $ss += "0.$frac" if $frac; + + return ($ss,$mm,$hh,$day,$month,$year,$zone); +} +ESQ + +use vars qw($day_ref $mon_ref $suf_ref $obj); + +sub gen_parser +{ + local($day_ref,$mon_ref,$suf_ref,$obj) = @_; + + if($obj) + { + my $obj_strptime = $strptime; + substr($obj_strptime,index($strptime,"sub")+6,0) = <<'ESQ'; + shift; # package +ESQ + my $sub = eval "$obj_strptime" or die $@; + return $sub; + } + + eval "$strptime" or die $@; + +} + +*strptime = gen_parser(\%day,\%month,\@suf); + +sub str2time +{ + my @t = strptime(@_); + + return undef + unless @t; + + my($ss,$mm,$hh,$day,$month,$year,$zone) = @t; + my @lt = localtime(time); + + $hh ||= 0; + $mm ||= 0; + $ss ||= 0; + + my $frac = $ss - int($ss); + $ss = int $ss; + + $month = $lt[4] + unless(defined $month); + + $day = $lt[3] + unless(defined $day); + + $year = ($month > $lt[4]) ? ($lt[5] - 1) : $lt[5] + unless(defined $year); + + return undef + unless($month <= 11 && $day >= 1 && $day <= 31 + && $hh <= 23 && $mm <= 59 && $ss <= 59); + + my $result; + + if (defined $zone) { + $result = eval { + local $SIG{__DIE__} = sub {}; # Ick! + timegm($ss,$mm,$hh,$day,$month,$year); + }; + return undef + if !defined $result + or $result == -1 + && join("",$ss,$mm,$hh,$day,$month,$year) + ne "595923311169"; + $result -= $zone; + } + else { + $result = eval { + local $SIG{__DIE__} = sub {}; # Ick! + timelocal($ss,$mm,$hh,$day,$month,$year); + }; + return undef + if !defined $result + or $result == -1 + && join("",$ss,$mm,$hh,$day,$month,$year) + ne join("",(localtime(-1))[0..5]); + } + + return $result + $frac; +} + +1; + +__END__ + + +=head1 NAME + +Date::Parse - Parse date strings into time values + +=head1 SYNOPSIS + + use Date::Parse; + + $time = str2time($date); + + ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date); + +=head1 DESCRIPTION + +C<Date::Parse> provides two routines for parsing date strings into time values. + +=over 4 + +=item str2time(DATE [, ZONE]) + +C<str2time> parses C<DATE> and returns a unix time value, or undef upon failure. +C<ZONE>, if given, specifies the timezone to assume when parsing if the +date string does not specify a timezone. + +=item strptime(DATE [, ZONE]) + +C<strptime> takes the same arguments as str2time but returns an array of +values C<($ss,$mm,$hh,$day,$month,$year,$zone)>. Elements are only defined +if they could be extracted from the date string. The C<$zone> element is +the timezone offset in seconds from GMT. An empty array is returned upon +failure. + +=head1 MULTI-LANGUAGE SUPPORT + +Date::Parse is capable of parsing dates in several languages, these include +English, French, German and Italian. + + $lang = Date::Language->new('German'); + $lang->str2time("25 Jun 1996 21:09:55 +0100"); + +=head1 EXAMPLE DATES + +Below is a sample list of dates that are known to be parsable with Date::Parse + + 1995:01:24T09:08:17.1823213 ISO-8601 + 1995-01-24T09:08:17.1823213 + Wed, 16 Jun 94 07:29:35 CST Comma and day name are optional + Thu, 13 Oct 94 10:13:13 -0700 + Wed, 9 Nov 1994 09:50:32 -0500 (EST) Text in ()'s will be ignored. + 21 dec 17:05 Will be parsed in the current time zone + 21-dec 17:05 + 21/dec 17:05 + 21/dec/93 17:05 + 1999 10:02:18 "GMT" + 16 Nov 94 22:28:20 PST + +=head1 LIMITATION + +Date::Parse uses L<Time::Local> internally, so is limited to only parsing dates +which result in valid values for Time::Local::timelocal. This generally means dates +between 1901-12-17 00:00:00 GMT and 2038-01-16 23:59:59 GMT + +=head1 BUGS + +When both the month and the date are specified in the date as numbers +they are always parsed assuming that the month number comes before the +date. This is the usual format used in American dates. + +The reason why it is like this and not dynamic is that it must be +deterministic. Several people have suggested using the current locale, +but this will not work as the date being parsed may not be in the format +of the current locale. + +My plans to address this, which will be in a future release, is to allow +the programmer to state what order they want these values parsed in. + +=head1 AUTHOR + +Graham Barr <gbarr@pobox.com> + +=head1 COPYRIGHT + +Copyright (c) 1995-2009 Graham Barr. This program is free +software; you can redistribute it and/or modify it under the same terms +as Perl itself. + +=cut + diff --git a/lib/Time/Zone.pm b/lib/Time/Zone.pm new file mode 100644 index 0000000..8a40f91 --- /dev/null +++ b/lib/Time/Zone.pm @@ -0,0 +1,291 @@ + +package Time::Zone; + +=head1 NAME + +Time::Zone -- miscellaneous timezone manipulations routines + +=head1 SYNOPSIS + + use Time::Zone; + print tz2zone(); + print tz2zone($ENV{'TZ'}); + print tz2zone($ENV{'TZ'}, time()); + print tz2zone($ENV{'TZ'}, undef, $isdst); + $offset = tz_local_offset(); + $offset = tz_offset($TZ); + +=head1 DESCRIPTION + +This is a collection of miscellaneous timezone manipulation routines. + +C<tz2zone()> parses the TZ environment variable and returns a timezone +string suitable for inclusion in L<date(1)>-like output. It opionally takes +a timezone string, a time, and a is-dst flag. + +C<tz_local_offset()> determins the offset from GMT time in seconds. It +only does the calculation once. + +C<tz_offset()> determines the offset from GMT in seconds of a specified +timezone. + +C<tz_name()> determines the name of the timezone based on its offset + +=head1 AUTHORS + +Graham Barr <gbarr@pobox.com> +David Muir Sharnoff <muir@idiom.com> +Paul Foley <paul@ascent.com> + +=cut + +require 5.002; + +require Exporter; +use Carp; +use strict; +use vars qw(@ISA @EXPORT $VERSION @tz_local); + +@ISA = qw(Exporter); +@EXPORT = qw(tz2zone tz_local_offset tz_offset tz_name); +$VERSION = "2.24"; + +# Parts stolen from code by Paul Foley <paul@ascent.com> + +sub tz2zone (;$$$) +{ + my($TZ, $time, $isdst) = @_; + + use vars qw(%tzn_cache); + + $TZ = defined($ENV{'TZ'}) ? ( $ENV{'TZ'} ? $ENV{'TZ'} : 'GMT' ) : '' + unless $TZ; + + # Hack to deal with 'PST8PDT' format of TZ + # Note that this can't deal with all the esoteric forms, but it + # does recognize the most common: [:]STDoff[DST[off][,rule]] + + if (! defined $isdst) { + my $j; + $time = time() unless $time; + ($j, $j, $j, $j, $j, $j, $j, $j, $isdst) = localtime($time); + } + + if (defined $tzn_cache{$TZ}->[$isdst]) { + return $tzn_cache{$TZ}->[$isdst]; + } + + if ($TZ =~ /^ + ( [^:\d+\-,] {3,} ) + ( [+-] ? + \d {1,2} + ( : \d {1,2} ) {0,2} + ) + ( [^\d+\-,] {3,} )? + /x + ) { + my $dsttz = defined($4) ? $4 : $1; + $TZ = $isdst ? $dsttz : $1; + $tzn_cache{$TZ} = [ $1, $dsttz ]; + } else { + $tzn_cache{$TZ} = [ $TZ, $TZ ]; + } + return $TZ; +} + +sub tz_local_offset (;$) +{ + my ($time) = @_; + + $time = time() unless $time; + my (@l) = localtime($time); + my $isdst = $l[8]; + + if (defined($tz_local[$isdst])) { + return $tz_local[$isdst]; + } + + $tz_local[$isdst] = &calc_off($time); + + return $tz_local[$isdst]; +} + +sub calc_off +{ + my ($time) = @_; + + my (@l) = localtime($time); + my (@g) = gmtime($time); + + my $off; + + $off = $l[0] - $g[0] + + ($l[1] - $g[1]) * 60 + + ($l[2] - $g[2]) * 3600; + + # subscript 7 is yday. + + if ($l[7] == $g[7]) { + # done + } elsif ($l[7] == $g[7] + 1) { + $off += 86400; + } elsif ($l[7] == $g[7] - 1) { + $off -= 86400; + } elsif ($l[7] < $g[7]) { + # crossed over a year boundry! + # localtime is beginning of year, gmt is end + # therefore local is ahead + $off += 86400; + } else { + $off -= 86400; + } + + return $off; +} + +# constants + +CONFIG: { + use vars qw(%dstZone %zoneOff %dstZoneOff %Zone); + + my @dstZone = ( + # "ndt" => -2*3600-1800, # Newfoundland Daylight + "brst" => -2*3600, # Brazil Summer Time (East Daylight) + "adt" => -3*3600, # Atlantic Daylight + "edt" => -4*3600, # Eastern Daylight + "cdt" => -5*3600, # Central Daylight + "mdt" => -6*3600, # Mountain Daylight + "pdt" => -7*3600, # Pacific Daylight + "akdt" => -8*3600, # Alaska Daylight + "ydt" => -8*3600, # Yukon Daylight + "hdt" => -9*3600, # Hawaii Daylight + "bst" => +1*3600, # British Summer + "mest" => +2*3600, # Middle European Summer + "metdst" => +2*3600, # Middle European DST + "sst" => +2*3600, # Swedish Summer + "fst" => +2*3600, # French Summer + "cest" => +2*3600, # Central European Daylight + "eest" => +3*3600, # Eastern European Summer + "msd" => +4*3600, # Moscow Daylight + "wadt" => +8*3600, # West Australian Daylight + "kdt" => +10*3600, # Korean Daylight + # "cadt" => +10*3600+1800, # Central Australian Daylight + "aedt" => +11*3600, # Eastern Australian Daylight + "eadt" => +11*3600, # Eastern Australian Daylight + "nzd" => +13*3600, # New Zealand Daylight + "nzdt" => +13*3600, # New Zealand Daylight + ); + + my @Zone = ( + "gmt" => 0, # Greenwich Mean + "ut" => 0, # Universal (Coordinated) + "utc" => 0, + "wet" => 0, # Western European + "wat" => -1*3600, # West Africa + "at" => -2*3600, # Azores + "fnt" => -2*3600, # Brazil Time (Extreme East - Fernando Noronha) + "brt" => -3*3600, # Brazil Time (East Standard - Brasilia) + # For completeness. BST is also British Summer, and GST is also Guam Standard. + # "bst" => -3*3600, # Brazil Standard + # "gst" => -3*3600, # Greenland Standard + # "nft" => -3*3600-1800,# Newfoundland + # "nst" => -3*3600-1800,# Newfoundland Standard + "mnt" => -4*3600, # Brazil Time (West Standard - Manaus) + "ewt" => -4*3600, # U.S. Eastern War Time + "ast" => -4*3600, # Atlantic Standard + "est" => -5*3600, # Eastern Standard + "act" => -5*3600, # Brazil Time (Extreme West - Acre) + "cst" => -6*3600, # Central Standard + "mst" => -7*3600, # Mountain Standard + "pst" => -8*3600, # Pacific Standard + "akst" => -9*3600, # Alaska Standard + "yst" => -9*3600, # Yukon Standard + "hst" => -10*3600, # Hawaii Standard + "cat" => -10*3600, # Central Alaska + "ahst" => -10*3600, # Alaska-Hawaii Standard + "nt" => -11*3600, # Nome + "idlw" => -12*3600, # International Date Line West + "cet" => +1*3600, # Central European + "mez" => +1*3600, # Central European (German) + "ect" => +1*3600, # Central European (French) + "met" => +1*3600, # Middle European + "mewt" => +1*3600, # Middle European Winter + "swt" => +1*3600, # Swedish Winter + "set" => +1*3600, # Seychelles + "fwt" => +1*3600, # French Winter + "eet" => +2*3600, # Eastern Europe, USSR Zone 1 + "ukr" => +2*3600, # Ukraine + "bt" => +3*3600, # Baghdad, USSR Zone 2 + "msk" => +3*3600, # Moscow + # "it" => +3*3600+1800,# Iran + "zp4" => +4*3600, # USSR Zone 3 + "zp5" => +5*3600, # USSR Zone 4 + # "ist" => +5*3600+1800,# Indian Standard + "zp6" => +6*3600, # USSR Zone 5 + # For completeness. NST is also Newfoundland Stanard, and SST is also Swedish Summer. + # "nst" => +6*3600+1800,# North Sumatra + # "sst" => +7*3600, # South Sumatra, USSR Zone 6 + # "jt" => +7*3600+1800,# Java (3pm in Cronusland!) + "wst" => +8*3600, # West Australian Standard + "hkt" => +8*3600, # Hong Kong + "cct" => +8*3600, # China Coast, USSR Zone 7 + "jst" => +9*3600, # Japan Standard, USSR Zone 8 + "kst" => +9*3600, # Korean Standard + # "cast" => +9*3600+1800,# Central Australian Standard + "aest" => +10*3600, # Eastern Australian Standard + "east" => +10*3600, # Eastern Australian Standard + "gst" => +10*3600, # Guam Standard, USSR Zone 9 + "nzt" => +12*3600, # New Zealand + "nzst" => +12*3600, # New Zealand Standard + "idle" => +12*3600, # International Date Line East + ); + + %Zone = @Zone; + %dstZone = @dstZone; + %zoneOff = reverse(@Zone); + %dstZoneOff = reverse(@dstZone); + +} + +sub tz_offset (;$$) +{ + my ($zone, $time) = @_; + + return &tz_local_offset($time) unless($zone); + + $time = time() unless $time; + my(@l) = localtime($time); + my $dst = $l[8]; + + $zone = lc $zone; + + if($zone =~ /^(([\-\+])\d\d?)(\d\d)$/) { + my $v = $2 . $3; + return $1 * 3600 + $v * 60; + } elsif (exists $dstZone{$zone} && ($dst || !exists $Zone{$zone})) { + return $dstZone{$zone}; + } elsif(exists $Zone{$zone}) { + return $Zone{$zone}; + } + undef; +} + +sub tz_name (;$$) +{ + my ($off, $dst) = @_; + + $off = tz_offset() + unless(defined $off); + + $dst = (localtime(time))[8] + unless(defined $dst); + + if (exists $dstZoneOff{$off} && ($dst || !exists $zoneOff{$off})) { + return $dstZoneOff{$off}; + } elsif (exists $zoneOff{$off}) { + return $zoneOff{$off}; + } + sprintf("%+05d", int($off / 60) * 100 + $off % 60); +} + +1; |