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

Scala Duration support #416

Open
joan38 opened this issue Sep 8, 2022 · 1 comment
Open

Scala Duration support #416

joan38 opened this issue Sep 8, 2022 · 1 comment

Comments

@joan38
Copy link
Contributor

joan38 commented Sep 8, 2022

Hi,

Would you be open for me to open a PR to support scala.concurrent.duration.{Duration, FiniteDuration}?
As in:

  implicit val durationParser: ArgParser[Duration] =
    SimpleArgParser.from[Duration]("Duration")(s =>
      Either.catchOnly[NumberFormatException](Duration(s)).leftMap(e => MalformedValue("Duration", e.getMessage))
    )

  implicit val finiteDurationParser: ArgParser[FiniteDuration] =
    SimpleArgParser.from[FiniteDuration]("FiniteDuration")(s =>
      Either
        .catchOnly[NumberFormatException](Duration(s))
        .leftMap(e => MalformedValue("FiniteDuration", e.getMessage))
        .flatMap {
          case finite: FiniteDuration => Right(finite)
          case _ => Left(MalformedValue("FiniteDuration", s"Expected finite duration but found infinite duration: $s"))
        }
    )

Let me know
Thanks

@alexarchambault
Copy link
Owner

@joan38 Sure, that would work!

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