sub name { $_[0]->{name} }
sub category { (split /\//, $_[0]->{name}, 2)[0] }
sub is_valid_name
{
my $tz;
{
local $@;
$tz = eval { $_[0]->new( name => $_[1] ) };
}
return $tz && $tz->isa('DateTime::TimeZone') ? 1 : 0
}
sub STORABLE_freeze
{
my $self = shift;
return $self->name;
}
sub STORABLE_thaw
{
my $self = shift;
my $cloning = shift;
my $serialized = shift;
my $class = ref $self || $self;
my $obj;
if ( $class->isa(__PACKAGE__) )
{
$obj = __PACKAGE__->new( name => $serialized );
}
else
{
$obj = $class->new( name => $serialized );
}
%$self = %$obj;
return $self;
}
#
# Functions
#
sub offset_as_seconds
{
{
local $@;
shift if eval { $_[0]->isa('DateTime::TimeZone') };
}
my $offset = shift;
return undef unless defined $offset;
return 0 if $offset eq '0';
my ( $sign, $hours, $minutes, $seconds );
if ( $offset =~ /^([\+\-])?(\d\d?):(\d\d)(?::(\d\d))?$/ )
{
( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $3, $4 );
}
elsif ( $offset =~ /^([\+\-])?(\d\d)(\d\d)(\d\d)?$/ )
{
( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $3, $4 );
}
else
{
return undef;
}
$sign = '+' unless defined $sign;
return undef unless $hours >= 0 && $hours <= 99;
return undef unless $minutes >= 0 && $minutes <= 59;
return undef unless ! defined( $seconds ) || ( $seconds >= 0 && $seconds <= 59 );
my $total = $hours * 3600 + $minutes * 60;
$total += $seconds if $seconds;
$total *= -1 if $sign eq '-';
return $total;
}
sub offset_as_string
{
{
local $@;
shift if eval { $_[0]->isa('DateTime::TimeZone') };
}
my $offset = shift;
return undef unless defined $offset;
return undef unless $offset >= -359999 && $offset <= 359999;
my $sign = $offset < 0 ? '-' : '+';
=5= |