Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Date / Language.pm
CommitLineData
86530b38
AT
1
2package Date::Language;
3
4use strict;
5use Time::Local;
6use Carp;
7use vars qw($VERSION @ISA);
8require Date::Format;
9
10$VERSION = "1.10";
11@ISA = qw(Date::Format::Generic);
12
13sub 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 ;-)
30sub DESTROY {}
31
32sub 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
55sub 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
831;