BozoJoe
BozoJoe

Reputation: 6462

Why does Perl's DateTime::Astro::Sunrise give me unexpected values?

Using the example code included in the man page for DateTime::Astro::Sunrise, I'm getting back ~14:00 for the sunrise and ~2:00 for the sunset.

My machine's time and timezone are set correctly (AFAIK).

Am I reading something wrong? 2am and 2pm are just so brutually wrong.

use DateTime;
use DateTime::Astro::Sunrise;

my $dt = DateTime->new( year   => 2010,
                                month  => 3,
                                day    => 15,
                         );
my $sunrise = DateTime::Astro::Sunrise ->new('-117','33',undef,1);

my ($tmp_rise, $tmp_set) = $sunrise->sunrise($dt);

printf "%s\n", $tmp_rise;
printf "%s\n", $tmp_set;

Upvotes: 0

Views: 740

Answers (2)

hobbs
hobbs

Reputation: 240512

At a guess, you've got the wrong sign on your longitude, so you're getting the sunrise/sunset times for Shanghai (which are about 6AM and 6PM Shanghai time right now), but you're getting the times in California time that the sun rises and sets in Shanghai, since that's your local timezone. Difference is 16 hours, so you get 2PM and 2AM.

Upvotes: 2

Gavin Brock
Gavin Brock

Reputation: 5087

Sorry, without any sample code, I can't say what you are doing wrong.

An alternative, Astro::Sunrise has been working well for me, and appears to be slightly more mature.

Upvotes: 1

Related Questions