-
Notifications
You must be signed in to change notification settings - Fork 2.1k
spec and behavior of into datetime is ambiguous #8244
Copy link
Copy link
Closed
Labels
category:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpectedBehavior between different commands or types inconsistent/unexpecteddeprecated:questionQuestions should be redirected to GitHub discussionsQuestions should be redirected to GitHub discussions
Milestone
Description
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.
// ...
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.
- Performance:
.abs()is way faster than.to_string().len(). But the difference would be small. - 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
category:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpectedBehavior between different commands or types inconsistent/unexpecteddeprecated:questionQuestions should be redirected to GitHub discussionsQuestions should be redirected to GitHub discussions