Time Libraries Rough Draft
ashley at semantic.org
Wed Feb 9 06:24:07 EST 2005
This seems to be roughly where we're at with the time libraries. It's
now three modules, Clock, LeapSeconds, and Calendar. Most people will
have no need for LeapSeconds.
I've added two more things which haven't been discussed much. The first
is a getCPUTime function that returns the current "CPU time". This has
an arbitrary base, but it doesn't hiccup. The Unix interface for this is
a "clock()" function that returns time in some unit, and
CLOCKS_PER_SECOND, which is a constant to convert to seconds. I'm
assuming there's a Windows equivalent to this.
The second thing is a type-synonym of Rational for Julian dates. Julian
dates are a standard representation of UT1, where one unit is one day,
and UT1 is a good choice for representing Earth-based times in the far
past or future continuously.
* UTC arithmetic
* types or type-synonyms for Julian days and dates (for UT1)
* getting the current UTC time
* getting the current "CPU time"
* TAI arithmetic
* leap-second table type
* conversion between UTC and TAI with table
System.Time.Calendar (largely undiscussed so far):
* time zones
* getting the locale time zone
* converting times to Gregorian "calendrical" format
* calendrical arithmetic
e.g. one month after March 31st
* possibly "incomplete dates"
e.g. "May 1" for all years
* parsing and showing dates and times
Left for other libraries (standard or user):
* sunrise/sunset, moon phase, solstices & equinoxes, etc.
* figuring out time zone from position on Earth
* civil summertime zone adjustment calculation,
interface to zoneinfo database
* calendar systems other than Gregorian
* generalised sets over time
e.g. "2pm-4pm every 4th Saturday of the month"
module System.Time.Clock ( ... ) where
-- | standard Julian count of Earth days
type JulianDay = Integer
newtype DiffTime = MkDiffTime Integer
timeToSISeconds :: DiffTime -> Rational
siSecondsToTime :: Rational -> DiffTime
data UTCTime = MkUTCTime JulianDay DiffTime
newtype UTCDiffTime = MkUTCDiffTime Integer
utcTimeToUTCSeconds :: UTCDiffTime -> Rational
utcSecondsToUTCTime :: Rational -> UTCDiffTime
addUTCTime :: UTCDiffTime -> UTCTime -> UTCTime
diffUTCTime :: UTCTime -> UTCTime -> UTCDiffTime
...more arithmetic on UTCDiffTime...
-- | standard Julian dates for UT1, 1 = 1 day
type JulianDate = Rational
getCurrentTime :: IO UTCTime
getCPUTime :: IO DiffTime
-- | most people won't need this module
module System.Time.LeapSeconds ( ... ) where
-- | TAI
type AbsoluteTime = MkAbsoluteTime Integer
addAbsoluteTime :: DiffTime -> AbsoluteTime -> AbsoluteTime
diffAbsoluteTime :: AbsoluteTime -> AbsoluteTime -> DiffTime
-- | TAI - UTC during this day
type LeapSecondTable = JulianDay -> Int
utcDayLength :: LeapSecondTable -> JulianDay -> DiffTime
utcToTAITime :: LeapSecondTable -> UTCTime -> TAITime
taiToUTCTime :: LeapSecondTable -> TAITime -> UTCTime
... TBD ...
Ashley Yakeley, Seattle WA
More information about the Libraries