Anyone knows of a Haskell package that can render NominalDiffTime
(or a similar type) as human readable time duration?
Some examples of what I mean:
f :: NominalDiffTime -> String
f 1 = "1 second"
f 10 = "10 seconds"
f 100 = "about 2 minutes"
f 10000 = "about 3 hours"
f 100000 = "about 1 day"
-- etc...
I've found a few that come close, but no cigar yet:
-
https://hackage.haskell.org/package/human-readable-duration
It has an output like: "2 years 33 days 2 min 3s 2ms", and I would prefer if I could ask for the most significant bit only, e.g. "2 years" since in my use case the rest is noise instead of information.
-
Another that comes close is: https://hackage.haskell.org/package/friendly-time-0.4/docs/Data-Time-Format-Human.html
Which is capable of printing the most significant unit, e.g. "3 days ago", but as far as I can see it is always relative to now and has the postfix " ago"/" from now".
A straightforward workaround could be to ask for the " ago" variety and always drop the last 4 characters.
-
Furthermore, there is also:
show (10000.123 :: NominalDiffTime) == "10000.123s"
But it's not very useful to just get an "s" postfix in my usecase.
Anyone knows of any package that comes closer to what I am looking for?