-
-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Duration.divide #2494
Add Duration.divide #2494
Conversation
🦋 Changeset detectedLatest commit: 5fc0797 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Looking to replace https://github.com/PREreview/coar-notify/blob/958faa16e9bf2fa4aee536c1d66d7ba4d5c36c89/src/BullMq.ts#L135-L136. Could be achieved with Duration.times(value, 0.5) but a division API would be more straightforward. |
A Duration.map("30 seconds", {
onMillis: (val: number) => val / 2,
onNanos: (val: bigint) => val / 2n
}) |
Hmm I think we might need a safe variant, and call this unsafeDivide. |
@tim-smart I've had a stab at that. I've followed the |
} = dual( | ||
2, | ||
(self: DurationInput, by: number): Option.Option<Duration> => | ||
match(self, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this by wrapping unsafeDivide with a try catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The results are a bit different (#2494 (comment)).
Type
Description
Adds
divide
to theDuration
module (it already hastimes
).UnlikeNumber.divide
andBigInt.divide
, this doesn't have safe/unsafe variants.Related