InseeFr / InseeFr/Trevas-TS

Arithmetics with `instr` is buggy

Open
#134 4 comments 0 reactions 2 assignees Claimed by @romaintailhurat View on GitHub
bug
Dominant language
TypeScript
Stars
9
Forks
8
PR merge metrics
No merged PRs in 30d

Description

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` and `instr` (here `DD` is a string with value `P100Y11M`):

```
substr(
DD,
instr(DD, "Y") + 1,
(instr(DD, "M")-instr(DD, "Y"))-1
)
```

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:

```
substr(
DD,
instr(DD, "Y") + 1,
2
)
```

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 😃

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.