$offset = abs($offset);
my $hours = int( $offset / 3600 );
$offset %= 3600;
my $mins = int( $offset / 60 );
$offset %= 60;
my $secs = int( $offset );
return ( $secs ?
sprintf( '%s%02d%02d%02d', $sign, $hours, $mins, $secs ) :
sprintf( '%s%02d%02d', $sign, $hours, $mins )
);
}
# These methods all operate on data contained in the DateTime/TimeZoneCatalog.pm file.
sub all_names
{
return wantarray ? @DateTime::TimeZone::ALL : [@DateTime::TimeZone::ALL];
}
sub categories
{
return wantarray
? @DateTime::TimeZone::CATEGORY_NAMES
: [@DateTime::TimeZone::CATEGORY_NAMES];
}
sub links
{
return
wantarray ? %DateTime::TimeZone::LINKS : {%DateTime::TimeZone::LINKS};
}
sub names_in_category
{
shift if $_[0]->isa('DateTime::TimeZone');
return unless exists $DateTime::TimeZone::CATEGORIES{ $_[0] };
return
wantarray
? @{ $DateTime::TimeZone::CATEGORIES{ $_[0] } }
: [ $DateTime::TimeZone::CATEGORIES{ $_[0] } ];
}
sub countries
{
wantarray
? ( sort keys %DateTime::TimeZone::ZONES_BY_COUNTRY )
: [ sort keys %DateTime::TimeZone::ZONES_BY_COUNTRY ];
}
sub names_in_country
{
shift if $_[0]->isa('DateTime::TimeZone');
return unless exists $DateTime::TimeZone::ZONES_BY_COUNTRY{ lc $_[0] };
return
wantarray
? @{ $DateTime::TimeZone::ZONES_BY_COUNTRY{ lc $_[0] } }
: $DateTime::TimeZone::ZONES_BY_COUNTRY{ lc $_[0] };
}
1;
__END__
=head1 NAME
DateTime::TimeZone - Time zone object base class and factory
=head1 SYNOPSIS
use DateTime;
use DateTime::TimeZone;
my $tz = DateTime::TimeZone->new( name => 'America/Chicago' );
my $dt = DateTime->now();
my $offset = $tz->offset_for_datetime($dt);
=head1 DESCRIPTION
This class is the base class for all time zone objects. A time zone
is represented internally as a set of observances, each of which
describes the offset from GMT for a given time period.
Note that without the C<DateTime.pm> module, this module does not do
much. It's primary interface is through a C<DateTime> object, and
most users will not need to directly use C<DateTime::TimeZone>
methods.
=head1 USAGE
This class has the following methods:
=head2 DateTime::TimeZone->new( name => $tz_name )
=6= |