Skip to content

spec and behavior of into datetime is ambiguous #8244

@baehyunsol

Description

@baehyunsol

Question

<int> | into datetime converts an integer to a datetime. If the number is big, it's in microseconds, otherwise it's second. But the spec doesn't tell us how big the number should be. Also, the implementation is ambiguous. Below is the implementation.

link

// ...
match ts.to_string().len() {
  x if x > 13 => Value::Date {
    val: Utc.timestamp_nanos(ts).into(),
    span: head,
  },
  x if x > 10 => match_datetime!(Utc.timestamp_millis_opt(ts)),
  _ => match_datetime!(Utc.timestamp_opt(ts, 0)),
}
// ...

ts is an i64 value which is converted to datetime. I have no idea why it uses .to_string().len() instead of .abs(). It has two issues.

  1. Performance: .abs() is way faster than .to_string().len(). But the difference would be small.
  2. Behavior: "-999"'s length is 4 and "999"'s length is 3 while their absolute values are the same! It's confusing..

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpecteddeprecated:questionQuestions should be redirected to GitHub discussions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions