Open romaintailhurat opened 7 months ago
More
With the same binding as above:
{"DD": "P100Y11M"}
we can check that:
instr(DD, "P") - 1
returns 0
🆗 instr(DD, "P")-1
returns 1
🔴 Even more
So:
substr(
DD,
instr(DD, "Y") + 1,
(instr(DD, "M") - instr(DD, "Y")) - 1
)
gives 11
.
Meaning in arithmetics spaces between operands are important, but probably not handled correctly for users, we should provide errors instead of wrong / curious results.
Truly, the problem is with this type of expression: 10 -9
, that seems to be parsed as the two integers 10
and 9
in sequence, not as the subtracting operation.
I'm trying to implement a simple feat with a duration string, that is extracting the month value for:
P100Y11M
We don't have yet a
duration
type implemented in Trevas JS, i'm trying to simply parse the string*.One way to do it is to use
substr
andinstr
(hereDD
is a string with valueP100Y11M
):But i'm getting the following error:
Type errors: Error: extraneous input '-1' expecting ')'
If i try the same formula using a scalar as the
length
param, it works:It's probably not a problem with
substr
, because this is also raising the same error as previously:instr(DD, "M")-(instr(DD, "Y")-1)
@NicoLaval we can discuss that and even pair programming over this when you find time 😃