diff --git a/Cargo.lock b/Cargo.lock index 3081be2..f75cbb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,6 +32,21 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.18" @@ -403,7 +418,12 @@ version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", "num-traits", + "wasm-bindgen", + "windows-link", ] [[package]] @@ -1201,6 +1221,29 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b24ad5637230df201ab1034d593f1d09bf7f2a9274f2e8897638078579f4265" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icu_collections" version = "1.5.0" @@ -2819,6 +2862,7 @@ version = "0.0.0" dependencies = [ "anyhow", "axum", + "chrono", "clap", "escpos", "image", @@ -4141,6 +4185,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-link" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 1541b50..79d32d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2024" [workspace.dependencies] anyhow = "1.0.97" axum = "0.8.1" +chrono = "0.4.40" clap = { version = "4.5.33", features = ["derive", "deprecated"] } escpos = "0.15.0" image = "0.25.6" diff --git a/showbits-thermal-printer/Cargo.toml b/showbits-thermal-printer/Cargo.toml index 50d47d6..5ff1d02 100644 --- a/showbits-thermal-printer/Cargo.toml +++ b/showbits-thermal-printer/Cargo.toml @@ -6,6 +6,7 @@ edition = { workspace = true } [dependencies] anyhow = { workspace = true } axum = { workspace = true, features = ["multipart"] } +chrono = {workspace = true} clap = { workspace = true } escpos = { workspace = true } image = { workspace = true } diff --git a/showbits-thermal-printer/src/documents/sunrise/mod.rs b/showbits-thermal-printer/src/documents/sunrise/mod.rs index 7ba244c..694082b 100644 --- a/showbits-thermal-printer/src/documents/sunrise/mod.rs +++ b/showbits-thermal-printer/src/documents/sunrise/mod.rs @@ -1,6 +1,8 @@ +use anyhow::anyhow; use axum::{Form, extract::State}; use jiff::{Timestamp, ToSpan, Zoned, civil, tz::TimeZone}; use serde::{Deserialize, Serialize}; +use sunrise::{Coordinates, SolarDay, SolarEvent}; use crate::server::{Server, somehow}; @@ -27,24 +29,32 @@ pub async fn post(server: State, Form(form): Form) -> somehow: let year = form.year.unwrap_or(now_date_utc.year()); let month = form.month.unwrap_or(now_date_utc.month()); + let coord = Coordinates::new(form.latitude, form.longitude) + .ok_or_else(|| somehow::Error(anyhow!("Invalid coordinates")))?; + let first = civil::Date::new(year, month, 1)?; let mut times = vec![]; for day in 0..first.days_in_month() { let date = first + day.days(); - let (rise, set) = sunrise::sunrise_sunset( - form.latitude, - form.longitude, + + let date_chrono = chrono::NaiveDate::from_ymd_opt( date.year() as i32, date.month() as u32, date.day() as u32, - ); + ) + .unwrap(); - let rise = Timestamp::new(rise, 0)? + let solar_day = SolarDay::new(coord, date_chrono); + + let rise_chrono = solar_day.event_time(SolarEvent::Sunrise); + let set_chrono = solar_day.event_time(SolarEvent::Sunset); + + let rise = Timestamp::new(rise_chrono.timestamp(), 0)? .to_zoned(now.time_zone().clone()) .strftime("%H:%M") .to_string(); - let set = Timestamp::new(set, 0)? + let set = Timestamp::new(set_chrono.timestamp(), 0)? .to_zoned(now.time_zone().clone()) .strftime("%H:%M") .to_string();