Astro-Coords

 view release on metacpan or  search on metacpan

t/riseset.t  view on Meta::CPAN

#!perl

# Test script for rise and set times
# Test using both DateTime and Time::Piece

use strict;
use Test::More tests => 295;
use Test::Number::Delta;
use Time::Piece qw/ :override /;
use DateTime;
use DateTime::TimeZone;

# Need this since the constants from Astro::Coords will
# not be defined if we only require
BEGIN { use_ok('Astro::Coords') };
require_ok('Astro::PAL');
require_ok('Astro::Telescope');

# reference time zones
my $UTC = new DateTime::TimeZone( name => 'UTC');
my $HST = new DateTime::TimeZone( name => 'US/Hawaii');

# telescope
my $tel = new Astro::Telescope( 'JCMT' );

# reference time (basically locks us into a day)
# Wed Jul 15 14:46:44 2003 UT
my $epoch = 1058280404;
my $timepiece = gmtime( $epoch );
my $datetime  = DateTime->from_epoch( epoch => $epoch );

for my $date ($timepiece, $datetime) {

  # The Sun
  my $c = new Astro::Coords( planet => 'sun' );
  $c->datetime( $date );
  $c->telescope( $tel );

#print $c->status;

# According to http://aa.usno.navy.mil/cgi-bin/aa_pap.pl
# [http://aa.usno.navy.mil/data/]
# Long = -155 29 Lat = 19 49
# Sun set is 19:04 and civil twilight is 19:28
# Sun rise is 05:51 and civil twilight start is 05:27
# Midday is 12:28  [22:28 UT]

  my $mtime = $c->meridian_time();
  my $civtwiri = $c->rise_time( horizon => Astro::Coords::CIVIL_TWILIGHT );
  my $rise = $c->rise_time( horizon => Astro::Coords::SUN_RISE_SET );
  my $set  = $c->set_time( horizon => Astro::Coords::SUN_RISE_SET );
  my $civtwi = $c->set_time( horizon => Astro::Coords::CIVIL_TWILIGHT );

  print "# SUN:\n";
  print "#  Local start civil twi:" . localtime($civtwiri->epoch)."\n";
  test_time( $civtwiri, [2003,7,15,5,27], "Civil twilight start", $HST);

  print "#  Local Rise time:      " . localtime($rise->epoch) ."\n";
  test_time( $rise, [2003,7,15,5, 51], "Sun rise", $HST);

  print "#  Local Transit time:   " . localtime($mtime->epoch) ."\n";
  test_time( $mtime, [2003,7,15,12,28],"Noon", $HST);

  print "#  Local Set time:       " . localtime($set->epoch) ."\n";
  test_time( $set, [2003,7,15,19,4], "Sun set", $HST);

  print "#  Local end Civil twi:  " . localtime($civtwi->epoch) ."\n";
  test_time( $civtwi, [2003,7,15,19,28], "Civil twilight end", $HST);

  print $c->status;

# Now try the moon
# USNO:
#       Moonrise                  20:27 on preceding day
#       Moon transit              02:05
#       Moonset                   07:46
#       Moonrise                  21:13
#       Moonset                   08:45 on following day

  my $moon = new Astro::Coords( planet => 'moon');
  $moon->datetime( $date );
  $moon->telescope( $tel );

  $mtime = $moon->meridian_time(nearest=>1);

  # use the default horizon for the moon
  $rise = $moon->rise_time();
  $set  = $moon->set_time();



( run in 1.420 second using v1.01-cache-2.11-cpan-98e64b0badf )