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

Add chrono::TimeDelta to mongodb::bson::DateTime #489

Closed
ChanManChan opened this issue Aug 5, 2024 · 2 comments
Closed

Add chrono::TimeDelta to mongodb::bson::DateTime #489

ChanManChan opened this issue Aug 5, 2024 · 2 comments
Assignees

Comments

@ChanManChan
Copy link

Is there a better way to add chrono::Duration to bson::DateTime without converting to chrono::DateTime?

currently I'm doing this
expires_at: DateTime::from_millis(now.timestamp_millis() + duration.num_milliseconds()),

@isabelatkinson
Copy link
Contributor

Hi @ChanManChan, there is currently no way to add a chrono::Duration/chrono::TimeDelta directly to a bson::DateTime. Your current approach looks reasonable. Enabling the chrono-0_4 feature flag if you have not done so already will also allow you to convert more easily between bson::DateTime and chrono::DateTime via the to_chrono and from_chrono methods.

@ChanManChan
Copy link
Author

Hi @ChanManChan, there is currently no way to add a chrono::Duration/chrono::TimeDelta directly to a bson::DateTime. Your current approach looks reasonable. Enabling the chrono-0_4 feature flag if you have not done so already will also allow you to convert more easily between bson::DateTime and chrono::DateTime via the to_chrono and from_chrono methods.

Thanks for the suggestions but I think I'm sticking with my solution if you find it reasonable.

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