DateTime-Util-Astro

 view release on metacpan or  search on metacpan

lib/DateTime/Util/Astro/Common.pm  view on Meta::CPAN

    standard_from_universal(dt_from_moment(
        universal_from_local($dt, $location)), $location);
}

# p.170
sub local_from_standard
{
    my($dt, $location) = @_;
    local_from_universal(dt_from_moment(
        universal_from_standard($dt, $location)), $location);
}

# p.169
sub local_from_universal
{
    my($dt, $location) = @_;
    moment($dt) + $location->longitude / 360;
}
# p.169
sub universal_from_local
{
    my($dt, $location) = @_;
    moment($dt) - $location->longitude / 360;
}

# [1] p172
sub dynamical_moment_from_dt
{
    my $dt = shift;
    return moment($dt) + ephemeris_correction($dt);
}

sub dt_from_dynamical
{
    my $t = shift;

    return dt_from_moment(
        $t - ephemeris_correction(dt_from_moment($t)));
}


# [1] p180
sub obliquity
{
    my $dt = shift;
    my $c  = julian_centuries($dt);
    return polynomial($c,
        angle(23, 26, 21.448),
        -1 * angle(0, 0, 46.8150),
        -1 * angle(0, 0, 0.00059),
        angle(0, 0, 0.001813)
    );
}

# [1] p171 + errata 158
my %EC;
sub ephemeris_correction
{
    my $dt = shift;

    # we need a gregorian calendar, so make sure $dt is just 'DateTime'
    if (ref($dt) ne 'DateTime') {
        $dt = DateTime->from_object(object => $dt);
    }

    my $year = $dt->year;
    my $correction = $EC{ $year };
    if (! $correction) {
        if (1988 <= $year && $year <= 2019) {
            $correction = EC1($year - 1933);
        } elsif (1900 <= $year && $year <= 1987) {
            $correction = EC2( EC_C($year) );
        } elsif (1800 <= $year && $year <= 1899) {
            $correction = EC3( EC_C($year) );
        } elsif (1700 <= $year && $year <= 1799) {
            $correction = EC4($year - 1700);
        } elsif (1620 <= $year && $year <= 1699) {
            $correction = EC5($year - 1600);
        } else {
            $correction = EC6( EC_X($year) );
        }
        $EC{ $year } = $correction;
    }

    return $correction;
}

my %EC_C;
sub EC_C
{
    # This value is constant for a given year
    my $value = $EC_C{ $_[0] };
    if (! defined $value) {
        my $top = (
            (DateTime->new(
                year => $_[0],
                month => 7,
                day => 1,
                time_zone => 'UTC'
            )->utc_rd_values)[0]
            -
            RD_MOMENT_1900_JAN_1
        );
        $value = $top / 36525;
        $EC_C{ $_[0] } = $value;
    }
    return $value;
}

my %EC_X;
sub EC_X
{
    my $value = $EC_X{ $_[0] };
    if (! defined $value) {
        $value = (
            (DateTime->new(
                year => $_[0],
                month => 1,
                day => 1,
                time_zone => 'UTC'
            )->utc_rd_values)[0]

lib/DateTime/Util/Astro/Common.pm  view on Meta::CPAN

{
    my $self = shift;
    my $ret = $self->{%s};
    if (@_) {
        my $val = shift;
        $self->{%s} = $val;
    }
    return $ret;
}
EOM
        die if $@;
    }
}

1;

__END__

=head1 NAME

DateTime::Util::Astro::Common - Common Utilities For Astronomical Calendar Calculations

=head1 SYNOPSIS

  use DateTime::Util::Astro::Common qw(
    aberration
    dt_from_dynamical
    dynamical_moment_from_dt
    ephemeris_correction
    equation_of_time
    julian_centuries
    local_from_apparent 
    nutation
    obliquity
    standard_from_local
    standard_from_universal
    universal_from_local
    universal_from_standard
    SPRING
    SUMMER
    AUTUMN
    WINTER
    MEAN_TROPICAL_YEAR
    RD_MOMENT_1900_JAN_1
    RD_MOMENT_1810_JAN_1
    RD_MOMENT_J2000
  );

  my $location = DateTime::Util::Astro::Location->new(
    longitude => $longitude,
    latitude  => $latitude,
    zone      => $zone,
    elevation => $elevation
  );

=head1 DESCRIPTION

DateTime::Util::Astro::Location implements some functions that are commonly
used for astronomical calculations. As with other DateTime::Util::Astro::
modules this module only implements the bare minimum required to make
astronomical calendars.

=head1 FUNCTIONS

=head2 aberration($dt)

Calculates the effect of the sun's moving during the time its light takes
takes to reach the Earth

=head2 dt_from_dynamical($moment)

=head2 dynamical_moment_from_dt($dt)

=head2 julian_centuries($moment)

The number and fraction of uniform-length centuries at a given moment.

=head2 ephemeris_correction($dt)

Calculates the offset from "dynamical time", which is caused by the
retarding effects of tide and other atmospheric conditions.

=head2 EC_C

=head2 EC_X

=head2 EC1

=head2 EC2

=head2 EC3

=head2 EC4

=head2 EC5

=head2 EC6

These are used to calculate the ephemeris_correction.

=head2 equation_of_time($dt)

Calculates the difference between "apparent midnight" and the "mean midnight"

=head2 julian_centuris($dt)

Calculates the fractional number of centuries since January 1, 2000 (Gregorian).

=head2 local_from_apparent($dt)

=head2 nutation($dt)

Calculates the effect caused by the wobble of the Earth.

=head2 obliquity($)

Calculates the inclination of th Earth

=head2 local_from_standard($dt, $location)

=head2 local_from_universal($dt, $location)



( run in 0.514 second using v1.01-cache-2.11-cpan-39bf76dae61 )