CalendarDate

Struct CalendarDate 

Source
pub struct CalendarDate {
    pub year: i32,
    pub month: i32,
    pub day: i32,
    pub hour: i32,
    pub minute: i32,
    pub second: f64,
}
Expand description

Represents a calendar date

Fields§

§year: i32§month: i32§day: i32§hour: i32§minute: i32§second: f64

Implementations§

Source§

impl CalendarDate

Source

pub fn new( year: i32, month: i32, day: i32, hour: i32, minute: i32, second: f64, ) -> Self

Create a new calendar date

Examples found in repository?
examples/time_conversion.rs (line 12)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    println!("=== Time Conversion Examples ===\n");
9
10    // Example 1: Convert calendar date to Julian date
11    println!("Example 1: Calendar to Julian Date");
12    let cal = CalendarDate::new(2024, 1, 15, 12, 0, 0.0);
13    let jd = cal.to_julian()?;
14    println!(
15        "  Calendar: {}-{:02}-{:02} {:02}:{:02}:{:02}",
16        cal.year, cal.month, cal.day, cal.hour, cal.minute, cal.second as i32
17    );
18    println!("  Julian Date: {:.6}\n", jd.as_f64());
19
20    // Example 2: Convert Julian date to calendar date
21    println!("Example 2: Julian to Calendar Date");
22    let jd2 = JulianDate::new(2460327.0); // January 15, 2024
23    let cal2 = jd2.to_calendar();
24    println!("  Julian Date: {:.6}", jd2.as_f64());
25    println!(
26        "  Calendar: {}-{:02}-{:02} {:02}:{:02}:{:02}\n",
27        cal2.year, cal2.month, cal2.day, cal2.hour, cal2.minute, cal2.second as i32
28    );
29
30    // Example 3: Using from_calendar directly
31    println!("Example 3: Direct conversion");
32    let jd3 = JulianDate::from_calendar(2000, 1, 1, 12, 0, 0.0)?;
33    println!("  January 1, 2000 12:00:00 UTC");
34    println!("  Julian Date: {:.6}\n", jd3.as_f64());
35
36    // Example 4: Historical dates
37    println!("Example 4: Historical Dates");
38    let dates = vec![
39        (1969, 7, 20, 20, 17, 0.0, "Apollo 11 Moon Landing"),
40        (1986, 1, 28, 11, 39, 0.0, "Space Shuttle Challenger"),
41        (2021, 7, 20, 9, 13, 0.0, "Blue Origin NS-16"),
42    ];
43
44    for (year, month, day, hour, minute, second, event) in dates {
45        let jd = JulianDate::from_calendar(year, month, day, hour, minute, second)?;
46        println!("  {}: JD {:.6}", event, jd.as_f64());
47    }
48
49    Ok(())
50}
More examples
Hide additional examples
examples/basic_usage.rs (line 55)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    println!("=== Rust JPL Ephemeris Reader - Basic Usage Example ===\n");
13
14    // Initialize the ephemeris from config.toml
15    println!("1. Initializing Ephemeris...");
16    let eph = Ephemeris::new("config.toml")?;
17    println!("   ✓ Ephemeris loaded successfully\n");
18
19    // Display metadata
20    println!("2. Ephemeris Metadata:");
21    let metadata = eph.get_metadata();
22    println!(
23        "   - Date Range: {} - {}",
24        metadata.start_year, metadata.end_year
25    );
26    println!(
27        "   - Julian Date Range: {:.2} - {:.2}",
28        metadata.julian_start, metadata.julian_end
29    );
30    println!("   - Interval: {} days", metadata.interval_days);
31    println!(
32        "   - Earth-Moon Mass Ratio: {:.6}",
33        metadata.earth_moon_ratio
34    );
35    println!(
36        "   - Number of Coefficients: {}\n",
37        metadata.number_of_coefficients
38    );
39
40    // List available bodies
41    println!("3. Available Celestial Bodies:");
42    for body in eph.get_bodies() {
43        let status = if body.active { "✓" } else { "✗" };
44        println!(
45            "   {} {} ({})",
46            status,
47            body.name,
48            if body.active { "active" } else { "inactive" }
49        );
50    }
51    println!();
52
53    // Time conversion example
54    println!("4. Time Conversion Example:");
55    let calendar_date = rust_jpl::CalendarDate::new(2024, 1, 15, 12, 0, 0.0);
56    println!(
57        "   Calendar Date: {}-{:02}-{:02} {:02}:{:02}:{:02}",
58        calendar_date.year,
59        calendar_date.month,
60        calendar_date.day,
61        calendar_date.hour,
62        calendar_date.minute,
63        calendar_date.second as i32
64    );
65
66    let jd = calendar_date.to_julian()?;
67    println!("   Julian Date: {:.6}", jd.as_f64());
68
69    let converted_back = jd.to_calendar();
70    println!(
71        "   Converted back: {}-{:02}-{:02} {:02}:{:02}:{:02}\n",
72        converted_back.year,
73        converted_back.month,
74        converted_back.day,
75        converted_back.hour,
76        converted_back.minute,
77        converted_back.second as i32
78    );
79
80    // Get planetary positions
81    println!(
82        "5. Planetary Positions (at Julian Date {:.6}):",
83        jd.as_f64()
84    );
85    let bodies = [
86        "Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn",
87    ];
88
89    for body_name in &bodies {
90        match eph.get_position(body_name, jd) {
91            Ok(pos) => {
92                println!(
93                    "   {}: ({:12.6}, {:12.6}, {:12.6}) AU, Distance: {:.6} AU",
94                    body_name,
95                    pos.x,
96                    pos.y,
97                    pos.z,
98                    pos.distance()
99                );
100            }
101            Err(e) => {
102                println!("   {}: Error - {}", body_name, e);
103            }
104        }
105    }
106
107    println!("\n=== Example Complete ===");
108    Ok(())
109}
Source

pub fn to_julian(&self) -> Result<JulianDate, Error>

Convert to Julian date

Examples found in repository?
examples/time_conversion.rs (line 13)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    println!("=== Time Conversion Examples ===\n");
9
10    // Example 1: Convert calendar date to Julian date
11    println!("Example 1: Calendar to Julian Date");
12    let cal = CalendarDate::new(2024, 1, 15, 12, 0, 0.0);
13    let jd = cal.to_julian()?;
14    println!(
15        "  Calendar: {}-{:02}-{:02} {:02}:{:02}:{:02}",
16        cal.year, cal.month, cal.day, cal.hour, cal.minute, cal.second as i32
17    );
18    println!("  Julian Date: {:.6}\n", jd.as_f64());
19
20    // Example 2: Convert Julian date to calendar date
21    println!("Example 2: Julian to Calendar Date");
22    let jd2 = JulianDate::new(2460327.0); // January 15, 2024
23    let cal2 = jd2.to_calendar();
24    println!("  Julian Date: {:.6}", jd2.as_f64());
25    println!(
26        "  Calendar: {}-{:02}-{:02} {:02}:{:02}:{:02}\n",
27        cal2.year, cal2.month, cal2.day, cal2.hour, cal2.minute, cal2.second as i32
28    );
29
30    // Example 3: Using from_calendar directly
31    println!("Example 3: Direct conversion");
32    let jd3 = JulianDate::from_calendar(2000, 1, 1, 12, 0, 0.0)?;
33    println!("  January 1, 2000 12:00:00 UTC");
34    println!("  Julian Date: {:.6}\n", jd3.as_f64());
35
36    // Example 4: Historical dates
37    println!("Example 4: Historical Dates");
38    let dates = vec![
39        (1969, 7, 20, 20, 17, 0.0, "Apollo 11 Moon Landing"),
40        (1986, 1, 28, 11, 39, 0.0, "Space Shuttle Challenger"),
41        (2021, 7, 20, 9, 13, 0.0, "Blue Origin NS-16"),
42    ];
43
44    for (year, month, day, hour, minute, second, event) in dates {
45        let jd = JulianDate::from_calendar(year, month, day, hour, minute, second)?;
46        println!("  {}: JD {:.6}", event, jd.as_f64());
47    }
48
49    Ok(())
50}
More examples
Hide additional examples
examples/basic_usage.rs (line 66)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    println!("=== Rust JPL Ephemeris Reader - Basic Usage Example ===\n");
13
14    // Initialize the ephemeris from config.toml
15    println!("1. Initializing Ephemeris...");
16    let eph = Ephemeris::new("config.toml")?;
17    println!("   ✓ Ephemeris loaded successfully\n");
18
19    // Display metadata
20    println!("2. Ephemeris Metadata:");
21    let metadata = eph.get_metadata();
22    println!(
23        "   - Date Range: {} - {}",
24        metadata.start_year, metadata.end_year
25    );
26    println!(
27        "   - Julian Date Range: {:.2} - {:.2}",
28        metadata.julian_start, metadata.julian_end
29    );
30    println!("   - Interval: {} days", metadata.interval_days);
31    println!(
32        "   - Earth-Moon Mass Ratio: {:.6}",
33        metadata.earth_moon_ratio
34    );
35    println!(
36        "   - Number of Coefficients: {}\n",
37        metadata.number_of_coefficients
38    );
39
40    // List available bodies
41    println!("3. Available Celestial Bodies:");
42    for body in eph.get_bodies() {
43        let status = if body.active { "✓" } else { "✗" };
44        println!(
45            "   {} {} ({})",
46            status,
47            body.name,
48            if body.active { "active" } else { "inactive" }
49        );
50    }
51    println!();
52
53    // Time conversion example
54    println!("4. Time Conversion Example:");
55    let calendar_date = rust_jpl::CalendarDate::new(2024, 1, 15, 12, 0, 0.0);
56    println!(
57        "   Calendar Date: {}-{:02}-{:02} {:02}:{:02}:{:02}",
58        calendar_date.year,
59        calendar_date.month,
60        calendar_date.day,
61        calendar_date.hour,
62        calendar_date.minute,
63        calendar_date.second as i32
64    );
65
66    let jd = calendar_date.to_julian()?;
67    println!("   Julian Date: {:.6}", jd.as_f64());
68
69    let converted_back = jd.to_calendar();
70    println!(
71        "   Converted back: {}-{:02}-{:02} {:02}:{:02}:{:02}\n",
72        converted_back.year,
73        converted_back.month,
74        converted_back.day,
75        converted_back.hour,
76        converted_back.minute,
77        converted_back.second as i32
78    );
79
80    // Get planetary positions
81    println!(
82        "5. Planetary Positions (at Julian Date {:.6}):",
83        jd.as_f64()
84    );
85    let bodies = [
86        "Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn",
87    ];
88
89    for body_name in &bodies {
90        match eph.get_position(body_name, jd) {
91            Ok(pos) => {
92                println!(
93                    "   {}: ({:12.6}, {:12.6}, {:12.6}) AU, Distance: {:.6} AU",
94                    body_name,
95                    pos.x,
96                    pos.y,
97                    pos.z,
98                    pos.distance()
99                );
100            }
101            Err(e) => {
102                println!("   {}: Error - {}", body_name, e);
103            }
104        }
105    }
106
107    println!("\n=== Example Complete ===");
108    Ok(())
109}

Trait Implementations§

Source§

impl Clone for CalendarDate

Source§

fn clone(&self) -> CalendarDate

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CalendarDate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CalendarDate

Source§

fn eq(&self, other: &CalendarDate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for CalendarDate

Source§

impl StructuralPartialEq for CalendarDate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.