Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chrono 0.5 Duration #59

Closed
fsktom opened this issue Jul 25, 2023 · 5 comments
Closed

chrono 0.5 Duration #59

fsktom opened this issue Jul 25, 2023 · 5 comments
Assignees
Labels
cli Regarding `endsong_ui` crate dependency Waiting for a change in a dependency library Regarding `endsong` crate refactor

Comments

@fsktom
Copy link
Owner

fsktom commented Jul 25, 2023

See chronotope/chrono#1137

When they do this, I'll have to probably rename chrono::Duration to whatever they decide on (currently TimeDelta), but I'll finally be able to use += (no longer necessary tbh), but they implement iter::Sum !!!

https://github.com/chronotope/chrono/blob/f5ea3ec216d8c34cd0346bc8b105287f9f641d2e/src/time_delta.rs#L392-L406

I won't have to use .fold(...) xd but a more concise .sum() instead :D
e.g. here

pub fn listening_time(entries: &[SongEntry]) -> Duration {
// sadly doesn't work bc neither chrono::Duration nor std::time::Duration implement iter::sum :))))
// self.iter().map(|entry| entry.time_played).sum::<Duration>()
entries
.iter()
.map(|entry| entry.time_played)
.fold(Duration::milliseconds(0), |sum, dur| sum + dur)
}

@fsktom fsktom self-assigned this Jul 25, 2023
@fsktom fsktom added refactor dependency Waiting for a change in a dependency library Regarding `endsong` crate cli Regarding `endsong_ui` crate labels Jul 26, 2023
@fsktom
Copy link
Owner Author

fsktom commented Sep 15, 2023

https://github.com/chronotope/chrono/releases/tag/v0.4.30

Oh damn seems like they changed the Duration type in v0.4.30 already ! :D

While this is technically a SemVer-breaking change, we expect the risk of downstream users experiencing actual incompatibility to be exceedingly limited (see chronotope/chrono#1095 (comment) of public code using a crater-like experiment), and not enough justification for the large ecosystem churn of a 0.5 release.

@fsktom
Copy link
Owner Author

fsktom commented Sep 15, 2023

So time v0.1 has been removed
but seems like the Duration features have not been merged yet?
chronotope/chrono#1137 (comment)

@fsktom
Copy link
Owner Author

fsktom commented Sep 15, 2023

omg

https://github.com/chronotope/chrono/releases/tag/v0.4.31

in v0.4.31 they added UNIX_EPOCH constants

let epoch = chrono::Utc.datetime_from_str("1970-01-01T00:00:00Z", "%FT%TZ")?;
Ok(Local.from_utc_datetime(&epoch.naive_utc()))

I'm gonna be able to get rid of this line :D

@fsktom
Copy link
Owner Author

fsktom commented Sep 16, 2023

seems like the Duration features have not been merged yet?

hmm at least the Sum for iterator has been merged..

@fsktom
Copy link
Owner Author

fsktom commented Feb 21, 2024

Heh, Clippy now has a lint for it, I guess?
It urged me to change a = to a += for a Duration addition in 739a0b3

:D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Regarding `endsong_ui` crate dependency Waiting for a change in a dependency library Regarding `endsong` crate refactor
Projects
None yet
Development

No branches or pull requests

1 participant