nathan-osman / rust-sunrise

Crate for calculating sunrise / sunset times
MIT License
11 stars 6 forks source link

How to decode the returned integers into a timepoint #3

Open rainerschoe opened 2 years ago

rainerschoe commented 2 years ago

Thanks for implementing this function.

However from reading the documentation I see that the function returns a tuple of i64. I do not yet understand how this i64 is representing a sunrise/sunset time. What is the encoding.

More specifically, how to convert this into something like a chrono::naive::NaiveTime

rainerschoe commented 2 years ago

I found https://docs.rs/sun-times/0.1.2/sun_times/fn.sun_times.html Which has a more strictly typed API, however it is fairly old, has no tests and is not as well structured.

nathan-osman commented 2 years ago

The return value is a tuple of two Unix timestamps representing the sunrise and sunset times respectively.

You could create a NaiveDateTime from the timestamp with something like:

let (sunrise, sunset) = sunrise_sunset(...);
let sunrise = NaiveDateTime::from_timestamp(sunrise, 0);
rainerschoe commented 2 years ago

Thanks for the quick reply. This helps :+1: Will try it like this. Maybe add this info and example to the documentation? If you like I could also do this as a PR.