For old time's sake.
目錄
Today we will have a short overview of old data-/time-related packages listed as follows:
Those modules are very easily to use but have some shortcomings. The old-time(System.Time
) has poor supporting on locale and formating and lack functions to manipulate times. And the TimeDiff
is not very sueful. The old-locale(System.Locale
), however, is not very out-dated.
old-locale
The old-locale package provides module System.Locale
allowing to adapt to local conventions. There is just one single structure defined.
The TimeLocale
data TimeLocale = TimeLocale {
wDays :: [(String, String)],
months :: [(String, String)],
intervals :: [(String, String)],
amPm :: (String, String),
dateTimeFmt, dateFmt,
timeFmt, time12Fmt :: String
} ...
The difference bewteen Data.Time.Format.TimeLocale
and System.Locale.TimeLocale
is very ignorable. The most significant one is that the has knownTimeZones :: [TimeZone]
instead of intervals :: [(String, String)]
.
Extra
The package time-locale-compat is a interface for importing different versions of TimeLocale
. If the version of time is greater then 1.5.0, it will import Data.Time.Format
and import System.Locale
for otherwise.
old-time
The old-time package provide the System.Time
module that contains three distinct structures for representing times:
The ClockTime
The first one is used to represent raw system time in two integers.
One can extract system clock time by using
Besides ClockTime
there is also a structure for recording differenct between two clock times
The CalendarTime
The second structure in this module is CalendarTime
which will store time in a human-friendly structure:
Also, this module defines several converting function between CalendarTime
, ClockTime
and String
. Read old-time for more details.
Extra
There is a tiny package, time-compat, providing single typeclass ToUTCTime
that define a function toUTCTime
to convert an old-time structure to a Data.Time.UTCTime
.
It’s an simple example for
{-# LANGUAGE CPP #-}
.↩