Skip to content

fix(builtins): add d/w/y duration units to time.parse_duration_ns - #799

Open
Anand Krishnamoorthi (anakrish) wants to merge 3 commits into
microsoft:mainfrom
anakrish:fix/time-duration-d-w-y
Open

fix(builtins): add d/w/y duration units to time.parse_duration_ns#799
Anand Krishnamoorthi (anakrish) wants to merge 3 commits into
microsoft:mainfrom
anakrish:fix/time-duration-d-w-y

Conversation

@anakrish

Copy link
Copy Markdown
Collaborator

OPA supports d (day), w (week), and y (365-day year) as duration unit suffixes; Regorus previously returned an UnknownUnit error for those tokens.

Changes

  • Add constants DAY = 24 * HOUR, WEEK = 7 * DAY, YEAR = 365 * DAY in src/builtins/time/compat.rs
  • Add "d", "w", "y" arms to the unit-matching block in parse_duration()

Tests

New tests/interpreter/cases/builtins/time/duration_units.yaml covering:

  • Individual units: 1d = 86400000000000 ns, 1w = 604800000000000 ns, 1y = 31536000000000000 ns
  • Mixed compound: "1d12h" = 129600000000000 ns

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

OPA supports 'd' (day), 'w' (week), and 'y' (365-day year) as duration
unit suffixes; Regorus previously returned an error for those tokens.

- Define DAY = 24 * HOUR, WEEK = 7 * DAY, YEAR = 365 * DAY constants
- Add 'd', 'w', 'y' arms to the unit-matching arm of parse_duration()
- Add YAML regression test covering individual units and a mixed
  '1d12h' compound duration

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant