Skip to content

How to calculate sunset? #3

@emosenkis

Description

@emosenkis

I'm trying to use this library to calculate sunset times for locations on Earth on a given date but I don't have a background in astronomy and I can't figure out how to calculate four of the values needed as input to the astro::transit::time function. Here's what I have so far:

extern crate astro;
extern crate chrono;

use astro::coords::GeographPoint;
use astro::time;
use astro::transit::{self, TransitBody, TransitType};
use chrono::{Datelike, Timelike, UTC};

fn main() {
    let coords: (f64, f64) = (40.7128, -74.0059);  // GPS coords of New York City
    let now = UTC::now();
    let day_of_month = time::DayOfMonth {
        day: now.day() as u8,
        hr: now.hour() as u8,
        min: now.minute() as u8,
        sec: now.second() as f64,
        time_zone: 0.0,
    };
    let date = time::Date {
        year: now.year() as i16,                                                                                                     
        month: now.month() as u8,                                                                                                    
        decimal_day: time::decimal_day(&day_of_month),                                                                               
        cal_type: time::CalType::Gregorian,                                                                                          
    };                                                                                                                               
    let julian_day = time::julian_day(&date);                                                                                        
    let delta_t = time::delta_t(date.year as i32, date.month);                                                                       
    let julian_ephm_day = time::julian_ephemeris_day(julian_day, delta_t);                                                           
    let sunset_time = astro::transit::time(&TransitType::Set,
                                           &TransitBody::Sun,
                                           &GeographPoint {
                                               lat: coords.0.to_radians(),
                                               long: coords.1.to_radians(),
                                           },
                                           // How do I calculate the next four args?
                                           eq_point1,
                                           eq_point2,
                                           eq_point3,
                                           apprnt_greenwhich_sidr,
                                           // End of missing args
                                           delta_t,
                                           0f64); // moon_eq_hz_parallax not needed
    println!("{:?}", sunset_time);                                                                                                   
}

Any pointers would be greatly appreciated. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions