flosse / rust-sun

A Rust library for calculating sun positions
47 stars 9 forks source link

Calculate times of sunset, sunrise and other sun phases #5

Closed markus-k closed 1 year ago

markus-k commented 1 year ago

This PR adds a function to calculate the time of sun phases like sunset, sunrise at a given date. Like sun::pos, it is mostly ported from the suncalc npm-package, with exception that it only calculates the time for one phase instead of a whole bunch (seemed more efficient/suitable to me). The function returns a timestamp (in ms).

It would be nice to add (optional) support for the chrono crate, so you don't have to manually convert the timestamps to something usable after every call. That would be a separate PR though and maybe even a breaking change dependening on how it's done.

flosse commented 1 year ago

Thank you!

It would be nice to add (optional) support for the chrono crate, so you don't have to manually convert the timestamps to something usable after every call. That would be a separate PR though and maybe even a breaking change dependening on how it's done.

I'd avoid chrono (not maintained & security issues) but we could use time

flosse commented 1 year ago

BTW: what do you think about using typed units with e.g. dimensioned?

markus-k commented 1 year ago

I like chronos DateTime and timezone handling, and haven't used time itself before. But that might be an upgrade already, I might look into if I can find the time.

I haven't heard about the dimensioned crate before. I like the idea, but I'm not sure yet if I like their implementation from what I've seen. It might be a bit overkill here as well, since the only unit we have is degrees.