home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / perl5 / Date / Language.pm < prev    next >
Encoding:
Perl POD Document  |  2009-12-12  |  2.6 KB  |  145 lines

  1.  
  2. package Date::Language;
  3.  
  4. use     strict;
  5. use     Time::Local;
  6. use     Carp;
  7. use     vars qw($VERSION @ISA);
  8. require Date::Format;
  9.  
  10. $VERSION = "1.10";
  11. @ISA     = qw(Date::Format::Generic);
  12.  
  13. sub new
  14. {
  15.  my $self = shift;
  16.  my $type = shift || $self;
  17.  
  18.  $type =~ s/^(\w+)$/Date::Language::$1/;
  19.  
  20.  croak "Bad language"
  21.     unless $type =~ /^[\w:]+$/;
  22.  
  23.  eval "require $type"
  24.     or croak $@;
  25.  
  26.  bless [], $type;
  27. }
  28.  
  29. # Stop AUTOLOAD being called ;-)
  30. sub DESTROY {}
  31.  
  32. sub AUTOLOAD
  33. {
  34.  use vars qw($AUTOLOAD);
  35.  
  36.  if($AUTOLOAD =~ /::strptime\Z/o)
  37.   {
  38.    my $self = $_[0];
  39.    my $type = ref($self) || $self;
  40.    require Date::Parse;
  41.  
  42.    no strict 'refs';
  43.    *{"${type}::strptime"} = Date::Parse::gen_parser(
  44.     \%{"${type}::DoW"},
  45.     \%{"${type}::MoY"},
  46.     \@{"${type}::Dsuf"},
  47.     1);
  48.  
  49.    goto &{"${type}::strptime"};
  50.   }
  51.  
  52.  croak "Undefined method &$AUTOLOAD called";
  53. }
  54.  
  55. sub str2time
  56. {
  57.  my $me = shift;
  58.  my @t = $me->strptime(@_);
  59.  
  60.  return undef
  61.     unless @t;
  62.  
  63.  my($ss,$mm,$hh,$day,$month,$year,$zone) = @t;
  64.  my @lt  = localtime(time);
  65.  
  66.  $hh    ||= 0;
  67.  $mm    ||= 0;
  68.  $ss    ||= 0;
  69.  
  70.  $month = $lt[4]
  71.     unless(defined $month);
  72.  
  73.  $day  = $lt[3]
  74.     unless(defined $day);
  75.  
  76.  $year = ($month > $lt[4]) ? ($lt[5] - 1) : $lt[5]
  77.     unless(defined $year);
  78.  
  79.  return defined $zone ? timegm($ss,$mm,$hh,$day,$month,$year) - $zone
  80.                       : timelocal($ss,$mm,$hh,$day,$month,$year);
  81. }
  82.  
  83. 1;
  84.  
  85. __END__
  86.  
  87.  
  88. =head1 NAME
  89.  
  90. Date::Language - Language specific date formating and parsing
  91.  
  92. =head1 SYNOPSIS
  93.  
  94.   use Date::Language;
  95.  
  96.   my $lang = Date::Language->new('German');
  97.   $lang->time2str("%a %b %e %T %Y\n", time);
  98.  
  99. =head1 DESCRIPTION
  100.  
  101. L<Date::Language> provides objects to parse and format dates for specific languages. Available languages are
  102.  
  103.   Afar                    French                  Russian_cp1251
  104.   Amharic                 Gedeo                   Russian_koi8r
  105.   Austrian                German                  Sidama
  106.   Brazilian               Greek                   Somali
  107.   Chinese                 Hungarian               Spanish
  108.   Chinese_GB              Icelandic               Swedish
  109.   Czech                   Italian                 Tigrinya
  110.   Danish                  Norwegian               TigrinyaEritrean
  111.   Dutch                   Oromo                   TigrinyaEthiopian
  112.   English                 Romanian                Turkish
  113.   Finnish                 Russian
  114.  
  115. =head1 METHODS
  116.  
  117. =over
  118.  
  119. =item time2str
  120.  
  121. See L<Date::Format/time2str>
  122.  
  123. =item strftime
  124.  
  125. See L<Date::Format/strftime>
  126.  
  127. =item ctime
  128.  
  129. See L<Date::Format/ctime>
  130.  
  131. =item asctime
  132.  
  133. See L<Date::Format/asctime>
  134.  
  135. =item str2time
  136.  
  137. See L<Date::Parse/str2time>
  138.  
  139. =item strptime
  140.  
  141. See L<Date::Parse/strptime>
  142.  
  143. =back
  144.  
  145.