eu-dcc-business-rules
eu-dcc-business-rules copied to clipboard
Use named capturing groups for regular expression
The regular expression used for parsing date times contains a lot of enumerated capturing groups
https://github.com/ehn-dcc-development/dgc-business-rules/blob/88a6e3bae58b8ff7cede2677982ee4fa771ee405/certlogic/certlogic-kotlin/src/main/kotlin/eu/ehn/dcc/certlogic/JsonDateTime.java#L37
I would suggest to change that to named capturing groups, to implicitly state the semantics of them and minimize errors when potentially adding or removing capturing groups.
Note, that https://github.com/ehn-dcc-development/dgc-business-rules/issues/31. mentions a missing ?
after the timezone capturing group, which is not included here.
^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<timeHour>\d{2}):(?<timeMinute>\d{2}):(?<timeSecond>\d{2})(?<fractional>\.\d+?)?(?<timezone>Z|(?<offsetHour>[+-]\d{2}):?(?<offsetMinute>\d{2})?)$
Note that the java.util.regex.Pattern
class does not support underscores in capturing group names: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#cg
Another concern is that I'd like to align the Kotlin/Java/JVM-implementation with the {Type|Java}Script one: https://github.com/ehn-dcc-development/dgc-business-rules/blob/main/certlogic/certlogic-js/src/internals.ts#L45
I'll keep the issue, but it's not very high-prio, so I'll have to see when I get around to it.
(Cleaning up issues.)