Skip to content

refactor(openworkflow): hoist parseDuration multipliers to module scope#467

Merged
jamescmartinez merged 2 commits intomainfrom
duration-constants
Apr 16, 2026
Merged

refactor(openworkflow): hoist parseDuration multipliers to module scope#467
jamescmartinez merged 2 commits intomainfrom
duration-constants

Conversation

@jamescmartinez
Copy link
Copy Markdown
Contributor

hoists the multipliers table and regex in parseDuration out of the function body so they aren't rebuilt on every call. also replaces the inline 60 * 60 * 1000 repetitions with named MINUTE_MS/HOUR_MS/etc constants.

hoists the multipliers table and regex in `parseDuration` out of the function
body so they aren't rebuilt on every call. also replaces the inline `60 * 60 * 1000`
repetitions with named `MINUTE_MS`/`HOUR_MS`/etc constants.
Copilot AI review requested due to automatic review settings April 16, 2026 21:23
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/openworkflowdev/openworkflow/@openworkflow/cli@467
npm i https://pkg.pr.new/openworkflowdev/openworkflow/@openworkflow/dashboard@467
npm i https://pkg.pr.new/openworkflowdev/openworkflow@467

commit: 09fbd3c

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hoists parseDuration’s regex and unit-to-millisecond multipliers to module scope to avoid rebuilding them on every call, and introduces named time constants for clearer multiplier definitions.

Changes:

  • Added module-scope SECOND_MS/MINUTE_MS/HOUR_MS/etc constants.
  • Moved the duration multipliers map and regex out of parseDuration into module-level constants.
  • Updated parseDuration to reuse the shared constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/openworkflow/core/duration.ts Outdated
Comment on lines +36 to +41
const DURATION_MULTIPLIERS: Record<string, number> = {
millisecond: 1,
milliseconds: 1,
msec: 1,
msecs: 1,
ms: 1,
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DURATION_MULTIPLIERS is typed as Record<string, number>, which drops compile-time validation of the supported units. Since this module already defines the Unit union, consider typing this as Record<Unit, number> (optionally via as const/satisfies) so unit additions/removals stay type-checked.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jamescmartinez jamescmartinez merged commit abb1e2c into main Apr 16, 2026
9 of 10 checks passed
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.

2 participants