Expected: Rise: 2022-04-01T06:12:04 Set: 2022-04-01T18:34:16 (Pacific/Auckland)

I am wondering where you're getting these from, since they don't seem to match any information I could find. My results below do match those from timeanddate.com. Even if you fiddle with DateTime::Event::Sunrise's altitude parameter as per "Sun Height" in its documentation, I don't get the same times. For Astro::Coords, the only reference to time zones in its documentation is "A copy of the input argument is created, guaranteeing a UTC representation." - so I figured it's best to just work with UTC inside the module, and only convert to local time zone once one gets the results. I think the slight deviation between the two modules could be because Astro::Coords takes the altitude into account, or some other minor inaccuracy.

use strict; use warnings; use Astro::Coords; use Astro::Telescope; use DateTime::Event::Sunrise; use DateTime; my %params = ( year => 2022, month => 4, day => 1, hour => 0, minute => 1, second => 0, time_zone => 'Pacific/Auckland' ); my $obsDate = DateTime->new(%params); $obsDate->set_time_zone('UTC'); my $tel = Astro::Telescope->new('485'); print "Lat=", $tel->lat('d'), " Lon=", $tel->long('d'), " Alt=", $tel->alt, "\n"; my $cSun = Astro::Coords->new(planet => 'sun'); $cSun->telescope($tel); $cSun->datetime($obsDate); my $sRise = $cSun->rise_time(); my $sSet = $cSun->set_time(); $sRise->set_time_zone('Pacific/Auckland'); $sSet ->set_time_zone('Pacific/Auckland'); print "Rise: ",$sRise->strftime('%FT%T %Z'), " Set: ",$sSet ->strftime('%FT%T %Z'),"\n"; my $sun = DateTime::Event::Sunrise->new( altitude=>-0.833, longitude => $tel->long('d'), latitude => $tel->lat('d') ); $obsDate->add(days=>1); # not sure yet why the two modules differ here my $rise2 = $sun->sunrise_datetime($obsDate); my $set2 = $sun-> sunset_datetime($obsDate); $rise2->set_time_zone('Pacific/Auckland'); $set2 ->set_time_zone('Pacific/Auckland'); print "Rise: ",$rise2->strftime('%FT%T %Z'), " Set: ",$set2 ->strftime('%FT%T %Z'),"\n"; __END__ Lat=-41.2842368910727 Lon=174.7654 Alt=144.005447541833 Rise: 2022-04-01T07:35:56 NZDT Set: 2022-04-01T19:13:17 NZDT Rise: 2022-04-01T07:36:11 NZDT Set: 2022-04-01T19:13:42 NZDT

Update: For Solstice/Equinox, see my script at Re: calculate length of day as function of space at onset of fall.


In reply to Re: Trouble with time zones and Sun rise/set by haukex
in thread Trouble with time zones and Sun rise/set by GrandFather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.