scala-library-next icon indicating copy to clipboard operation
scala-library-next copied to clipboard

FiniteDuration human representation

Open Lasering opened this issue 3 years ago • 2 comments

When debugging/inspecting code with timeouts/ellapsed times/etc using FiniteDuration seeing 2068493 seconds is not ergonomic, and in most cases unhelpful.

I suggest adding either of these things (or even everything):

  • A method that returns the duration per unit of time (Map[TimeUnit, Double]). For the example above it would be:

    Map(
      TimeUnit.DAYS -> 23,
      TimeUnit.HOURS -> 22,
      TimeUnit.MINUTES -> 34,
      TimeUnit.SECONDS -> 53,
    )
    
  • A method that returns a human readable string of the above. Keeping with the example it would return: 23 days, 22 hours, 34 minutes, 53 seconds

  • An approximate human readable string: About 24 days. This method could have some sort of max allowed error function.

Lasering avatar Aug 19 '22 14:08 Lasering

I like this option, seems to hit the debug use case and remain precise:

A method that returns a human readable string of the above. Keeping with the example it would return: 23 days, 22 hours, 34 minutes, 53 seconds

On Sat, Aug 20, 2022 at 12:41 AM Simão Martins @.***> wrote:

When debugging/inspecting code with timeouts/ellapsed times/etc using FiniteDuration seeing 2068493 seconds is not ergonomic, and in most cases unhelpful.

I suggest adding either of these things (or even everything):

A method that returns the duration per unit of time (Map[TimeUnit, Double]). For the example above it would be:

Map( TimeUnit.DAYS -> 23, TimeUnit.HOURS -> 22, TimeUnit.MINUTES -> 34, TimeUnit.SECONDS -> 53, )

A method that returns a human readable string of the above. Keeping with the example it would return: 23 days, 22 hours, 34 minutes, 53 seconds

An approximate human readable string: About 24 days. This method could have some sort of max allowed error function.

— Reply to this email directly, view it on GitHub https://github.com/scala/scala-library-next/issues/129, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAXJZDQLVYKGILRO2TBWVDVZ6MJTANCNFSM57A7ISLQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

benhutchison avatar Aug 19 '22 21:08 benhutchison

A method that returns a human readable string of the above.

This seems the most useful. The Map can already be done fairly easily, and the conversion to human-readable text isn't something you want to have to bother with whenever you need this.

The approximate string wouldn't really be helpful for one of the most common places I could see using this: failing test case output.

morgen-peschke avatar Aug 20 '22 02:08 morgen-peschke