1 package DateTime::TimeZone::OffsetOnly;
5 use vars qw ($VERSION);
8 use DateTime::TimeZone;
9 use base 'DateTime::TimeZone';
11 use DateTime::TimeZone::UTC;
12 use Params::Validate qw( validate SCALAR );
17 my %p = validate( @_, { offset => { type => SCALAR },
21 DateTime::TimeZone::offset_as_seconds( $p{offset} );
23 die "Invalid offset: $p{offset}\n" unless defined $offset;
25 return DateTime::TimeZone::UTC->new unless $offset;
27 my $self = { name => DateTime::TimeZone::offset_as_string( $offset ),
31 return bless $self, $class;
34 sub is_dst_for_datetime { 0 }
36 sub offset_for_datetime { $_[0]->{offset} }
37 sub offset_for_local_datetime { $_[0]->{offset} }
41 sub short_name_for_datetime { $_[0]->name }
43 sub category { undef }
57 my $serialized = shift;
59 my $class = ref $self || $self;
62 if ( $class->isa(__PACKAGE__) )
64 $obj = __PACKAGE__->new( offset => $serialized );
68 $obj = $class->new( offset => $serialized );
83 DateTime::TimeZone::OffsetOnly - A DateTime::TimeZone object that just contains an offset
87 my $offset_tz = DateTime::TimeZone->new( name => '-0300' );
91 This class is used to provide the DateTime::TimeZone API needed by
92 DateTime.pm, but with a fixed offset. An object in this class always
93 returns the same offset as was given in its constructor, regardless of
98 This class has the same methods as a real time zone object, but the
99 C<category()> method returns undef.
101 =head2 DateTime::TimeZone::OffsetOnly->new ( offset => $offset )
103 The value given to the offset parameter must be a string such as
104 "+0300". Strings will be converted into numbers by the
105 C<DateTime::TimeZone::offset_as_seconds()> function.
107 =head2 $tz->offset_for_datetime( $datetime )
109 No matter what date is given, the offset provided to the constructor
114 =head2 $tz->short_name_for_datetime()
116 Both of these methods return the offset in string form.
120 Dave Rolsky, <autarch@urth.org>
122 =head1 COPYRIGHT & LICENSE
124 Copyright (c) 2003-2008 David Rolsky. All rights reserved. This
125 program is free software; you can redistribute it and/or modify it
126 under the same terms as Perl itself.
128 The full text of the license can be found in the LICENSE file included