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

Converting a Time (or DateTime) to seconds #85

Open
Kleidukos opened this issue Dec 4, 2023 · 2 comments
Open

Converting a Time (or DateTime) to seconds #85

Kleidukos opened this issue Dec 4, 2023 · 2 comments

Comments

@Kleidukos
Copy link
Collaborator

Hi, @andrewthad, I'm using cryptographic APIs that need sometimes a timestamp in seconds. Reading the API reference of Chronos it's not obvious which function I should use to convert a time or datetime object to an integer that expresses the time in seconds (instead of nanoseconds).

Is this a situation where the Torsor package is useful?

@andrewthad
Copy link
Member

Unfortunately, you have to open it up with the data constructor

newtype Time = Time { getTime :: Int64 }

and then divide it by a billion. I've personally stumbled across the need for timestamps with various precisions (typically millisecond precision) several times since writing this library, and I'm not aware of a good solution to this, at least not in a way that's compatible with chronos's API.

@Kleidukos
Copy link
Collaborator Author

Ok, thank you! quot ns 10^9 is good enough for me. :)

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