Skip to content

Commit

Permalink
Improved code example
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcarr committed Apr 7, 2024
1 parent 096597c commit 3731f48
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion practical-astronomy-rust-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
practical-astronomy-rust = { version = "0.2.1", path = "../practical-astronomy-rust" }
practical-astronomy-rust = { version = "0.2.2", path = "../practical-astronomy-rust" }
2 changes: 1 addition & 1 deletion practical-astronomy-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "practical-astronomy-rust"
description = "Algorithms from Practical Astronomy, implemented in Rust"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
documentation = "https://jfcarr.github.io/practical-astronomy-rust/"
Expand Down
25 changes: 23 additions & 2 deletions practical-astronomy-rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,19 @@ fn main() {
geog_latitude_deg,
);

// Results are in Universal Time, so lets adjust them for local
let adjustment_value: f64 = if is_daylight_saving {
(zone_correction_hours as f64) - 1.0
} else {
zone_correction_hours as f64
};

let ut_first_contact_hour_adj: f64 = ut_first_contact_hour - adjustment_value;
let ut_mid_eclipse_hour_adj: f64 = ut_mid_eclipse_hour - adjustment_value;
let ut_last_contact_hour_adj: f64 = ut_last_contact_hour - adjustment_value;

// Display the results
println!("Solar eclipse circumstances: [Local Date] {}/{}/{} [DST?] {} [Zone Correction] {} hours [Geographical Longitude/Latitude] {} degrees / {} degrees = [Certain Date] {}/{}/{} [First Contact] {}:{} [Mid Eclipse] {}:{} [Last Contact] {}:{} [Magnitude] {}", local_date_month, local_date_day, local_date_year, is_daylight_saving, zone_correction_hours, geog_longitude_deg, geog_latitude_deg, solar_eclipse_certain_date_month, solar_eclipse_certain_date_day, solar_eclipse_certain_date_year, ut_first_contact_hour, ut_first_contact_minutes, ut_mid_eclipse_hour, ut_mid_eclipse_minutes, ut_last_contact_hour, ut_last_contact_minutes, eclipse_magnitude);
println!("Solar eclipse circumstances:\n\t[Local Date] {}/{}/{}\n\t[DST?] {}\n\t[Zone Correction] {} hours\n\t[Geographical Longitude/Latitude] {} degrees / {} degrees\n\t=\n\t[Certain Date] {}/{}/{}\n\t[First Contact] {}:{}\n\t[Mid Eclipse] {}:{}\n\t[Last Contact] {}:{}\n\t[Magnitude] {}", local_date_month, local_date_day, local_date_year, is_daylight_saving, zone_correction_hours, geog_longitude_deg, geog_latitude_deg, solar_eclipse_certain_date_month, solar_eclipse_certain_date_day, solar_eclipse_certain_date_year, ut_first_contact_hour_adj, ut_first_contact_minutes, ut_mid_eclipse_hour_adj, ut_mid_eclipse_minutes, ut_last_contact_hour_adj, ut_last_contact_minutes, eclipse_magnitude);
}
```

Expand All @@ -71,7 +82,17 @@ cargo run
You should see this:

```
Solar eclipse circumstances: [Local Date] 4/8/2024 [DST?] true [Zone Correction] 5 hours [Geographical Longitude/Latitude] -84.53639 degrees / 39.74722 degrees = [Certain Date] 4/8/2024 [First Contact] 17:55 [Mid Eclipse] 19:11 [Last Contact] 20:27 [Magnitude] 1.006
Solar eclipse circumstances:
[Local Date] 4/8/2024
[DST?] true
[Zone Correction] 5 hours
[Geographical Longitude/Latitude] -84.53639 degrees / 39.74722 degrees
=
[Certain Date] 4/8/2024
[First Contact] 13:55
[Mid Eclipse] 15:11
[Last Contact] 16:27
[Magnitude] 1.006
```

## Library Functions - Status
Expand Down

0 comments on commit 3731f48

Please sign in to comment.