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

No FiniteDuration parser #1266

Open
AndreyLadniy opened this issue Sep 13, 2023 · 1 comment
Open

No FiniteDuration parser #1266

AndreyLadniy opened this issue Sep 13, 2023 · 1 comment

Comments

@AndreyLadniy
Copy link

AndreyLadniy commented Sep 13, 2023

Is it possible to add FiniteDuration parsing to the zio-config

Solution of the problem:

  case object FiniteDuration extends Primitive[scala.concurrent.duration.FiniteDuration] {
    final def parse(text: String): Either[Config.Error, scala.concurrent.duration.FiniteDuration] =
        Duration.parse(text).flatMap{
          case zio.Duration.Infinity => Left(Config.Error.InvalidData(Chunk.empty, s"Expected a finite duration value, but found ${text}"))
          case zio.Duration.Zero => Right(scala.concurrent.duration.Duration.Zero)
          case duration => Right(scala.concurrent.duration.FiniteDuration(duration.toNanos, TimeUnit.NANOSECONDS))
        }
  }
@mberndt123
Copy link
Contributor

@AndreyLadniy,
that probably belongs in zio core, not zio-config.

Try creating a PR here:
https://github.com/zio/zio/blob/series/2.x/core/shared/src/main/scala/zio/Config.scala

That said, I can't guarantee it'll be accepted as zio has its own Duration type (which is just an alias for the java.time one, but still). But you can try, after all you've already written the code…

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

No branches or pull requests

2 participants