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

date arithmetic returns date instead of number #866

Closed
MartijnR opened this issue Nov 2, 2021 · 2 comments · Fixed by enketo/openrosa-xpath-evaluator#143
Closed

date arithmetic returns date instead of number #866

MartijnR opened this issue Nov 2, 2021 · 2 comments · Fixed by enketo/openrosa-xpath-evaluator#143
Assignees

Comments

@MartijnR
Copy link
Member

MartijnR commented Nov 2, 2021

These (new) tests fail:

 it('example 4', () => {
     assertStringValue('"2021-11-30" + 1', '18962'); // returns '2021-11-01' instead
});

it('example 5', () => {
     assertStringValue('"2021-11-30" - "2021-11-29"', '1'); // returns '1970-01-02' instead
});

Both ODK Collect and the old Enketo evaluator return a number (as string), following the XPath rule that the presence of the operator (+) causes both left and right operands to be converted to a number.

I suspect, I may be responsible for this change, so sorry about that. I am hoping the fix may actually simplify the code.

Note, that if behind the scenes, the number value is not an integer (but a decimal), I think it might be pragmatic to consider that a separate (timezone) issue in either Collect or Enketo (and leave it for later).

@MartijnR
Copy link
Member Author

MartijnR commented Nov 4, 2021

Removing this code makes these tests pass (though decimal 18962.291666666668 is the result for the first).

There is one karma test that will start failing which is:

#date() date calculations should convert today() > ('2012-01-01' + 10) to true

Adding another test like 'date("2100-01-02") > 1' (which should be true but is false), reveals that comparisons with numbers and dates do not work currently in master. That is probably the cause of that.

Though some other mocha tests are failing. Tbc (probably requires changing expected results to numbers).

MartijnR referenced this issue in enketo/openrosa-xpath-evaluator Nov 9, 2021
@MartijnR
Copy link
Member Author

MartijnR commented Nov 9, 2021

I added the above tests to the fix/dates-141 branch (though integer results can be decimals in reality as mentioned above).

MartijnR referenced this issue in enketo/openrosa-xpath-evaluator Nov 15, 2021
@MartijnR MartijnR self-assigned this Nov 15, 2021
MartijnR referenced this issue in enketo/openrosa-xpath-evaluator Jan 18, 2022
* Fixed date arithmetic returning date instead of number, closes #141
@lognaturel lognaturel transferred this issue from enketo/openrosa-xpath-evaluator Nov 29, 2023
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.

1 participant