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

<datetime> / <duration> feature is questionable, possibly should be removed. #1213

Closed
2 tasks done
tobiemh opened this issue Sep 24, 2022 Discussed in #1207 · 0 comments
Closed
2 tasks done

<datetime> / <duration> feature is questionable, possibly should be removed. #1213

tobiemh opened this issue Sep 24, 2022 Discussed in #1207 · 0 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@tobiemh
Copy link
Member

tobiemh commented Sep 24, 2022

Discussed in https://github.com/orgs/surrealdb/discussions/1207

Originally posted by finnbear September 23, 2022

Is your feature request related to a problem?

SurrealDB implements division for datetime divided by duration, which truncates the datetime to the duration:

SELECT * FROM time::now() / 1w;

The implementation of the feature is questionable because:

The feature itself is questionable because:

  • Division truncates instead of dividing:
    impl ops::Div<Datetime> for Duration {
    type Output = Datetime;
    fn div(self, other: Datetime) -> Datetime {
    match chrono::Duration::from_std(self.0) {
    Ok(d) => match other.duration_trunc(d) {
    Ok(v) => Datetime::from(v),
    Err(_) => Datetime::default(),
    },
    Err(_) => Datetime::default(),
    }
    }
    }

Describe the solution

  • Remove this type of division
  • time::floor seems like a canonical, much more clear way to truncate datetimes

Alternative methods

  • Use the time::floor function to truncate datetimes to specific durations.

SurrealDB version

surreal 1.0.0-beta.7 for windows on x86_64

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tobiemh tobiemh added the feature New feature or request label Sep 24, 2022
@tobiemh tobiemh added this to the v1.0.0-beta.8 milestone Sep 24, 2022
@tobiemh tobiemh self-assigned this Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant