Skip to content

Add helpers to go from Instants to a duration #99

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

Merged
merged 3 commits into from
Jul 10, 2022

Conversation

i-am-the-slime
Copy link
Contributor

Description of the change

Fixes #98

Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@garyb
Copy link
Member

garyb commented May 29, 2022

Looks good to me! Do we like the name duration over delta? I know I was the one to suggest it, but I wonder if it's weird now since sometimes the result is going to be negative. I guess the library already promotes the idea of negative durations since the duration types don't have any restriction on that, but even still... thoughts?

@i-am-the-slime
Copy link
Contributor Author

@garyb I like duration much better. I wouldn't mind durationDelta either.

Copy link
Contributor

@JordanMartinez JordanMartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote durationDelta

@garyb garyb merged commit b17a455 into purescript:master Jul 10, 2022
@garyb
Copy link
Member

garyb commented Jul 10, 2022

Thanks, sorry about the wait!

@f-f
Copy link
Member

f-f commented Jul 15, 2022

Is this an equivalent implementation? (found it in the assorted datetime code I carry around my projects)

import Data.DateTime as DateTime
import Data.DateTime.Instant as Instant
import Data.Time.Duration as Duration

diffInstant :: forall a. Duration.Duration a => Instant -> Instant -> a
diffInstant a b = DateTime.diff (Instant.toDateTime a) (Instant.toDateTime b)

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

Successfully merging this pull request may close these issues.

Add a convenient way to get the Milliseconds between two Instants
4 participants