Everything from file timestamps to business transactions involve dates and times. Haskell provides ways for manipulating dates and times, as well as features for obtaining date and time information from the system.
In Haskell, the
System.Time module is primarily responsible for date and time handling. It
defines two types:
ClockTime is the Haskell version of the
traditional POSIX epoch. A
ClockTime represents a time relative to
midnight the morning of January 1, 1970, Coordinated Universal Time
(UTC). A negative
represents a number of seconds prior to that date, while a positive
number represents a count of seconds after it.
ClockTime is convenient for computations.
Since it tracks UTC, it doesn’t have to adjust for local time zones,
daylight saving time, or other special cases in time handling. Every
day is exactly (60 * 60 * 24) or 86,400 seconds, which makes time interval calculations simple. You can,
for instance, check the
ClockTime at the start of a long task,
again at the end, and simply subtract the start time from the end time
to determine how much time elapsed. You can then divide by 3,600 and
display the elapsed time as a count of hours if you wish.
ClockTime is ideal for answering questions
such as these:
How much time has elapsed?
What will be the
ClockTime 14 days ahead of this precise
When was the file last modified?
What is the precise time right now?
These are good uses of