Re: [Patch] DT::TZ Offsets
> Ok, I'm convinced. Just go ahead and check it in as implemented. Done. I'll also add some tests for the 'name' normalization in OffsetOnly before the next release. -J --
Re: [Patch] DT::TZ Offsets
On Fri, 22 Aug 2003, Joshua Hoblitt wrote: > > I didn't look up the offset for Kiribati, actually, so thanks for the > > correction. > > I think the republic crosses at least 4 timezones. > > > Offsets of more than 12 hours aren't that strange; countries near the > > international date line can choose on which side of that line they are. > > I wouldn't be surprised if some parts of Alaska have been about +1530 at > > some point. > > > > Offsets of 24 hours are something else entirely, of course. > > True, but that's not a reason to go out of our way not to support them. Ok, I'm convinced. Just go ahead and check it in as implemented. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: [Patch] DT::TZ Offsets
> I didn't look up the offset for Kiribati, actually, so thanks for the > correction. I think the republic crosses at least 4 timezones. > Offsets of more than 12 hours aren't that strange; countries near the > international date line can choose on which side of that line they are. > I wouldn't be surprised if some parts of Alaska have been about +1530 at > some point. > > Offsets of 24 hours are something else entirely, of course. True, but that's not a reason to go out of our way not to support them. -J --
Re: [Patch] DT::TZ Offsets
Joshua Hoblitt schreef: > > Cuba (-0500) was at some point planning to change to +1900, to be the > > first country in the year 2000. If that would have happened, what do you > > think Kiribati (+1200, the first country to celebrate 2000 in reality) > > would have done? (They would have gone to +3600, of course; and perhaps > > even change back to +1200 at noon, 1 Jan 2000: "celebrate the new > > millennium twice!!!"). > > I've actually been to Kiribati and at least Fanning island is +1400. :) I didn't look up the offset for Kiribati, actually, so thanks for the correction. Offsets of more than 12 hours aren't that strange; countries near the international date line can choose on which side of that line they are. I wouldn't be surprised if some parts of Alaska have been about +1530 at some point. Offsets of 24 hours are something else entirely, of course. In the discussions on abandoning the leap second, one solution was to stop having them, to collect the time difference until it was 1 hour, and to adjust the timezones (and not UTC). So Greenwich time would become -0100 (summer time +), Central European Time + (CEST +0100) etcetera. After 24 of these adjustments, Greenwich would be at -2400, and British time would again agree with UTC time; except that the dates would be wrong. Eugene
Re: [Patch] DT::TZ Offsets
> > There's no official limit on offsets are there? I can envision some > > small country declaring an offset of greater then 24hours. > > You can? That doesn't make much sense to me. If it happens, we can > change the code ;) The universe doesn't always make sense to you? :) I choose 99:59:59 as the offset limit as that's the maximum time value that can be represented by that number of digits. If someone wants to specify an offset of > 24 hours I'm willing to assume they know what they're asking. It doesn't cause us any pain as it fits within the format we're already supporting. Of course we could also optionally accept duration objects as offsets specifiers... That actually doesn't sound like a bad idea. :) -J --
Re: [Patch] DT::TZ Offsets
> Cuba (-0500) was at some point planning to change to +1900, to be the > first country in the year 2000. If that would have happened, what do you > think Kiribati (+1200, the first country to celebrate 2000 in reality) > would have done? (They would have gone to +3600, of course; and perhaps > even change back to +1200 at noon, 1 Jan 2000: "celebrate the new > millennium twice!!!"). I've actually been to Kiribati and at least Fanning island is +1400. :) -J --
Re: [Patch] DT::TZ Offsets
Dave Rolsky schreef: > On Fri, 22 Aug 2003, Joshua Hoblitt wrote: > > > > Can you change it so that the maximum offset is 24:00:00 and then check it > > > in? > > > > There's no official limit on offsets are there? I can envision some > > small country declaring an offset of greater then 24hours. > > You can? That doesn't make much sense to me. If it happens, we can > change the code ;) Cuba (-0500) was at some point planning to change to +1900, to be the first country in the year 2000. If that would have happened, what do you think Kiribati (+1200, the first country to celebrate 2000 in reality) would have done? (They would have gone to +3600, of course; and perhaps even change back to +1200 at noon, 1 Jan 2000: "celebrate the new millennium twice!!!"). (source: Wall Street Journal 1996-01-22, via the tzdata mailing list archive) Eugene
Re: [Patch] DT::TZ Offsets
On Fri, 22 Aug 2003, Joshua Hoblitt wrote: > > Can you change it so that the maximum offset is 24:00:00 and then check it > > in? > > There's no official limit on offsets are there? I can envision some > small country declaring an offset of greater then 24hours. You can? That doesn't make much sense to me. If it happens, we can change the code ;) -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: [Patch] DT::TZ Offsets
> Can you change it so that the maximum offset is 24:00:00 and then check it > in? There's no official limit on offsets are there? I can envision some small country declaring an offset of greater then 24hours. -J --
Re: [Patch] DT::TZ Offsets
On Tue, 19 Aug 2003, Joshua Hoblitt wrote: > Comments? Can you change it so that the maximum offset is 24:00:00 and then check it in? -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
[Patch] DT::TZ Offsets
This patch started out as just adding some tests (taken from DT::TZ::Alias) but I uncovered several issues. These currently accepted offset formats should be rejected as they are ambiguous: '111', '+111', '-111', '1:11', '+1:11', '-1:11', '1', '+1', '-1', '111:11', '+111:11', '-111:11', '1:', '+1:', '-1:', '1:11:11', '+1:11:11', '-1:11:11', ':11', '+:11', '-:11', '11:', '+11:', '-11:', - the hours value of an offset must be specified as 2 digits - the colon separator must be used between both hours/minutes and minutes/seconds or not at all The algorithm for turning an offset string into a number of seconds was taking a modulus of the hours value. This could lead to developer surprise. The hours value has been limited to 99 (what fits into 2 digits), minutes limited to 59, and seconds limited to 59. - offset string formats are now validated and undef is returned for bad formats - the modulus of the hours value is removed The algorithm for turning a number of seconds into an offset string was producing floating point values. These were not being seen because of the sprintf format but could be a problem in the future. - internal floating point values are now truncated - the input number of seconds is now limited to what can actually be formated into a valid offset string - the output of offset_as_seconds() passed to offset_as_string() will return the original input (and vice versa) The 'name' key of OffsetOnly objects was not being normalized. Two objects with identical values but different 'names' could be created. - the 'name' value is now normalized Also: - added more regression tests - some minor cosmetic changes for clarity Comments? -J -- Index: lib/DateTime/TimeZone.pm === RCS file: /cvsroot/perl-date-time/modules/DateTime-TimeZone/lib/DateTime/TimeZone.pm,v retrieving revision 1.84 diff -u -r1.84 TimeZone.pm --- lib/DateTime/TimeZone.pm10 Aug 2003 13:44:48 - 1.84 +++ lib/DateTime/TimeZone.pm19 Aug 2003 10:28:53 - @@ -346,12 +346,16 @@ return 0 if $offset eq '0'; -return undef unless $offset =~ /^([\+\-])?(\d\d?):?(\d\d)(?::?(\d\d))?$/; +return undef unless $offset =~ /^([\+\-])?(\d\d)(:?)(\d\d)(?:\3(\d\d))?$/; + +my ( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $4, $5 ); -my ( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $3, $4 ); $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 * 60 * 60) + ($minutes * 60); +my $total = $hours * 3600 + $minutes * 60; $total += $seconds if $seconds; $total *= -1 if $sign eq '-'; @@ -363,17 +367,17 @@ my $offset = shift; return undef unless defined $offset; +return undef unless $offset >= -35 && $offset <= 35; my $sign = $offset < 0 ? '-' : '+'; $offset = abs($offset); -my $hours = $offset / ( 60 * 60 ); -$hours = $hours % 24; - -my $mins = ( $offset % ( 60 * 60 ) ) / 60; - -my $secs = $offset % 60; +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 ) : @@ -569,10 +573,12 @@ Given an offset as a string, this returns the number of seconds represented by the offset as a positive or negative number. +Returns C if $offset is not in the range C<-99:59:59> to C<+99:59:59>. =item * offset_as_string( $offset ) Given an offset as a number, this returns the offset as a string. +Returns C if $offset is not in the range C<-35> to C<35>. =back Index: lib/DateTime/TimeZone/OffsetOnly.pm === RCS file: /cvsroot/perl-date-time/modules/DateTime-TimeZone/lib/DateTime/TimeZone/OffsetOnly.pm,v retrieving revision 1.18 diff -u -r1.18 OffsetOnly.pm --- lib/DateTime/TimeZone/OffsetOnly.pm 13 Jun 2003 17:50:57 - 1.18 +++ lib/DateTime/TimeZone/OffsetOnly.pm 19 Aug 2003 10:28:53 - @@ -3,7 +3,7 @@ use strict; use vars qw ($VERSION); -$VERSION = 0.01; +$VERSION = 0.02; use DateTime::TimeZone; use base 'DateTime::TimeZone'; @@ -24,7 +24,10 @@ return DateTime::TimeZone::UTC->new unless $offset; -my $self = { name => $p{offset}, offset => $offset }; +my $self = { +name=> DateTime::TimeZone::offset_as_string( $offset ), +offset => $offset, +}; return bless $self, $class; } Index: t/05offset.t === RCS file: /cvsroot/perl-date-time/modules/DateTime-TimeZone/t/05offset.t,v retrieving revision 1.2 diff -u -r1.2 05offset.t --- t/05offset.t