diff --git a/Sunrise.pm b/Sunrise.pm index 79973b6..0bae9e2 100644 --- a/Sunrise.pm +++ b/Sunrise.pm @@ -615,6 +615,7 @@ sub sun_rise my $offset = int( shift || 0 ); my $today = DateTime->today->set_time_zone( 'local' ); + $today->set( hour => 12 ); $today->add( days => $offset ); my( $sun_rise, undef ) = sunrise( $today->year, $today->mon, $today->mday, @@ -667,6 +668,7 @@ sub sun_set my $offset = int( shift || 0 ); my $today = DateTime->today->set_time_zone( 'local' ); + $today->set( hour => 12 ); $today->add( days => $offset ); my( undef, $sun_set ) = sunrise( $today->year, $today->mon, $today->mday, diff --git a/t/03dst.t b/t/03dst.t new file mode 100755 index 0000000..13b20af --- /dev/null +++ b/t/03dst.t @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w +# -*- perl -*- + +# +# Author: Slaven Rezic +# + +use strict; +use Test::More; + +if (!eval q{ require Time::Fake; 1;}) { + print "1..0 # skip no Time::Fake module\n"; + exit; +} + +my @tests = ( + [1288545834, 'sun_rise', '07:00'], + [1288545834, 'sun_set', '16:39'], + + [1269738800, 'sun_rise', '06:49'], + [1269738800, 'sun_set', '19:33'], + ); + +plan tests => scalar @tests; + +for my $test (@tests) { + my($epoch, $func, $expected) = @$test; + my @cmd = ($^X, "-Mblib", "-MTime::Fake=$epoch", "-MAstro::Sunrise", "-e", "print $func(13.5,52.5)"); + open my $fh, "-|", @cmd or die $!; + local $/; + my $res = <$fh>; + close $fh or die "Failure while running @cmd: $!"; + is $res, $expected, "Check for $func at $epoch"; +} + +__END__