InseeFr / Trevas-TS

JavaScript engine for the Validation and Transformation Language
MIT License
9 stars 8 forks source link

Date arithmetic - Adding a Date and a number #127

Open romaintailhurat opened 1 year ago

romaintailhurat commented 1 year ago

Some date arithmetics are already implemented in Trevas JS.

In the case of subtraction between two dates, the return type is an integer (eg seconds).

We would like to implement addition and subtraction between a date and a number with another date as the return type.

For example, with a DATE variable of 2023-09-29, we would like the resulting behavior:

DATE + 32023-10-02

romaintailhurat commented 1 year ago

The VTL spec doesn't allow for this kind of behavior:

image

romaintailhurat commented 1 year ago

Maybe we could a custom operator that wraps a call to a underlying engine function? Or is it too much of a hack?

NicoLaval commented 1 year ago

Hi,

Instead of the 3 integer you certainly want to add a duration to the date, enable you to specify that your 3 is 3 days. Didn't find a way to do it for now: Date + Duration -> Date

This subject can maybe be discussed this week during Roma meeting.

Please link your issue to the https://github.com/VTL-Community/VTL-Community issues.

romaintailhurat commented 1 year ago

👉 https://github.com/VTL-Community/VTL-Community/issues/38