Handling timezones correctly, along with the distinction between timestamps and calendar dates is an endless source of bugs. Being precise about which exact type of time data your program takes in and spits out can completely obviate that problem.
The de-facto standard date and time library in Haskell, time, however, can be a little obtuse to get started with. Here’s a cheatsheet for the most common use cases for the time library.
Importing and using time library
Add to your package.yaml file:
1 2
dependencies: -time
In modules where you need to work with date/time data:
1
importData.Time
In GHCi:
1
Prelude> import Data.Time
The primitive type in the time library is UTCTime. If you need to do anything involving the current time, it will most likely involve some conversion from/to this type. As the name suggests, it’s a timestamp in the UTC timezone.