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

Timestamp issue? #67

Closed
alexsnaps opened this issue Jul 11, 2024 · 2 comments · Fixed by #68
Closed

Timestamp issue? #67

alexsnaps opened this issue Jul 11, 2024 · 2 comments · Fixed by #68

Comments

@alexsnaps
Copy link
Contributor

I'm not sure whether I'm the one doing something here, but I find this slightly confusing:

let script = "ts == timestamp('2023-05-28T00:00:00+00:00')";
let program = Program::compile(script).unwrap();
let mut context = Context::default();
let ts: DateTime<FixedOffset> = DateTime::parse_from_rfc3339("2023-05-28T00:00:00+00:00").unwrap();
context.add_variable("ts", Value::Timestamp(ts)).unwrap();
assert_eq!(program.execute(&context), Ok(true.into()));

Interestingly, this yields comparing: Timestamp(2023-05-28T00:00:00+00:00) vs String("2023-05-28T00:00:00+00:00")
Where the lhs is the timestamp('2023-05-28T00:00:00+00:00', but for some reason ts ends up being a ... String? Am I missing something here?

@clarkmcc
Copy link
Owner

clarkmcc commented Jul 11, 2024

This was a regression introduced in #40 (extension of changes in #33)

It is because of this trait

V: TryIntoValue,

Which ultimately calls this function, converting the timestamp to a string

Value::Timestamp(ref dt) => serializer.serialize_str(&dt.to_rfc3339()),

Still thinking about exactly how to solve this. In the meantime, you can use this to add a Value type directly and skip serialization.

context.add_variable_from_value("foo", Value::Timestamp(DateTime::default()))

@clarkmcc clarkmcc linked a pull request Jul 12, 2024 that will close this issue
@clarkmcc
Copy link
Owner

clarkmcc commented Jul 12, 2024

I need to think through the repercussions of #68 but it does resolve the issue (test added). Because of this addition, I don't think there will be any breaking changes. We were effectively doing that before, just with an unnecessary intermediate serialization step.

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

Successfully merging a pull request may close this issue.

2 participants