hyperjumptech / grule-rule-engine

Rule engine implementation in Golang
Other
2.22k stars 346 forks source link

Grule `MakeTime` Function does not accept 'Leading Zeroes' for Months `08` and `09`. #462

Closed ashwingopalsamy-solaris closed 2 months ago

ashwingopalsamy-solaris commented 2 months ago

Describe the bug

We have identified an issue with the MakeTime() function (defined in the ast/BuiltInFunctions.go) used in our Grule rules. Specifically, when the month is passed as 08 or 09 (e.g., MakeTime(2023, 08, 1, 0, 0, 0)), Grule does not accept this format. Grule expects months to be in a single-digit format without leading zeros (e.g., MakeTime(2023, 8, 1, 0, 0, 0)).

Important Observation: Grule does accept the format with a leading zero for months 01 to 07 (e.g., MakeTime(2023, 01, 1, 0, 0, 0)), making this issue specific to months 08 and 09.

To Reproduce Steps to reproduce the behaviour:

  1. I create a Grule rule using MakeTime with a month value of 08 or 09 with a leading zero(0).
  2. I create a test for this rule to check if Grule accepts it.
  3. Instead of seeing the rule being accepted, I see that Grule throws an error or fails to process the rule.

Expected behaviour

Grule should consistently accept month values with or without leading zeros for all months (1-12). The expected behaviour is that the rule should work regardless of whether the month is provided as 08 or 8.

Additional context

Grule Version: 1.15.0 Go Version: 1.21 Operating System: Linux

ivoshm commented 2 months ago

This is not a GRULE problem, but a general Golang feature:

Integer literal starting with 0 (zero) is treated as octal number (so 08 and 09 didn't make sense).

ashwingopalsamy-solaris commented 2 months ago

Got it, thanks for the insight, @ivoshm !

We’ll avoid leading zeros then.