Bonus patch: this adds handling of the nautical single-letter timezone
names to DT::TZ::OffsetOnly and DT::TZ.  Very simple feature, bound to
be useful to someone.

-zefram
diff -ur dttz-mod1/lib/DateTime/TimeZone/OffsetOnly.pm 
dttz-mod2/lib/DateTime/TimeZone/OffsetOnly.pm
--- dttz-mod1/lib/DateTime/TimeZone/OffsetOnly.pm       2007-02-18 
15:54:12.000000000 +0000
+++ dttz-mod2/lib/DateTime/TimeZone/OffsetOnly.pm       2007-02-19 
22:13:36.809631560 +0000
@@ -11,6 +11,14 @@
 use DateTime::TimeZone::UTC;
 use Params::Validate qw( validate SCALAR );
 
+my %letter_offset = (
+       A =>  +1,  B =>  +2,  C =>  +3,  D =>  +4,  E =>  +5,  F =>  +6,
+       G =>  +7,  H =>  +8,  I =>  +9,  K => +10,  L => +11,  M => +12,
+       N =>  -1,  O =>  -2,  P =>  -3,  Q =>  -4,  R =>  -5,  S =>  -6,
+       T =>  -7,  U =>  -8,  V =>  -9,  W => -10,  X => -11,  Y => -12,
+       Z => 0,
+);
+
 sub new
 {
     my $class = shift;
@@ -18,7 +26,8 @@
                           } );
 
     my $offset =
-        DateTime::TimeZone::offset_as_seconds( $p{offset} );
+        $p{offset} =~ /\A[A-IK-Z]\z/ ? 3600 * $letter_offset{$p{offset}} :
+            DateTime::TimeZone::offset_as_seconds( $p{offset} );
 
     die "Invalid offset: $p{offset}\n" unless defined $offset;
 
@@ -100,9 +109,13 @@
 
 =head2 DateTime::TimeZone::OffsetOnly->new ( offset => $offset )
 
-The value given to the offset parameter must be a string such as
-"+0300".  Strings will be converted into numbers by the
-C<DateTime::TimeZone::offset_as_seconds()> function.
+Three forms are accepted for the offset parameter.  It may be an offset in
+hours, minutes, and optional seconds, each two digits, with no separators
+and optional leading sign, for example "+0300".  It may be an offset in
+hours (one or two digits), minutes (two digits), and optional seconds
+(two digits), with ":" separators and optional leading sign, for example
+"-1:01:06".  Or it may be a single capital letter other than "J", in
+which case it is interpreted as a nautical timezone name.
 
 =head2 $tz->offset_for_datetime( $datetime )
 
diff -ur dttz-mod1/lib/DateTime/TimeZone.pm dttz-mod2/lib/DateTime/TimeZone.pm
--- dttz-mod1/lib/DateTime/TimeZone.pm  2007-02-19 20:19:13.383139216 +0000
+++ dttz-mod2/lib/DateTime/TimeZone.pm  2007-02-19 22:08:10.911550810 +0000
@@ -95,7 +95,8 @@
         require DateTime::TimeZone::Tzfile;
         return DateTime::TimeZone::Tzfile->new( $filename );
     }
-    elsif ( $name =~ /\A[-+]?(?:\d\d?:\d\d(?::\d\d)?|\d{4}(?:\d\d)?)\z/ )
+    elsif ( $name =~ /\A(?:[-+]?(?:\d\d?:\d\d(?::\d\d)?|\d{4}(?:\d\d)?)|
+                           [A-IK-Z])\z/x )
     {
         require DateTime::TimeZone::OffsetOnly;
         return DateTime::TimeZone::OffsetOnly->new( offset => $name );
@@ -606,6 +607,13 @@
 
 =item *
 
+If the name is a single capital letter, other than "J", it is treated as
+a nautical timezone name, and a C<DateTime::TimeZone::OffsetOnly> object
+is returned.  (The case of "Z" is also handled by one of the rules above.
+It means the same thing either way.)
+
+=item *
+
 If the name is "floating", then a
 C<DateTime::TimeZone::Floating> object is returned.  A floating time
 zone does have I<any> offset, and is always the same time.  This is

Reply via email to