Blame t/local.t

Packit Service f95697
use warnings;
Packit Service f95697
use strict;
Packit Service f95697
Packit Service f95697
use Test::More tests => 113;
Packit Service f95697
Packit Service f95697
{
Packit Service f95697
	package FakeLocalDateTime;
Packit Service f95697
	use Date::ISO8601 0.000 qw(ymd_to_cjdn);
Packit Service f95697
	my $rdn_epoch_cjdn = 1721425;
Packit Service f95697
	sub new {
Packit Service f95697
		my($class, $y, $mo, $d, $h, $mi, $s) = @_;
Packit Service f95697
		return bless({
Packit Service f95697
			rdn => ymd_to_cjdn($y, $mo, $d) - $rdn_epoch_cjdn,
Packit Service f95697
			sod => 3600*$h + 60*$mi + $s,
Packit Service f95697
		}, $class);
Packit Service f95697
	}
Packit Service f95697
	sub local_rd_values { ($_[0]->{rdn}, $_[0]->{sod}, 0) }
Packit Service f95697
}
Packit Service f95697
Packit Service f95697
require_ok "DateTime::TimeZone::Tzfile";
Packit Service f95697
Packit Service f95697
my $tz;
Packit Service f95697
Packit Service f95697
sub try($$) {
Packit Service f95697
	my($timespec, $offset) = @_;
Packit Service f95697
	$timespec =~ /\A([0-9]{4})-([0-9]{2})-([0-9]{2})T
Packit Service f95697
			([0-9]{2}):([0-9]{2}):([0-9]{2})\z/x or die;
Packit Service f95697
	my $dt = FakeLocalDateTime->new("$1", "$2", "$3", "$4", "$5", "$6");
Packit Service f95697
	my $errcond;
Packit Service f95697
	unless($offset =~ /\A[-+]?[0-9]+\z/) {
Packit Service f95697
		$errcond = $offset;
Packit Service f95697
		$offset = undef;
Packit Service f95697
	}
Packit Service f95697
	is eval { $tz->offset_for_local_datetime($dt) }, $offset,
Packit Service f95697
		"offset for $timespec";
Packit Service f95697
	unless(defined $offset) {
Packit Service f95697
		like $@, qr#\A
Packit Service f95697
			local\ time\ \Q$timespec\E\ does\ not\ exist
Packit Service f95697
			\ in\ the\ [!-~]+\ timezone\ due\ to\ \Q$errcond\E
Packit Service f95697
		\b#x, "error message for $timespec";
Packit Service f95697
	}
Packit Service f95697
}
Packit Service f95697
Packit Service f95697
$tz = DateTime::TimeZone::Tzfile->new("t/London.tz");
Packit Service f95697
try "1800-01-01T00:00:00", -75;
Packit Service f95697
try "1920-03-28T01:59:59", +0;
Packit Service f95697
try "1920-03-28T02:00:00", "offset change";
Packit Service f95697
try "1920-03-28T02:59:59", "offset change";
Packit Service f95697
try "1920-03-28T03:00:00", +3600;
Packit Service f95697
try "1920-10-25T01:59:59", +3600;
Packit Service f95697
try "1920-10-25T02:00:00", +0;
Packit Service f95697
try "1920-10-25T02:59:59", +0;
Packit Service f95697
try "1920-10-25T03:00:00", +0;
Packit Service f95697
try "1942-04-05T01:59:59", +3600;
Packit Service f95697
try "1942-04-05T02:00:00", "offset change";
Packit Service f95697
try "1942-04-05T02:59:59", "offset change";
Packit Service f95697
try "1942-04-05T03:00:00", +7200;
Packit Service f95697
try "2039-03-27T00:59:59", +0;
Packit Service f95697
try "2039-03-27T01:00:00", "offset change";
Packit Service f95697
try "2039-03-27T01:59:59", "offset change";
Packit Service f95697
try "2039-03-27T02:00:00", +3600;
Packit Service f95697
try "2039-10-30T00:59:59", +3600;
Packit Service f95697
try "2039-10-30T01:00:00", +0;
Packit Service f95697
try "2039-10-30T01:59:59", +0;
Packit Service f95697
try "2039-10-30T02:00:00", +0;
Packit Service f95697
Packit Service f95697
# The Davis base in Antarctica has been uninhabited at times.
Packit Service f95697
$tz = DateTime::TimeZone::Tzfile->new("t/Davis.tz");
Packit Service f95697
try "1953-07-01T12:00:00", "zone disuse";
Packit Service f95697
try "1957-01-13T06:59:59", "zone disuse";
Packit Service f95697
try "1957-01-13T07:00:00", +25200;
Packit Service f95697
try "1960-01-01T12:00:00", +25200;
Packit Service f95697
try "1964-10-31T23:59:59", +25200;
Packit Service f95697
try "1964-11-01T00:00:00", "zone disuse";
Packit Service f95697
try "1967-01-01T12:00:00", "zone disuse";
Packit Service f95697
try "1969-02-01T06:59:59", "zone disuse";
Packit Service f95697
try "1969-02-01T07:00:00", +25200;
Packit Service f95697
try "1980-01-01T12:00:00", +25200;
Packit Service f95697
try "2009-10-17T23:59:59", +25200;
Packit Service f95697
try "2009-10-18T00:00:00", +18000;
Packit Service f95697
try "2010-01-01T12:00:00", +18000;
Packit Service f95697
try "2010-03-11T00:59:59", +18000;
Packit Service f95697
try "2010-03-11T01:00:00", "offset change";
Packit Service f95697
try "2010-03-11T02:59:59", "offset change";
Packit Service f95697
try "2010-03-11T03:00:00", +25200;
Packit Service f95697
try "2011-01-01T12:00:00", +25200;
Packit Service f95697
Packit Service f95697
# This version of San_Luis.tz has no POSIX-TZ extension rule, because
Packit Service f95697
# the source data ends with an indefinite-future observance that is on
Packit Service f95697
# DST, and that can't be expressed in a POSIX-TZ recipe.  The correct
Packit Service f95697
# interpretation of the tzfile is that the zone behaviour is unknown
Packit Service f95697
# after the final transition time.
Packit Service f95697
$tz = DateTime::TimeZone::Tzfile->new("t/San_Luis.tz");
Packit Service f95697
try "2008-01-01T12:00:00", -7200;
Packit Service f95697
try "2008-01-20T22:59:59", -7200;
Packit Service f95697
try "2008-01-20T23:00:00", -10800;
Packit Service f95697
try "2008-02-01T12:00:00", -10800;
Packit Service f95697
try "2008-03-08T22:59:59", -10800;
Packit Service f95697
try "2008-03-08T23:00:00", -14400;
Packit Service f95697
try "2008-06-01T12:00:00", -14400;
Packit Service f95697
try "2008-10-11T23:59:59", -14400;
Packit Service f95697
try "2008-10-12T00:00:00", "offset change";
Packit Service f95697
try "2008-10-12T00:59:59", "offset change";
Packit Service f95697
try "2008-10-12T01:00:00", -10800;
Packit Service f95697
try "2009-01-01T12:00:00", -10800;
Packit Service f95697
try "2009-03-07T22:59:59", -10800;
Packit Service f95697
try "2009-03-07T23:00:00", -14400;
Packit Service f95697
try "2009-06-01T12:00:00", -14400;
Packit Service f95697
try "2009-10-10T23:59:59", -14400;
Packit Service f95697
try "2009-10-11T00:00:00", "missing data";
Packit Service f95697
try "2010-01-01T12:00:00", "missing data";
Packit Service f95697
Packit Service f95697
# Loyston was settled in the early 19th century and ultimately abandoned
Packit Service f95697
# in 1936 to make way for the Norris Lake.  This tzfile is not from the
Packit Service f95697
# Olson database.  It's here to test the handling of a presently-disused
Packit Service f95697
# zone.
Packit Service f95697
$tz = DateTime::TimeZone::Tzfile->new("t/Loyston.tz");
Packit Service f95697
try "1799-01-01T12:00:00", "zone disuse";
Packit Service f95697
try "1799-12-31T18:24:15", "zone disuse";
Packit Service f95697
try "1799-12-31T18:24:16", -20144;
Packit Service f95697
try "1840-01-01T12:00:00", -20144;
Packit Service f95697
try "1883-11-18T11:24:15", -20144;
Packit Service f95697
try "1883-11-18T11:24:16", "offset change";
Packit Service f95697
try "1883-11-18T11:59:59", "offset change";
Packit Service f95697
try "1883-11-18T12:00:00", -18000;
Packit Service f95697
try "1900-01-01T12:00:00", -18000;
Packit Service f95697
try "1918-03-31T01:59:59", -18000;
Packit Service f95697
try "1918-03-31T02:00:00", "offset change";
Packit Service f95697
try "1918-03-31T02:59:59", "offset change";
Packit Service f95697
try "1918-03-31T03:00:00", -14400;
Packit Service f95697
try "1918-07-01T12:00:00", -14400;
Packit Service f95697
try "1918-10-27T00:59:59", -14400;
Packit Service f95697
try "1918-10-27T01:00:00", -18000;
Packit Service f95697
try "1919-01-01T12:00:00", -18000;
Packit Service f95697
try "1919-03-30T01:59:59", -18000;
Packit Service f95697
try "1919-03-30T02:00:00", "offset change";
Packit Service f95697
try "1919-03-30T02:59:59", "offset change";
Packit Service f95697
try "1919-03-30T03:00:00", -14400;
Packit Service f95697
try "1919-07-01T12:00:00", -14400;
Packit Service f95697
try "1919-10-26T00:59:59", -14400;
Packit Service f95697
try "1919-10-26T01:00:00", -18000;
Packit Service f95697
try "1930-01-01T12:00:00", -18000;
Packit Service f95697
try "1936-03-03T23:59:59", -18000;
Packit Service f95697
try "1936-03-04T00:00:00", "zone disuse";
Packit Service f95697
try "1937-01-01T12:00:00", "zone disuse";
Packit Service f95697
Packit Service f95697
1;