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

Make Datetime sortable? #13

Closed
alexwennerberg opened this issue Feb 7, 2022 · 5 comments
Closed

Make Datetime sortable? #13

alexwennerberg opened this issue Feb 7, 2022 · 5 comments

Comments

@alexwennerberg
Copy link
Contributor

I'm trying to sort a list of emails by datetime, and it appears the DateTime struct doesn't allow this -- what do you think the best solution is for this?

@mdecimus
Copy link
Member

mdecimus commented Feb 7, 2022

The quickest solution would be converting the date to a ISO8601 string using Message::get_date().unwrap().to_iso8601(). Alternatively you could use the chrono crate to convert the date to a timestamp, or sort directly the chrono object.

@alexwennerberg
Copy link
Contributor Author

Would you accept a PR that converted this datetime object to unix time? I'm trying to avoid pulling in chrono as a dependency @mdecimus

@mdecimus
Copy link
Member

Ok, I'll add this feature as soon as I have some free time this week. I found a neat algorithm for this:
https://github.com/protocolbuffers/upb/blob/22182e6e/upb/json_decode.c#L982

@alexwennerberg
Copy link
Contributor Author

alexwennerberg commented Mar 14, 2022

@mdecimus I actually found the same thing and implemented it here lol https://git.alexwennerberg.com/crabmail/file/src/utils.rs.html#l6

Haven't really tested it yet though, just tried to copy/paste the c code. It's also not that idiomatic

@mdecimus
Copy link
Member

Done, v.0.4.5 is out with support for timestamp conversion and sorting by DateTime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants