JulianDate

Struct JulianDate 

Source
pub struct JulianDate {
    pub jd: f64,
}
Expand description

Represents a Julian Date (JD)

Fields§

§jd: f64

Julian day number

Implementations§

Source§

impl JulianDate

Source

pub fn new(jd: f64) -> Self

Create a Julian date from a Julian day number

Examples found in repository?
examples/time_conversion.rs (line 22)
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}
Source

pub fn from_calendar( year: i32, month: i32, day: i32, hour: i32, minute: i32, second: f64, ) -> Result<Self, Error>

Convert calendar date to Julian date

§Arguments
  • year - Year (e.g., 2024)
  • month - Month (1-12)
  • day - Day of month (1-31)
  • hour - Hour (0-23)
  • minute - Minute (0-59)
  • second - Second (0-59.999…)
§Example
use rust_jpl::JulianDate;
let jd = JulianDate::from_calendar(2024, 1, 15, 12, 0, 0.0);
Examples found in repository?
examples/planetary_positions.rs (line 23)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    println!("=== Planetary Positions Example ===\n");
9
10    // Initialize ephemeris
11    let eph = Ephemeris::new("config.toml")?;
12
13    // Define dates to query
14    let dates = vec![
15        (2024, 1, 1, 0, 0, 0.0),
16        (2024, 6, 15, 12, 0, 0.0),
17        (2024, 12, 31, 23, 59, 59.0),
18    ];
19
20    let bodies = vec!["Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter"];
21
22    for (year, month, day, hour, minute, second) in dates {
23        let jd = JulianDate::from_calendar(year, month, day, hour, minute, second)?;
24        println!(
25            "Date: {}-{:02}-{:02} {:02}:{:02}:{:02} (JD: {:.6})",
26            year,
27            month,
28            day,
29            hour,
30            minute,
31            second as i32,
32            jd.as_f64()
33        );
34        println!("{}", "=".repeat(70));
35
36        for body_name in &bodies {
37            match eph.get_position(body_name, jd) {
38                Ok(pos) => {
39                    println!(
40                        "  {:10} | X: {:12.6} | Y: {:12.6} | Z: {:12.6} | Distance: {:10.6} AU",
41                        body_name,
42                        pos.x,
43                        pos.y,
44                        pos.z,
45                        pos.distance()
46                    );
47                }
48                Err(e) => {
49                    println!("  {:10} | Error: {}", body_name, e);
50                }
51            }
52        }
53        println!();
54    }
55
56    Ok(())
57}
More examples
Hide additional examples
examples/time_conversion.rs (line 32)
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}
Source

pub fn to_calendar(&self) -> CalendarDate

Convert Julian date to calendar date

Examples found in repository?
examples/time_conversion.rs (line 23)
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 69)
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 as_f64(&self) -> f64

Get the Julian day number

Examples found in repository?
examples/planetary_positions.rs (line 32)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    println!("=== Planetary Positions Example ===\n");
9
10    // Initialize ephemeris
11    let eph = Ephemeris::new("config.toml")?;
12
13    // Define dates to query
14    let dates = vec![
15        (2024, 1, 1, 0, 0, 0.0),
16        (2024, 6, 15, 12, 0, 0.0),
17        (2024, 12, 31, 23, 59, 59.0),
18    ];
19
20    let bodies = vec!["Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter"];
21
22    for (year, month, day, hour, minute, second) in dates {
23        let jd = JulianDate::from_calendar(year, month, day, hour, minute, second)?;
24        println!(
25            "Date: {}-{:02}-{:02} {:02}:{:02}:{:02} (JD: {:.6})",
26            year,
27            month,
28            day,
29            hour,
30            minute,
31            second as i32,
32            jd.as_f64()
33        );
34        println!("{}", "=".repeat(70));
35
36        for body_name in &bodies {
37            match eph.get_position(body_name, jd) {
38                Ok(pos) => {
39                    println!(
40                        "  {:10} | X: {:12.6} | Y: {:12.6} | Z: {:12.6} | Distance: {:10.6} AU",
41                        body_name,
42                        pos.x,
43                        pos.y,
44                        pos.z,
45                        pos.distance()
46                    );
47                }
48                Err(e) => {
49                    println!("  {:10} | Error: {}", body_name, e);
50                }
51            }
52        }
53        println!();
54    }
55
56    Ok(())
57}
More examples
Hide additional examples
examples/time_conversion.rs (line 18)
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}
examples/basic_usage.rs (line 67)
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 JulianDate

Source§

fn clone(&self) -> JulianDate

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 JulianDate

Source§

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

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

impl PartialEq for JulianDate

Source§

fn eq(&self, other: &JulianDate) -> 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 PartialOrd for JulianDate

Source§

fn partial_cmp(&self, other: &JulianDate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for JulianDate

Source§

impl StructuralPartialEq for JulianDate

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.