#!/usr/bin/perl use warnings; use strict; use 5.010; use Astro::Utils; use DateTime; use DateTime::Event::Sunrise; use DateTime::Format::Strptime; use DateTime::Format::Human::Duration; my $LONG = -122.5; # E = +, W = - my $LAT = 45; # N = +, S = - my $ZONE = 'America/Los_Angeles'; for my $sun_height ( 0, -0.833, -6, -12, -18 ) { my $sun = DateTime::Event::Sunrise->new( precise => 1, longitude => $LONG, latitude => $LAT, altitude => $sun_height ); say "sun height is $sun_height"; my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S', time_zone => 'UTC', on_error => 'croak' ); my $durfmt = DateTime::Format::Human::Duration->new(); print "At " . abs($LAT) . ( $LAT > 0 ? "N" : "S" ) . " " . abs($LONG) . ( $LONG > 0 ? "E" : "W" ) . ":\n"; my $now_year = DateTime->now->year; for my $year ($now_year) { print " In $year:\n"; my @seas = ( [ 'Spring', 'March equinox', calculate_equinox( 'mar', 'utc', $year ) ], [ 'Summer', 'June solstice', calculate_solstice( 'jun', 'utc', $year ) ], [ 'Fall', 'September equinox', calculate_equinox( 'sep', 'utc', $year ) ], [ 'Winter', 'December solstice', calculate_solstice( 'dec', 'utc', $year ) ], ); for my $seas (@seas) { my ( $sname, $when, $start ) = @$seas; $start = $strp->parse_datetime($start); $start->set_time_zone($ZONE); my $rise = $sun->sunrise_datetime($start); my $set = $sun->sunset_datetime($start); my $dur = $durfmt->format_duration_between( $rise, $set ); print " $sname begins on the $when at ", $start->strftime('%Y-%m-%d %H:%M:%S %Z'), ".\n"; print " Sunrise is at ", $rise->strftime('%H:%M:%S %Z'), ", sunset is at ", $set->strftime('%H:%M:%S %Z'), ",\n"; print " and the day is $dur long.\n"; } } } #### C:\Users\Fred\Desktop>perl astro5.pl sun height is 0 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 07:15:36 PDT, sunset is at 19:17:02 PDT, and the day is 12 hours, 1 minute, and 26 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 05:27:45 PDT, sunset is at 20:53:24 PDT, and the day is 15 hours, 25 minutes, and 39 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 07:02:13 PDT, sunset is at 18:58:39 PDT, and the day is 11 hours, 56 minutes, and 26 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 07:50:12 PST, sunset is at 16:24:55 PST, and the day is 8 hours, 34 minutes, and 43 seconds long. sun height is -0.833 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 07:10:53 PDT, sunset is at 19:21:45 PDT, and the day is 12 hours, 10 minutes, and 52 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 05:22:01 PDT, sunset is at 20:59:08 PDT, and the day is 15 hours, 37 minutes, and 7 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 06:57:30 PDT, sunset is at 19:03:21 PDT, and the day is 12 hours, 5 minutes, and 51 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 07:44:32 PST, sunset is at 16:30:35 PST, and the day is 8 hours, 46 minutes, and 3 seconds long. sun height is -6 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 06:41:38 PDT, sunset is at 19:51:05 PDT, and the day is 13 hours, 9 minutes, and 27 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 04:44:34 PDT, sunset is at 21:36:35 PDT, and the day is 16 hours, 52 minutes, and 1 second long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 06:28:12 PDT, sunset is at 19:32:35 PDT, and the day is 13 hours, 4 minutes, and 23 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 07:10:39 PST, sunset is at 17:04:27 PST, and the day is 9 hours, 53 minutes, and 48 seconds long. sun height is -12 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 06:07:16 PDT, sunset is at 20:25:33 PDT, and the day is 14 hours, 18 minutes, and 17 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 03:54:46 PDT, sunset is at 22:26:23 PDT, and the day is 18 hours, 31 minutes, and 37 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 05:53:49 PDT, sunset is at 20:06:52 PDT, and the day is 14 hours, 13 minutes, and 3 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 06:33:22 PST, sunset is at 17:41:44 PST, and the day is 11 hours, 8 minutes, and 22 seconds long. sun height is -18 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 05:32:02 PDT, sunset is at 21:00:56 PDT, and the day is 15 hours, 28 minutes, and 54 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 02:48:34 PDT, sunset is at 23:32:32 PDT, and the day is 20 hours, 43 minutes, and 58 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 05:18:36 PDT, sunset is at 20:41:56 PDT, and the day is 15 hours, 23 minutes, and 20 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 05:57:35 PST, sunset is at 18:17:31 PST, and the day is 12 hours, 19 minutes, and 56 seconds long.