Chris Stryczynski
Chris Stryczynski

Reputation: 34061

How do I create a UTCTime from Int values, using the thyme library in Haskell?

I've got a year, month, day, hour and minute value (all of them are of type Int) - how can I convert these to a UTCTime or UniversalTime?

Upvotes: 2

Views: 271

Answers (1)

chi
chi

Reputation: 116174

The following imports are required:

import Control.Lens
import Data.Thyme.Clock
import Data.Thyme.Calendar

And then:

makeUtcTime :: Year -> Month -> DayOfMonth -> Int -> UTCTime
makeUtcTime y m d x =  UTCTime ((YearMonthDay y m d)^.from gregorian) (toEnum x) ^. from utcTime

Within ghci:

:t makeUtcTime 2020 1 1 9143892431
makeUtcTime 2020 1 1 9143892431 :: UTCTime

(Perhaps there's a simpler way, but this is not too bad)

Upvotes: 3

Related Questions