Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.38 KB | None | 0 0
  1. {-#LANGUAGE ScopedTypeVariables#-}
  2. {-#LANGUAGE MagicHash#-}
  3.  
  4. -----------------------------------------------------------------------------
  5. -- |
  6. -- Module : System.Time
  7. -- Copyright : (c) The University of Glasgow 2001
  8. -- License : BSD-style (see the file libraries/old-time/LICENSE)
  9. --
  10. -- Maintainer : libraries@haskell.org
  11. -- Stability : provisional
  12. -- Portability : portable
  13. --
  14. -- The standard time library from Haskell 98. This library is
  15. -- deprecated, please look at @Data.Time@ in the @time@ package
  16. -- instead.
  17. --
  18. -- "System.Time" provides functionality for clock times, including
  19. -- timezone information (i.e, the functionality of \"@time.h@\",
  20. -- adapted to the Haskell environment). It follows RFC 1129 in its
  21. -- use of Coordinated Universal Time (UTC).
  22. --
  23. -----------------------------------------------------------------------------
  24.  
  25. {-
  26. Haskell 98 Time of Day Library
  27. ------------------------------
  28.  
  29. 2000/06/17 <michael.weber@post.rwth-aachen.de>:
  30. RESTRICTIONS:
  31. * min./max. time diff currently is restricted to
  32. [minBound::Int, maxBound::Int]
  33.  
  34. * surely other restrictions wrt. min/max bounds
  35.  
  36.  
  37. NOTES:
  38. * printing times
  39.  
  40. `showTime' (used in `instance Show ClockTime') always prints time
  41. converted to the local timezone (even if it is taken from
  42. `(toClockTime . toUTCTime)'), whereas `calendarTimeToString'
  43. honors the tzone & tz fields and prints UTC or whatever timezone
  44. is stored inside CalendarTime.
  45.  
  46. Maybe `showTime' should be changed to use UTC, since it would
  47. better correspond to the actual representation of `ClockTime'
  48. (can be done by replacing localtime(3) by gmtime(3)).
  49.  
  50.  
  51. BUGS:
  52. * add proper handling of microsecs, currently, they're mostly
  53. ignored
  54.  
  55. * `formatFOO' case of `%s' is currently broken...
  56.  
  57.  
  58. TODO:
  59. * check for unusual date cases, like 1970/1/1 00:00h, and conversions
  60. between different timezone's etc.
  61.  
  62. * check, what needs to be in the IO monad, the current situation
  63. seems to be a bit inconsistent to me
  64.  
  65. * check whether `isDst = -1' works as expected on other arch's
  66. (Solaris anyone?)
  67.  
  68. * add functions to parse strings to `CalendarTime' (some day...)
  69.  
  70. * implement padding capabilities ("%_", "%-") in `formatFOO'
  71.  
  72. * add rfc822 timezone (+0200 is CEST) representation ("%z") in `formatFOO'
  73. -}
  74.  
  75. module System.Time
  76. (
  77. -- * Clock times
  78.  
  79. ClockTime(..) -- non-standard, lib. report gives this as abstract
  80. -- instance Eq, Ord
  81. -- instance Show (non-standard)
  82.  
  83. , getClockTime
  84.  
  85. -- * Time differences
  86.  
  87. , TimeDiff(..)
  88. , noTimeDiff -- non-standard (but useful when constructing TimeDiff vals.)
  89. , diffClockTimes
  90. , addToClockTime
  91. , normalizeTimeDiff -- non-standard
  92. , timeDiffToString -- non-standard
  93. , formatTimeDiff -- non-standard
  94.  
  95. -- * Calendar times
  96.  
  97. , CalendarTime(..)
  98. , Month(..)
  99. , Day(..)
  100. , toCalendarTime
  101. , toUTCTime
  102. , toClockTime
  103. , calendarTimeToString
  104. , formatCalendarTime
  105.  
  106. ) where
  107.  
  108. -- #ifdef __GLASGOW_HASKELL__
  109. -- #include "HsTime.h"
  110. -- #endif
  111.  
  112. import Prelude
  113. import GHC.Pack
  114.  
  115. import Data.Ix
  116. import System.Locale
  117. import Foreign
  118. import System.IO.Unsafe (unsafePerformIO)
  119. import Foreign.C
  120.  
  121.  
  122. -- One way to partition and give name to chunks of a year and a week:
  123.  
  124. -- | A month of the year.
  125.  
  126. data Month
  127. = January | February | March | April
  128. | May | June | July | August
  129. | September | October | November | December
  130. deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)
  131.  
  132. -- | A day of the week.
  133.  
  134. data Day
  135. = Sunday | Monday | Tuesday | Wednesday
  136. | Thursday | Friday | Saturday
  137. deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)
  138.  
  139. -- | A representation of the internal clock time.
  140. -- Clock times may be compared, converted to strings, or converted to an
  141. -- external calendar time 'CalendarTime' for I\/O or other manipulations.
  142.  
  143. data ClockTime = TOD Integer Integer
  144. -- ^ Construct a clock time. The arguments are a number
  145. -- of seconds since 00:00:00 (UTC) on 1 January 1970,
  146. -- and an additional number of picoseconds.
  147. --
  148. -- In Haskell 98, the 'ClockTime' type is abstract.
  149. deriving (Eq, Ord)
  150.  
  151. -- When a ClockTime is shown, it is converted to a CalendarTime in the current
  152. -- timezone and then printed. FIXME: This is arguably wrong, since we can't
  153. -- get the current timezone without being in the IO monad.
  154.  
  155. instance Show ClockTime where
  156. showsPrec _ t = showString (calendarTimeToString
  157. (unsafePerformIO (toCalendarTime t)))
  158.  
  159. {-
  160. The numeric fields have the following ranges.
  161.  
  162. \begin{verbatim}
  163. Value Range Comments
  164. ----- ----- --------
  165.  
  166. year -maxInt .. maxInt [Pre-Gregorian dates are inaccurate]
  167. day 1 .. 31
  168. hour 0 .. 23
  169. min 0 .. 59
  170. sec 0 .. 61 [Allows for two leap seconds]
  171. picosec 0 .. (10^12)-1 [This could be over-precise?]
  172. yday 0 .. 365 [364 in non-Leap years]
  173. tz -43200 .. 50400 [Variation from UTC in seconds]
  174. \end{verbatim}
  175. -}
  176.  
  177. -- | 'CalendarTime' is a user-readable and manipulable
  178. -- representation of the internal 'ClockTime' type.
  179.  
  180. data CalendarTime
  181. = CalendarTime {
  182. ctYear :: Int -- ^ Year (pre-Gregorian dates are inaccurate)
  183. , ctMonth :: Month -- ^ Month of the year
  184. , ctDay :: Int -- ^ Day of the month (1 to 31)
  185. , ctHour :: Int -- ^ Hour of the day (0 to 23)
  186. , ctMin :: Int -- ^ Minutes (0 to 59)
  187. , ctSec :: Int -- ^ Seconds (0 to 61, allowing for up to
  188. -- two leap seconds)
  189. , ctPicosec :: Integer -- ^ Picoseconds
  190. , ctWDay :: Day -- ^ Day of the week
  191. , ctYDay :: Int -- ^ Day of the year
  192. -- (0 to 364, or 365 in leap years)
  193. , ctTZName :: String -- ^ Name of the time zone
  194. , ctTZ :: Int -- ^ Variation from UTC in seconds
  195. , ctIsDST :: Bool -- ^ 'True' if Daylight Savings Time would
  196. -- be in effect, and 'False' otherwise
  197. }
  198. deriving (Eq,Ord,Read,Show)
  199.  
  200. -- | records the difference between two clock times in a user-readable way.
  201.  
  202. data TimeDiff
  203. = TimeDiff {
  204. tdYear :: Int,
  205. tdMonth :: Int,
  206. tdDay :: Int,
  207. tdHour :: Int,
  208. tdMin :: Int,
  209. tdSec :: Int,
  210. tdPicosec :: Integer -- not standard
  211. }
  212. deriving (Eq,Ord,Read,Show)
  213.  
  214. -- | null time difference.
  215.  
  216. noTimeDiff :: TimeDiff
  217. noTimeDiff = TimeDiff 0 0 0 0 0 0 0
  218.  
  219. -- -----------------------------------------------------------------------------
  220. -- | returns the current time in its internal representation.
  221.  
  222. realToInteger :: Real a => a -> Integer
  223. realToInteger ct = round (realToFrac ct :: Double)
  224. -- CTime, CClock, CUShort etc are in Real but not Fractional,
  225. -- so we must convert to Double before we can round it
  226.  
  227. getClockTime :: IO ClockTime
  228. getClockTime = do
  229. let ctime = getClockTimePrim
  230. return $ milliSecondsToClockTime ctime
  231.  
  232. -- -----------------------------------------------------------------------------
  233. -- | @'addToClockTime' d t@ adds a time difference @d@ and a
  234. -- clock time @t@ to yield a new clock time. The difference @d@
  235. -- may be either positive or negative.
  236.  
  237. addToClockTime :: TimeDiff -> ClockTime -> ClockTime
  238. addToClockTime (TimeDiff year mon day hour minute sec psec)
  239. (TOD c_sec c_psec) =
  240. let
  241. sec_diff = toInteger sec +
  242. 60 * toInteger minute +
  243. 3600 * toInteger hour +
  244. 24 * 3600 * toInteger day
  245. (d_sec, d_psec) = (c_psec + psec) `quotRem` 1000000000000
  246. cal = toUTCTime (TOD (c_sec + sec_diff + d_sec) d_psec)
  247. new_mon = fromEnum (ctMonth cal) + r_mon
  248. month' = fst tmp
  249. yr_diff = snd tmp
  250. tmp
  251. | new_mon < 0 = (toEnum (12 + new_mon), (-1))
  252. | new_mon > 11 = (toEnum (new_mon `mod` 12), 1)
  253. | otherwise = (toEnum new_mon, 0)
  254.  
  255. (r_yr, r_mon) = mon `quotRem` 12
  256.  
  257. year' = ctYear cal + year + r_yr + yr_diff
  258. in
  259. toClockTime cal{ctMonth=month', ctYear=year'}
  260.  
  261. -- | @'diffClockTimes' t1 t2@ returns the difference between two clock
  262. -- times @t1@ and @t2@ as a 'TimeDiff'.
  263.  
  264. diffClockTimes :: ClockTime -> ClockTime -> TimeDiff
  265. -- diffClockTimes is meant to be the dual to `addToClockTime'.
  266. -- If you want to have the TimeDiff properly splitted, use
  267. -- `normalizeTimeDiff' on this function's result
  268. --
  269. -- CAVEAT: see comment of normalizeTimeDiff
  270. diffClockTimes (TOD sa pa) (TOD sb pb) =
  271. noTimeDiff{ tdSec = fromIntegral (sa - sb)
  272. -- FIXME: can handle just 68 years...
  273. , tdPicosec = pa - pb
  274. }
  275.  
  276.  
  277. -- | converts a time difference to normal form.
  278.  
  279. normalizeTimeDiff :: TimeDiff -> TimeDiff
  280. -- FIXME: handle psecs properly
  281. -- FIXME: ?should be called by formatTimeDiff automagically?
  282. --
  283. -- when applied to something coming out of `diffClockTimes', you loose
  284. -- the duality to `addToClockTime', since a year does not always have
  285. -- 365 days, etc.
  286. --
  287. -- apply this function as late as possible to prevent those "rounding"
  288. -- errors
  289. normalizeTimeDiff td =
  290. let
  291. rest0 = toInteger (tdSec td)
  292. + 60 * (toInteger (tdMin td)
  293. + 60 * (toInteger (tdHour td)
  294. + 24 * (toInteger (tdDay td)
  295. + 30 * toInteger (tdMonth td)
  296. + 365 * toInteger (tdYear td))))
  297.  
  298. (diffYears, rest1) = rest0 `quotRem` (365 * 24 * 3600)
  299. (diffMonths, rest2) = rest1 `quotRem` (30 * 24 * 3600)
  300. (diffDays, rest3) = rest2 `quotRem` (24 * 3600)
  301. (diffHours, rest4) = rest3 `quotRem` 3600
  302. (diffMins, diffSecs) = rest4 `quotRem` 60
  303. in
  304. td{ tdYear = fromInteger diffYears
  305. , tdMonth = fromInteger diffMonths
  306. , tdDay = fromInteger diffDays
  307. , tdHour = fromInteger diffHours
  308. , tdMin = fromInteger diffMins
  309. , tdSec = fromInteger diffSecs
  310. }
  311.  
  312.  
  313.  
  314. -- replace
  315.  
  316. -- | converts a 'CalendarTime' into the corresponding internal
  317. -- 'ClockTime', ignoring the contents of the 'ctWDay', 'ctYDay',
  318. -- 'ctTZName' and 'ctIsDST' fields.
  319.  
  320. toClockTime :: CalendarTime -> ClockTime
  321. toClockTime (CalendarTime year mon mday hour minute sec psec
  322. _wday _yday _tzname tz _isdst) = error "no"
  323.  
  324. -- -----------------------------------------------------------------------------
  325. -- Converting time values to strings.
  326.  
  327. -- | formats calendar times using local conventions.
  328.  
  329. calendarTimeToString :: CalendarTime -> String
  330. calendarTimeToString = formatCalendarTime defaultTimeLocale "%c"
  331.  
  332. -- | formats calendar times using local conventions and a formatting string.
  333. -- The formatting string is that understood by the ISO C @strftime()@
  334. -- function.
  335.  
  336. formatCalendarTime :: TimeLocale -> String -> CalendarTime -> String
  337. formatCalendarTime l fmt cal@(CalendarTime year mon day hour minute sec _
  338. wday yday tzname' _ _) =
  339. doFmt fmt
  340. where doFmt ('%':'-':cs) = doFmt ('%':cs) -- padding not implemented
  341. doFmt ('%':'_':cs) = doFmt ('%':cs) -- padding not implemented
  342. doFmt ('%':c:cs) = decode c ++ doFmt cs
  343. doFmt (c:cs) = c : doFmt cs
  344. doFmt "" = ""
  345.  
  346. decode 'A' = fst (wDays l !! fromEnum wday) -- day of the week, full name
  347. decode 'a' = snd (wDays l !! fromEnum wday) -- day of the week, abbrev.
  348. decode 'B' = fst (months l !! fromEnum mon) -- month, full name
  349. decode 'b' = snd (months l !! fromEnum mon) -- month, abbrev
  350. decode 'h' = snd (months l !! fromEnum mon) -- ditto
  351. decode 'C' = show2 (year `quot` 100) -- century
  352. decode 'c' = doFmt (dateTimeFmt l) -- locale's data and time format.
  353. decode 'D' = doFmt "%m/%d/%y"
  354. decode 'd' = show2 day -- day of the month
  355. decode 'e' = show2' day -- ditto, padded
  356. decode 'H' = show2 hour -- hours, 24-hour clock, padded
  357. decode 'I' = show2 (to12 hour) -- hours, 12-hour clock
  358. decode 'j' = show3 (yday + 1) -- day of the year
  359. decode 'k' = show2' hour -- hours, 24-hour clock, no padding
  360. decode 'l' = show2' (to12 hour) -- hours, 12-hour clock, no padding
  361. decode 'M' = show2 minute -- minutes
  362. decode 'm' = show2 (fromEnum mon+1) -- numeric month
  363. decode 'n' = "\n"
  364. decode 'p' = (if hour < 12 then fst else snd) (amPm l) -- am or pm
  365. decode 'R' = doFmt "%H:%M"
  366. decode 'r' = doFmt (time12Fmt l)
  367. decode 'T' = doFmt "%H:%M:%S"
  368. decode 't' = "\t"
  369. decode 'S' = show2 sec -- seconds
  370. decode 's' = let TOD esecs _ = toClockTime cal in show esecs
  371. -- number of secs since Epoch.
  372. decode 'U' = show2 ((yday + 7 - fromEnum wday) `div` 7) -- week number, starting on Sunday.
  373. decode 'u' = show (let n = fromEnum wday in -- numeric day of the week (1=Monday, 7=Sunday)
  374. if n == 0 then 7 else n)
  375. decode 'V' = -- week number (as per ISO-8601.)
  376. let (week, days) = -- [yep, I've always wanted to be able to display that too.]
  377. (yday + 7 - if fromEnum wday > 0 then
  378. fromEnum wday - 1 else 6) `divMod` 7
  379. in show2 (if days >= 4 then
  380. week+1
  381. else if week == 0 then 53 else week)
  382.  
  383. decode 'W' = -- week number, weeks starting on monday
  384. show2 ((yday + 7 - if fromEnum wday > 0 then
  385. fromEnum wday - 1 else 6) `div` 7)
  386. decode 'w' = show (fromEnum wday) -- numeric day of the week, weeks starting on Sunday.
  387. decode 'X' = doFmt (timeFmt l) -- locale's preferred way of printing time.
  388. decode 'x' = doFmt (dateFmt l) -- locale's preferred way of printing dates.
  389. decode 'Y' = show year -- year, including century.
  390. decode 'y' = show2 (year `rem` 100) -- year, within century.
  391. decode 'Z' = tzname' -- timezone name
  392. decode '%' = "%"
  393. decode c = [c]
  394.  
  395.  
  396. show2, show2', show3 :: Int -> String
  397. show2 x
  398. | x' < 10 = '0': show x'
  399. | otherwise = show x'
  400. where x' = x `rem` 100
  401.  
  402. show2' x
  403. | x' < 10 = ' ': show x'
  404. | otherwise = show x'
  405. where x' = x `rem` 100
  406.  
  407. show3 x = show (x `quot` 100) ++ show2 (x `rem` 100)
  408.  
  409. to12 :: Int -> Int
  410. to12 h = let h' = h `mod` 12 in if h' == 0 then 12 else h'
  411.  
  412. -- Useful extensions for formatting TimeDiffs.
  413.  
  414. -- | formats time differences using local conventions.
  415.  
  416. timeDiffToString :: TimeDiff -> String
  417. timeDiffToString = formatTimeDiff defaultTimeLocale "%c"
  418.  
  419. -- | formats time differences using local conventions and a formatting string.
  420. -- The formatting string is that understood by the ISO C @strftime()@
  421. -- function.
  422.  
  423. formatTimeDiff :: TimeLocale -> String -> TimeDiff -> String
  424. formatTimeDiff l fmt (TimeDiff year month day hour minute sec _)
  425. = doFmt fmt
  426. where
  427. doFmt "" = ""
  428. doFmt ('%':'-':cs) = doFmt ('%':cs) -- padding not implemented
  429. doFmt ('%':'_':cs) = doFmt ('%':cs) -- padding not implemented
  430. doFmt ('%':c:cs) = decode c ++ doFmt cs
  431. doFmt (c:cs) = c : doFmt cs
  432.  
  433. decode spec =
  434. case spec of
  435. 'B' -> fst (months l !! fromEnum month)
  436. 'b' -> snd (months l !! fromEnum month)
  437. 'h' -> snd (months l !! fromEnum month)
  438. 'c' -> defaultTimeDiffFmt
  439. 'C' -> show2 (year `quot` 100)
  440. 'D' -> doFmt "%m/%d/%y"
  441. 'd' -> show2 day
  442. 'e' -> show2' day
  443. 'H' -> show2 hour
  444. 'I' -> show2 (to12 hour)
  445. 'k' -> show2' hour
  446. 'l' -> show2' (to12 hour)
  447. 'M' -> show2 minute
  448. 'm' -> show2 (fromEnum month + 1)
  449. 'n' -> "\n"
  450. 'p' -> (if hour < 12 then fst else snd) (amPm l)
  451. 'R' -> doFmt "%H:%M"
  452. 'r' -> doFmt (time12Fmt l)
  453. 'T' -> doFmt "%H:%M:%S"
  454. 't' -> "\t"
  455. 'S' -> show2 sec
  456. 's' -> show2 sec -- Implementation-dependent, sez the lib doc..
  457. 'X' -> doFmt (timeFmt l)
  458. 'x' -> doFmt (dateFmt l)
  459. 'Y' -> show year
  460. 'y' -> show2 (year `rem` 100)
  461. '%' -> "%"
  462. c -> [c]
  463.  
  464. defaultTimeDiffFmt =
  465. foldr (\ (v,s) rest ->
  466. (if v /= 0
  467. then show v ++ ' ':(addS v s)
  468. ++ if null rest then "" else ", "
  469. else "") ++ rest
  470. )
  471. ""
  472. (zip [year, month, day, hour, minute, sec] (intervals l))
  473.  
  474. addS v s = if abs v == 1 then fst s else snd s
  475.  
  476. milliSecondsToClockTime :: Int64 -> ClockTime
  477. milliSecondsToClockTime sec = TOD sec' (rem * (10 ^ 12))
  478. where
  479. (sec' :: Integer,rem :: Integer) = quotRem secInt 1000
  480. secInt :: Integer = fromIntegral sec
  481.  
  482. clockTimeToMilliSeconds :: ClockTime -> Int64
  483. clockTimeToMilliSeconds (TOD sa pa) = fromIntegral (sa * 1000) + 0
  484.  
  485. data {-# CLASS "java.util.Calendar" #-} Calendar = Calendar (Object# Calendar)
  486.  
  487. -- Calendar.YEAR/DAY_OF_MONTH is constant, so no need for monadic context
  488.  
  489. foreign import java unsafe "@static @field Calendar.YEAR" yEAR :: Int
  490. foreign import java unsafe "@static @field Calendar.DAY_OF_MONTH" dAY_OF_MONTH :: Int
  491. foreign import java unsafe "@static @field Calendar.HOUR_OF_DAY" hOUR_OF_DAY :: Int
  492. foreign import java unsafe "@static @field Calendar.MINUTE" mINUTE :: Int
  493. foreign import java unsafe "@static @field Calendar.SECOND" sECOND :: Int
  494. foreign import java unsafe "@static @field Calendar.DAY_OF_YEAR" dAY_OF_YEAR :: Int
  495. foreign import java unsafe "@static @field Calendar.MILLISECOND" mILLISECOND :: Int
  496. foreign import java unsafe "@static ghcvm.oldtime.Utils.getTZ" getTZ :: JString
  497. foreign import java unsafe "@static ghcvm.oldtime.Utils.getClockTimePrim" getClockTimePrim :: Int64
  498. foreign import java unsafe "@static ghcvm.oldtime.Utils.getMonth" getMonth :: Int64 -> JString
  499. foreign import java unsafe "@static ghcvm.oldtime.Utils.getDayOfWeek" getDayOfWeek :: Int64 -> JString
  500. foreign import java unsafe "@static ghcvm.oldtime.Utils.getIsDST" getIsDST :: Bool
  501. foreign import java unsafe "@static ghcvm.oldtime.Utils.getCtTz" getCtTz :: Int
  502. foreign import java unsafe "@static ghcvm.oldtime.Utils.setTimeInMillis" setTimeInMillis :: Int64 -> Calendar
  503.  
  504. -- Again, you can make this pure given that you don't mutate the calendar after -- creation.
  505.  
  506. foreign import java unsafe "get" getField :: Calendar -> Int -> Int
  507.  
  508. getYear :: Calendar -> Int
  509. getYear = flip getField yEAR
  510.  
  511. flipField = flip getField
  512.  
  513. getDayOfMonth :: Calendar -> Int
  514. getDayOfMonth = flipField dAY_OF_MONTH
  515.  
  516. getMillisecond :: Calendar -> Int
  517. getMillisecond = flipField mILLISECOND
  518.  
  519. getHourOfDay :: Calendar -> Int
  520. getHourOfDay = flipField hOUR_OF_DAY
  521.  
  522. getMinute :: Calendar -> Int
  523. getMinute = flipField mINUTE
  524.  
  525. getSecond :: Calendar -> Int
  526. getSecond = flipField sECOND
  527.  
  528. getDayOfYear :: Calendar -> Int
  529. getDayOfYear = flipField dAY_OF_YEAR
  530.  
  531. calToCalendarTime :: Calendar -> CalendarTime
  532. calToCalendarTime cal = CalendarTime {
  533. ctYear = getYear cal
  534. , ctMonth = read $ unpackCString $ getMonth $ fromIntegral $ getMillisecond cal
  535. , ctDay = getDayOfMonth cal
  536. , ctHour = getHourOfDay cal
  537. , ctMin = getMinute cal
  538. , ctSec = getSecond cal
  539. , ctPicosec = 0
  540. , ctWDay = read $ unpackCString $ getDayOfWeek $ fromIntegral $ getMillisecond cal
  541. , ctYDay = getDayOfYear cal
  542. , ctTZName = unpackCString getTZ
  543. , ctTZ = (getCtTz `div` 1000)
  544. , ctIsDST = getIsDST
  545. }
  546.  
  547.  
  548.  
  549.  
  550. -- -----------------------------------------------------------------------------
  551. -- | converts an internal clock time to a local time, modified by the
  552. -- timezone and daylight savings time settings in force at the time
  553. -- of conversion. Because of this dependence on the local environment,
  554. -- 'toCalendarTime' is in the 'IO' monad.
  555.  
  556. toCalendarTime :: ClockTime -> IO CalendarTime
  557. toCalendarTime ct@(TOD sa pa)= return $ calToCalendarTime $ setTimeInMillis msec
  558. where msec = clockTimeToMilliSeconds ct
  559.  
  560. -- | converts an internal clock time into a 'CalendarTime' in standard
  561. -- UTC format.
  562.  
  563. toUTCTime :: ClockTime -> CalendarTime
  564. toUTCTime ct = calToCalendarTime $ setTimeInMillis (clockTimeToMilliSeconds ct)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement