Skip to content
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 methods to get finite duration from duration #8832

Open
wants to merge 2 commits into
base: series/2.x
Choose a base branch
from

Conversation

NavidJalali
Copy link
Contributor

@NavidJalali NavidJalali commented May 9, 2024

Fix #8797

/claim #8797

@kyri-petrou
Copy link
Contributor

@NavidJalali just FYI, you'll need to add /claim #8797 to the PR description if you want to receive payment for bounty

Copy link

algora-pbc bot commented May 12, 2024

💵 To receive payouts, sign up on Algora, link your Github account and connect with Stripe/Alipay.

case _ => Some(ScalaFiniteDuration(duration.toNanos, TimeUnit.NANOSECONDS))
}

def asFiniteDurationUnsafe: ScalaFiniteDuration = duration match {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's necessary to throw, because if you look at "Infinity", it's just a "really big" (biggest possible) finite duration. So I think this can and should be a total function.

Copy link
Member

Choose a reason for hiding this comment

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

Btw I would also consider simply changing def asScala: ScalaDuration to def asScala: ScalaFiniteDuration. This way no new methods are necessary and it should be backward compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

@@ -154,7 +154,7 @@ object DurationSpec extends ZIOBaseSpec {
assert(Duration.Infinity.isZero)(equalTo(false))
},
test("It converts into the infinite s.c.d.Duration") {
assert(Duration.Infinity.asScala)(equalTo(ScalaDuration.Inf: ScalaDuration))
assert(Duration.Infinity.asScala)(equalTo(ScalaFiniteDuration(Long.MaxValue, TimeUnit.NANOSECONDS)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I will note this is likely not preferable if users are using APIs which special case for Duration.Inf...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add conversion to FiniteDuration to zio.duration
4 participants