You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a convenient way to get the Milliseconds between two Instants #98
This is a use case I have often when timing things.
I would like to avoid running unInstant in application code.
Maybe like this:
-- | Get the amount of milliseconds between the first and second Instant-- | for example:-- | ```-- | do-- | start <- Instant.now-- | aLongRunningEffect-- | end <- Instant.now-- | let duration = Instant.delta end start-- | log ("A long running effect took " <> show duration)-- | ```delta∷Instant→Instant→Milliseconds
delta i1 i2 = (unInstant i1) <> negateDuration (unInstant i2)
Yeah agreed, I was doing something with this just the other day and was surprised we'd not included something for it already.
I'd be tempted to make the type something like duration :: { start :: Instant, end :: Instant } -> Milliseconds to avoid confusion over argument order.
Yeah. Either way it's easy to get what you want. I guess the other Instant functions work in Milliseconds so maybe it'd make more sense to do the same here.
Activity
garyb commentedon May 19, 2022
Yeah agreed, I was doing something with this just the other day and was surprised we'd not included something for it already.
I'd be tempted to make the type something like
duration :: { start :: Instant, end :: Instant } -> Millisecondsto avoid confusion over argument order.hdgarrood commentedon May 19, 2022
This feels to me like it could be a nice use case for the Duration class?
i-am-the-slime commentedon May 19, 2022
Yes, but it risks to also be a bit annoying when trying to just log it with
showfor example, right?hdgarrood commentedon May 19, 2022
Yeah. Either way it's easy to get what you want. I guess the other
Instantfunctions work inMillisecondsso maybe it'd make more sense to do the same here.