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

Add "ulidToUTCTime" function (or similar) #1

Open
ad-si opened this issue Jun 12, 2018 · 3 comments
Open

Add "ulidToUTCTime" function (or similar) #1

ad-si opened this issue Jun 12, 2018 · 3 comments

Comments

@ad-si
Copy link
Member

ad-si commented Jun 12, 2018

I'm missing a function to get the timestamp of a ulid.
Or is there a trick to get it I'm not aware of?

@ad-si
Copy link
Member Author

ad-si commented Jun 12, 2018

I'm now using following code in combination with hourglass:

ulidToDateTime :: Text -> DateTime
ulidToDateTime =
  timeGetDateTimeOfDay
  . Elapsed
  . (`div` 1000)
  . fromMaybe 0
  . Crock.decode
  . unpack
  . Data.Text.take 10

Shame on me for the fromMaybe 😅, but I'm validating the ulid already before, so it's OK =P

@ad-si
Copy link
Member Author

ad-si commented Jun 12, 2018

Better:

ulidToDateTime :: Text -> Maybe DateTime
ulidToDateTime =
  (fmap $
    timeGetDateTimeOfDay
    . Elapsed
    . (`div` 1000)
  )
  . Crock.decode
  . unpack
  . Data.Text.take 10

@ad-si ad-si self-assigned this Jul 10, 2018
@ad-si ad-si removed their assignment Mar 13, 2019
@ad-si
Copy link
Member Author

ad-si commented Apr 4, 2020

My current implementation can be found at https://github.com/ad-si/TaskLite/blob/master/tasklite-core/source/Utils.hs#L83

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

1 participant