Re: DateTime->season?

[email protected] (Eugene van der Pijll)
Newsgroups perl.datetime
Message-ID <[email protected]>
Zefram schreef:
> Sounds like you're looking for the equinox and solstice dates.  I don't
> see any CPAN module providing this, on search.cpan.org.

Take a look at the DateTime::Util::Astro modules. solar_longitude_before
and _after are useful to look for equinoxes and solstices, but you don't
need those to determine the season.

I would guess that something like

  use DateTime::Util::Astro::Sun;

  my $dt = DateTime->now;
  my $sl = DateTime::Util::Astro::Sun::solar_longitude($dt);

  if ($sl < 90) {
    print 'spring';
  } elsif ($sl < 180) {
    print 'summer';
  } elsif ($sl < 270) {
    print 'autumn';
  } else {
    print 'winter';
  }

would work (for the Northern Hemisphere).

Eugene
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.