#!/usr/bin/perl # Version: # 0.1.0 - 1/29/4 - Original creation. Smart enough to parse itself for # the data. # 0.2.0 - 2/1/4 - Compares dates and can find next solstice - this year # or next # 0.3.0 - 6/21/4 - Finds days until next solstice. # # ToDo: # [X] Add support for Equinoxes and Winter Solstice. # [_] Add support for time until solstice, equinox, etc... # [X] Test the retrieved dates to see if we have passed the current dates # and need to look into the next year. (We always want to display the # *next* Solstice, equinox, etc... print "All times are GMT.\n"; $tnow = time(); @tanow = localtime($tnow); #print "Local --------------------------------\n"; #print "Time now: ", scalar localtime($tnow), "\n"; #print " -> Year: ", $tanow[5] + 1900, "\n"; #print " -> Month: ", $tanow[4], "\n"; #print " -> Day: ", $tanow[3], "\n"; #print " -> Hour: ", $tanow[2], "\n"; #print " -> Min: ", $tanow[1], "\n"; #print "GMT ----------------------------------\n"; @tanow = gmtime($tnow); print "Time now: ", scalar gmtime($tnow), "\n"; #print " -> Year: ", $tanow[5] + 1900, "\n"; #print " -> Month: ", $tanow[4], "\n"; #print " -> Day: ", $tanow[3], "\n"; #print " -> Hour: ", $tanow[2], "\n"; #print " -> Min: ", $tanow[1], "\n"; my $inyear = 0; my $yoffset = 0; my $ytm = $tanow[5] + 1900; my %thisssol; my %nextssol; my %thiswsol; my %nextwsol; my %thisseqn; my %nextseqn; my %thisfeqn; my %nextfeqn; while() { if (/^$ytm.*$ytm/) { $inyear = 1; } if($inyear) { if (/^$/) { $inyear = 0; if($yoffset == 0) { $ytm++; } $yoffset++; } else { if ( /^Aphelion/ ) { my ($aname, $amonth, $aday, $ahour, $sname, $smonth, $sday, $shour, $smin, $wmonth, $wday, $whour, $wmin) = split /\s+/; if($yoffset == 0) { $thisssol{"day"} = $sday; $thisssol{"hour"} = $shour; $thisssol{"min"} = $smin; $thiswsol{"day"} = $wday; $thiswsol{"hour"} = $whour; $thiswsol{"min"} = $wmin; } else { $nextssol{"day"} = $sday; $nextssol{"hour"} = $shour; $nextssol{"min"} = $smin; $nextwsol{"day"} = $wday; $nextwsol{"hour"} = $whour; $nextwsol{"min"} = $wmin; } #print "Winter: Dec ", $wday, " ", $whour, ":", $wmin, "\n"; #print "Summer: June ", $sday, " ", $shour, ":", $smin, "\n"; } if ( /^Perihelion/ ) { my ($aname, $amonth, $aday, $ahour, $ename, $smonth, $sday, $shour, $smin, $fmonth, $fday, $fhour, $fmin) = split /\s+/; if($yoffset == 0) { $thisseqn{"day"} = $sday; $thisseqn{"hour"} = $shour; $thisseqn{"min"} = $smin; $thisfeqn{"day"} = $fday; $thisfeqn{"hour"} = $fhour; $thisfeqn{"min"} = $fmin; } else { $nextseqn{"day"} = $sday; $nextseqn{"hour"} = $shour; $nextseqn{"min"} = $smin; $nextfeqn{"day"} = $fday; $nextfeqn{"hour"} = $fhour; $nextfeqn{"min"} = $fmin; } #print "Fall : Sept ", $fday, " ", $fhour, ":", $fmin, "\n"; #print "Spring: Mar ", $sday, " ", $shour, ":", $smin, "\n"; } } } } print "Finding next Spring Equinox : "; my $ncomp = mkcompare($tanow[4], $tanow[3], $tanow[2], $tanow[2]); my $scomp = mkcompare(2, $thisseqn{"day"}, $thisseqn{"hour"}, $thisseqn{"min"});if($ncomp >= $scomp) { print $nextseqn{"hour"}, ":",$nextseqn{"min"}, " on Mar ", $nextseqn{"day"}, ", ", $tanow[5] + 1901, "\n"; } else { print $thisseqn{"hour"}, ":",$thisseqn{"min"}, " on Mar ", $thisseqn{"day"}, ", ", $tanow[5] + 1900, "\n"; } print "Finding next Summer Solstice: "; my $ncomp = mkcompare($tanow[4], $tanow[3], $tanow[2], $tanow[2]); my $scomp = mkcompare(5, $thisssol{"day"}, $thisssol{"hour"}, $thisssol{"min"});if($ncomp >= $scomp) { print $nextssol{"hour"}, ":",$nextssol{"min"}, " on Jun ", $nextssol{"day"}, ", ", $tanow[5] + 1901, "\n"; } else { print $thisssol{"hour"}, ":",$thisssol{"min"}, " on Jun ", $thisssol{"day"}, ", ", $tanow[5] + 1900, "\n"; } print "Finding next Fall Equinox : "; my $ncomp = mkcompare($tanow[4], $tanow[3], $tanow[2], $tanow[2]); my $scomp = mkcompare(8, $thisfeqn{"day"}, $thisfeqn{"hour"}, $thisfeqn{"min"});if($ncomp >= $scomp) { print $nextfeqn{"hour"}, ":",$nextfeqn{"min"}, " on Sep ", $nextfeqn{"day"}, ", ", $tanow[5] + 1901, "\n"; } else { print $thisfeqn{"hour"}, ":",$thisfeqn{"min"}, " on Sep ", $thisfeqn{"day"}, ", ", $tanow[5] + 1900, "\n"; } print "Finding next Winter Solstice: "; my $ncomp = mkcompare($tanow[4], $tanow[3], $tanow[2], $tanow[2]); my $scomp = mkcompare(11, $thiswsol{"day"}, $thiswsol{"hour"}, $thiswsol{"min"});if($ncomp >= $scomp) { print $nextwsol{"hour"}, ":",$nextwsol{"min"}, " on Dec ", $nextwsol{"day"}, ", ", $tanow[5] + 1901, "\n"; } else { print $thiswsol{"hour"}, ":",$thiswsol{"min"}, " on Dec ", $thiswsol{"day"}, ", ", $tanow[5] + 1900, "\n"; } # ------------------------------------------------------------ my $dts = 0; if( $tanow[4] == 0 ) { # Jan Mar Apr May June $dts = (31 - $tanow[3]) + 31 + 30 + 31 + $thisssol{"day"}; if( 0 == $tanow[5] % 4) { $dts = $dts + 29; } else { $dts = $dts + 28; } print $dts, " days till the Summer (next) solstice.\n"; } if( $tanow[4] == 1 ) { # Mar Apr May June $dts = (31 - $tanow[3]) + 30 + 31 + $thisssol{"day"}; if( 0 == $tanow[5] % 4) { $dts = $dts + 29; } else { $dts = $dts + 28; } print $dts, " days till the Summer (next) solstice.\n"; } if( $tanow[4] == 2 ) { # Mar Apr May June $dts = (31 - $tanow[3]) + 30 + 31 + $thisssol{"day"}; print $dts, " days till the Summer (next) solstice.\n"; } if( $tanow[4] == 3 ) { # Apr May June $dts = (30 - $tanow[3]) + 31 + $thisssol{"day"}; print $dts, " days till the Summer (next) solstice.\n"; } if( $tanow[4] == 4 ) { # May June $dts = (31 - $tanow[3]) + $thisssol{"day"}; print $dts, " days till the Summer (next) solstice.\n"; } if( $tanow[4] == 5 ) { if( $tanow[3] >= $thisssol{"day"} ) { # June + Jul+ Aug+ Sep+ Oct+ Nov+ Dec $dts = (30 - $tanow[3]) + 31 + 31 + 30 + 31 + 30 + $thiswsol{"day"}; print $dts, " days till the Winter (next) solstice.\n"; } else { print $thisssol{"day"} - $tanow[3], " days till the Summer (next) solstice.\n"; } } if( $tanow[4] == 6 ) { # Jul + Aug+ Sep+ Oct+ Nov+ Dec $dts = (31 - $tanow[3]) + 31 + 30 + 31 + 30 + $nextwsol{"day"}; print $dts, " days till the Winter (next) solstice.\n"; } if( $tanow[4] == 7 ) { # Aug + Sep+ Oct+ Nov+ Dec $dts = (31 - $tanow[3]) + 30 + 31 + 30 + $nextwsol{"day"}; print $dts, " days till the Winter (next) solstice.\n"; } if( $tanow[4] == 8 ) { # Sep + Oct+ Nov+ Dec $dts = (30 - $tanow[3]) + 31 + 30 + $nextwsol{"day"}; print $dts, " days till the Winter (next) solstice.\n"; } if( $tanow[4] == 9 ) { # Oct + Nov+ Dec $dts = (31 - $tanow[3]) + 30 + $nextwsol{"day"}; print $dts, " days till the Winter (next) solstice.\n"; } if( $tanow[4] == 10 ) { # Nov + Dec $dts = (30 - $tanow[3]) + $nextwsol{"day"}; print $dts, " days till the Winter (next) solstice.\n"; } if( $tanow[4] == 11 ) { if( $tanow[3] >= $thiwssol{"day"} ) { # Dec + Jan+ Mar+ Apr+ May+ Jun $dts = (31 - $tanow[3]) + 31 + 31 + 30 + 31 + $nextssol{"day"}; if( 0 == ($tanow[5] + 1) % 4) { $dts = $dts + 29; } else { $dts = $dts + 28; } print $dts, " days till the Summer (next) solstice.\n"; } else { print $thiswsol{"day"} - $tanow[3], " days till the Winter (next) solstice.\n"; } } # ------------------------------------------------------------ sub mkcompare { my ($month, $day, $hour, $min) = @_; my $total = 0; $total = $month * 31; # The most a month has is 31 days (so they all do). $total = $total + $day; $total = $total * 24; $total = $total + $hour; $total = $total * 60; $total = $total + $min; $total; } ##################################################################### __END__ Perihelion - Sun is closest to earth in elliptical orbit Aphelion - Sun is most distant from earth in elliptical orbit Equinoxes - Sun rises in East, Sets in West, is in sky 12 hours Solstices - "Sun stands still", on longest or shortest day of year Times are day hour min in GMT (aka UT) 2004 2004 Perihelion Jan 4 18 Equinoxes Mar 20 06 49 Sept 22 16 30 Aphelion July 5 11 Solstices June 21 00 57 Dec 21 12 42 2005 2005 Perihelion Jan 2 01 Equinoxes Mar 20 12 33 Sept 22 22 23 Aphelion July 5 05 Solstices June 21 06 46 Dec 21 18 35 2006 2006 Perihelion Jan 4 15 Equinoxes Mar 20 18 26 Sept 23 04 03 Aphelion July 3 23 Solstices June 21 12 26 Dec 22 00 22 2007 2007 Perihelion Jan 3 20 Equinoxes Mar 21 00 07 Sept 23 09 51 Aphelion July 7 00 Solstices June 21 18 06 Dec 22 06 08 2008 2008 Perihelion Jan 3 00 Equinoxes Mar 20 05 48 Sept 22 15 44 Aphelion July 4 08 Solstices June 20 23 59 Dec 21 12 04 2009 2009 Perihelion Jan 4 15 Equinoxes Mar 20 11 44 Sept 22 21 18 Aphelion July 4 02 Solstices June 21 05 45 Dec 21 17 47 2010 2010 Perihelion Jan 3 00 Equinoxes Mar 20 17 32 Sept 23 03 09 Aphelion July 6 11 Solstices June 21 11 28 Dec 21 23 38 2011 2011 Perihelion Jan 3 19 Equinoxes Mar 20 23 21 Sept 23 09 04 Aphelion July 4 15 Solstices June 21 17 16 Dec 22 05 30 2012 2012 Perihelion Jan 5 00 Equinoxes Mar 20 05 14 Sept 22 14 49 Aphelion July 5 03 Solstices June 20 23 09 Dec 21 11 11 2013 2013 Perihelion Jan 2 05 Equinoxes Mar 20 11 02 Sept 22 20 44 Aphelion July 5 15 Solstices June 21 05 04 Dec 21 17 11 2014 2014 Perihelion Jan 4 12 Equinoxes Mar 20 16 57 Sept 23 02 29 Aphelion July 4 00 Solstices June 21 10 51 Dec 21 23 03 2015 2015 Perihelion Jan 4 07 Equinoxes Mar 20 22 45 Sept 23 08 20 Aphelion July 6 19 Solstices June 21 16 38 Dec 22 04 48 2016 2016 Perihelion Jan 2 23 Equinoxes Mar 20 04 30 Sept 22 14 21 Aphelion July 4 16 Solstices June 20 22 34 Dec 21 10 44 2017 2017 Perihelion Jan 4 14 Equinoxes Mar 20 10 28 Sept 22 20 02 Aphelion July 3 20 Solstices June 21 04 24 Dec 21 16 28 2018 2018 Perihelion Jan 3 06 Equinoxes Mar 20 16 15 Sept 23 01 54 Aphelion July 6 17 Solstices June 21 10 07 Dec 21 22 22 2019 2019 Perihelion Jan 3 05 Equinoxes Mar 20 21 58 Sept 23 07 50 Aphelion July 4 22 Solstices June 21 15 54 Dec 22 04 19 2020 2020 Perihelion Jan 5 08 Equinoxes Mar 20 03 49 Sept 22 13 30 Aphelion July 4 12 Solstices June 20 21 43 Dec 21 10 02