{-# LINE 1 "System/Time.hsc" #-}
{-# LINE 2 "System/Time.hsc" #-}
{-# LANGUAGE Trustworthy #-}
{-# LINE 4 "System/Time.hsc" #-}
module System.Time
(
ClockTime(..)
, getClockTime
, TimeDiff(..)
, noTimeDiff
, diffClockTimes
, addToClockTime
, normalizeTimeDiff
, timeDiffToString
, formatTimeDiff
, CalendarTime(..)
, Month(..)
, Day(..)
, toCalendarTime
, toUTCTime
, toClockTime
, calendarTimeToString
, formatCalendarTime
) where
{-# LINE 111 "System/Time.hsc" #-}
{-# LINE 113 "System/Time.hsc" #-}
import Prelude
import Data.Ix
import System.Locale
import Foreign
import System.IO.Unsafe (unsafePerformIO)
{-# LINE 124 "System/Time.hsc" #-}
import Foreign.C
{-# LINE 126 "System/Time.hsc" #-}
data Month
= January | February | March | April
| May | June | July | August
| September | October | November | December
deriving (Month -> Month -> Bool
(Month -> Month -> Bool) -> (Month -> Month -> Bool) -> Eq Month
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Month -> Month -> Bool
== :: Month -> Month -> Bool
$c/= :: Month -> Month -> Bool
/= :: Month -> Month -> Bool
Eq, Eq Month
Eq Month =>
(Month -> Month -> Ordering)
-> (Month -> Month -> Bool)
-> (Month -> Month -> Bool)
-> (Month -> Month -> Bool)
-> (Month -> Month -> Bool)
-> (Month -> Month -> Month)
-> (Month -> Month -> Month)
-> Ord Month
Month -> Month -> Bool
Month -> Month -> Ordering
Month -> Month -> Month
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Month -> Month -> Ordering
compare :: Month -> Month -> Ordering
$c< :: Month -> Month -> Bool
< :: Month -> Month -> Bool
$c<= :: Month -> Month -> Bool
<= :: Month -> Month -> Bool
$c> :: Month -> Month -> Bool
> :: Month -> Month -> Bool
$c>= :: Month -> Month -> Bool
>= :: Month -> Month -> Bool
$cmax :: Month -> Month -> Month
max :: Month -> Month -> Month
$cmin :: Month -> Month -> Month
min :: Month -> Month -> Month
Ord, Int -> Month
Month -> Int
Month -> [Month]
Month -> Month
Month -> Month -> [Month]
Month -> Month -> Month -> [Month]
(Month -> Month)
-> (Month -> Month)
-> (Int -> Month)
-> (Month -> Int)
-> (Month -> [Month])
-> (Month -> Month -> [Month])
-> (Month -> Month -> [Month])
-> (Month -> Month -> Month -> [Month])
-> Enum Month
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Month -> Month
succ :: Month -> Month
$cpred :: Month -> Month
pred :: Month -> Month
$ctoEnum :: Int -> Month
toEnum :: Int -> Month
$cfromEnum :: Month -> Int
fromEnum :: Month -> Int
$cenumFrom :: Month -> [Month]
enumFrom :: Month -> [Month]
$cenumFromThen :: Month -> Month -> [Month]
enumFromThen :: Month -> Month -> [Month]
$cenumFromTo :: Month -> Month -> [Month]
enumFromTo :: Month -> Month -> [Month]
$cenumFromThenTo :: Month -> Month -> Month -> [Month]
enumFromThenTo :: Month -> Month -> Month -> [Month]
Enum, Month
Month -> Month -> Bounded Month
forall a. a -> a -> Bounded a
$cminBound :: Month
minBound :: Month
$cmaxBound :: Month
maxBound :: Month
Bounded, Ord Month
Ord Month =>
((Month, Month) -> [Month])
-> ((Month, Month) -> Month -> Int)
-> ((Month, Month) -> Month -> Int)
-> ((Month, Month) -> Month -> Bool)
-> ((Month, Month) -> Int)
-> ((Month, Month) -> Int)
-> Ix Month
(Month, Month) -> Int
(Month, Month) -> [Month]
(Month, Month) -> Month -> Bool
(Month, Month) -> Month -> Int
forall a.
Ord a =>
((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
$crange :: (Month, Month) -> [Month]
range :: (Month, Month) -> [Month]
$cindex :: (Month, Month) -> Month -> Int
index :: (Month, Month) -> Month -> Int
$cunsafeIndex :: (Month, Month) -> Month -> Int
unsafeIndex :: (Month, Month) -> Month -> Int
$cinRange :: (Month, Month) -> Month -> Bool
inRange :: (Month, Month) -> Month -> Bool
$crangeSize :: (Month, Month) -> Int
rangeSize :: (Month, Month) -> Int
$cunsafeRangeSize :: (Month, Month) -> Int
unsafeRangeSize :: (Month, Month) -> Int
Ix, ReadPrec [Month]
ReadPrec Month
Int -> ReadS Month
ReadS [Month]
(Int -> ReadS Month)
-> ReadS [Month]
-> ReadPrec Month
-> ReadPrec [Month]
-> Read Month
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Month
readsPrec :: Int -> ReadS Month
$creadList :: ReadS [Month]
readList :: ReadS [Month]
$creadPrec :: ReadPrec Month
readPrec :: ReadPrec Month
$creadListPrec :: ReadPrec [Month]
readListPrec :: ReadPrec [Month]
Read, Int -> Month -> ShowS
[Month] -> ShowS
Month -> String
(Int -> Month -> ShowS)
-> (Month -> String) -> ([Month] -> ShowS) -> Show Month
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Month -> ShowS
showsPrec :: Int -> Month -> ShowS
$cshow :: Month -> String
show :: Month -> String
$cshowList :: [Month] -> ShowS
showList :: [Month] -> ShowS
Show)
data Day
= Sunday | Monday | Tuesday | Wednesday
| Thursday | Friday | Saturday
deriving (Day -> Day -> Bool
(Day -> Day -> Bool) -> (Day -> Day -> Bool) -> Eq Day
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Day -> Day -> Bool
== :: Day -> Day -> Bool
$c/= :: Day -> Day -> Bool
/= :: Day -> Day -> Bool
Eq, Eq Day
Eq Day =>
(Day -> Day -> Ordering)
-> (Day -> Day -> Bool)
-> (Day -> Day -> Bool)
-> (Day -> Day -> Bool)
-> (Day -> Day -> Bool)
-> (Day -> Day -> Day)
-> (Day -> Day -> Day)
-> Ord Day
Day -> Day -> Bool
Day -> Day -> Ordering
Day -> Day -> Day
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Day -> Day -> Ordering
compare :: Day -> Day -> Ordering
$c< :: Day -> Day -> Bool
< :: Day -> Day -> Bool
$c<= :: Day -> Day -> Bool
<= :: Day -> Day -> Bool
$c> :: Day -> Day -> Bool
> :: Day -> Day -> Bool
$c>= :: Day -> Day -> Bool
>= :: Day -> Day -> Bool
$cmax :: Day -> Day -> Day
max :: Day -> Day -> Day
$cmin :: Day -> Day -> Day
min :: Day -> Day -> Day
Ord, Int -> Day
Day -> Int
Day -> [Day]
Day -> Day
Day -> Day -> [Day]
Day -> Day -> Day -> [Day]
(Day -> Day)
-> (Day -> Day)
-> (Int -> Day)
-> (Day -> Int)
-> (Day -> [Day])
-> (Day -> Day -> [Day])
-> (Day -> Day -> [Day])
-> (Day -> Day -> Day -> [Day])
-> Enum Day
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Day -> Day
succ :: Day -> Day
$cpred :: Day -> Day
pred :: Day -> Day
$ctoEnum :: Int -> Day
toEnum :: Int -> Day
$cfromEnum :: Day -> Int
fromEnum :: Day -> Int
$cenumFrom :: Day -> [Day]
enumFrom :: Day -> [Day]
$cenumFromThen :: Day -> Day -> [Day]
enumFromThen :: Day -> Day -> [Day]
$cenumFromTo :: Day -> Day -> [Day]
enumFromTo :: Day -> Day -> [Day]
$cenumFromThenTo :: Day -> Day -> Day -> [Day]
enumFromThenTo :: Day -> Day -> Day -> [Day]
Enum, Day
Day -> Day -> Bounded Day
forall a. a -> a -> Bounded a
$cminBound :: Day
minBound :: Day
$cmaxBound :: Day
maxBound :: Day
Bounded, Ord Day
Ord Day =>
((Day, Day) -> [Day])
-> ((Day, Day) -> Day -> Int)
-> ((Day, Day) -> Day -> Int)
-> ((Day, Day) -> Day -> Bool)
-> ((Day, Day) -> Int)
-> ((Day, Day) -> Int)
-> Ix Day
(Day, Day) -> Int
(Day, Day) -> [Day]
(Day, Day) -> Day -> Bool
(Day, Day) -> Day -> Int
forall a.
Ord a =>
((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
$crange :: (Day, Day) -> [Day]
range :: (Day, Day) -> [Day]
$cindex :: (Day, Day) -> Day -> Int
index :: (Day, Day) -> Day -> Int
$cunsafeIndex :: (Day, Day) -> Day -> Int
unsafeIndex :: (Day, Day) -> Day -> Int
$cinRange :: (Day, Day) -> Day -> Bool
inRange :: (Day, Day) -> Day -> Bool
$crangeSize :: (Day, Day) -> Int
rangeSize :: (Day, Day) -> Int
$cunsafeRangeSize :: (Day, Day) -> Int
unsafeRangeSize :: (Day, Day) -> Int
Ix, ReadPrec [Day]
ReadPrec Day
Int -> ReadS Day
ReadS [Day]
(Int -> ReadS Day)
-> ReadS [Day] -> ReadPrec Day -> ReadPrec [Day] -> Read Day
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Day
readsPrec :: Int -> ReadS Day
$creadList :: ReadS [Day]
readList :: ReadS [Day]
$creadPrec :: ReadPrec Day
readPrec :: ReadPrec Day
$creadListPrec :: ReadPrec [Day]
readListPrec :: ReadPrec [Day]
Read, Int -> Day -> ShowS
[Day] -> ShowS
Day -> String
(Int -> Day -> ShowS)
-> (Day -> String) -> ([Day] -> ShowS) -> Show Day
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Day -> ShowS
showsPrec :: Int -> Day -> ShowS
$cshow :: Day -> String
show :: Day -> String
$cshowList :: [Day] -> ShowS
showList :: [Day] -> ShowS
Show)
data ClockTime = TOD Integer Integer
deriving (ClockTime -> ClockTime -> Bool
(ClockTime -> ClockTime -> Bool)
-> (ClockTime -> ClockTime -> Bool) -> Eq ClockTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClockTime -> ClockTime -> Bool
== :: ClockTime -> ClockTime -> Bool
$c/= :: ClockTime -> ClockTime -> Bool
/= :: ClockTime -> ClockTime -> Bool
Eq, Eq ClockTime
Eq ClockTime =>
(ClockTime -> ClockTime -> Ordering)
-> (ClockTime -> ClockTime -> Bool)
-> (ClockTime -> ClockTime -> Bool)
-> (ClockTime -> ClockTime -> Bool)
-> (ClockTime -> ClockTime -> Bool)
-> (ClockTime -> ClockTime -> ClockTime)
-> (ClockTime -> ClockTime -> ClockTime)
-> Ord ClockTime
ClockTime -> ClockTime -> Bool
ClockTime -> ClockTime -> Ordering
ClockTime -> ClockTime -> ClockTime
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ClockTime -> ClockTime -> Ordering
compare :: ClockTime -> ClockTime -> Ordering
$c< :: ClockTime -> ClockTime -> Bool
< :: ClockTime -> ClockTime -> Bool
$c<= :: ClockTime -> ClockTime -> Bool
<= :: ClockTime -> ClockTime -> Bool
$c> :: ClockTime -> ClockTime -> Bool
> :: ClockTime -> ClockTime -> Bool
$c>= :: ClockTime -> ClockTime -> Bool
>= :: ClockTime -> ClockTime -> Bool
$cmax :: ClockTime -> ClockTime -> ClockTime
max :: ClockTime -> ClockTime -> ClockTime
$cmin :: ClockTime -> ClockTime -> ClockTime
min :: ClockTime -> ClockTime -> ClockTime
Ord)
instance Show ClockTime where
showsPrec :: Int -> ClockTime -> ShowS
showsPrec Int
_ ClockTime
t = String -> ShowS
showString (CalendarTime -> String
calendarTimeToString
(IO CalendarTime -> CalendarTime
forall a. IO a -> a
unsafePerformIO (ClockTime -> IO CalendarTime
toCalendarTime ClockTime
t)))
data CalendarTime
= CalendarTime {
CalendarTime -> Int
ctYear :: Int
, CalendarTime -> Month
ctMonth :: Month
, CalendarTime -> Int
ctDay :: Int
, CalendarTime -> Int
ctHour :: Int
, CalendarTime -> Int
ctMin :: Int
, CalendarTime -> Int
ctSec :: Int
, CalendarTime -> Integer
ctPicosec :: Integer
, CalendarTime -> Day
ctWDay :: Day
, CalendarTime -> Int
ctYDay :: Int
, CalendarTime -> String
ctTZName :: String
, CalendarTime -> Int
ctTZ :: Int
, CalendarTime -> Bool
ctIsDST :: Bool
}
deriving (CalendarTime -> CalendarTime -> Bool
(CalendarTime -> CalendarTime -> Bool)
-> (CalendarTime -> CalendarTime -> Bool) -> Eq CalendarTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CalendarTime -> CalendarTime -> Bool
== :: CalendarTime -> CalendarTime -> Bool
$c/= :: CalendarTime -> CalendarTime -> Bool
/= :: CalendarTime -> CalendarTime -> Bool
Eq,Eq CalendarTime
Eq CalendarTime =>
(CalendarTime -> CalendarTime -> Ordering)
-> (CalendarTime -> CalendarTime -> Bool)
-> (CalendarTime -> CalendarTime -> Bool)
-> (CalendarTime -> CalendarTime -> Bool)
-> (CalendarTime -> CalendarTime -> Bool)
-> (CalendarTime -> CalendarTime -> CalendarTime)
-> (CalendarTime -> CalendarTime -> CalendarTime)
-> Ord CalendarTime
CalendarTime -> CalendarTime -> Bool
CalendarTime -> CalendarTime -> Ordering
CalendarTime -> CalendarTime -> CalendarTime
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CalendarTime -> CalendarTime -> Ordering
compare :: CalendarTime -> CalendarTime -> Ordering
$c< :: CalendarTime -> CalendarTime -> Bool
< :: CalendarTime -> CalendarTime -> Bool
$c<= :: CalendarTime -> CalendarTime -> Bool
<= :: CalendarTime -> CalendarTime -> Bool
$c> :: CalendarTime -> CalendarTime -> Bool
> :: CalendarTime -> CalendarTime -> Bool
$c>= :: CalendarTime -> CalendarTime -> Bool
>= :: CalendarTime -> CalendarTime -> Bool
$cmax :: CalendarTime -> CalendarTime -> CalendarTime
max :: CalendarTime -> CalendarTime -> CalendarTime
$cmin :: CalendarTime -> CalendarTime -> CalendarTime
min :: CalendarTime -> CalendarTime -> CalendarTime
Ord,ReadPrec [CalendarTime]
ReadPrec CalendarTime
Int -> ReadS CalendarTime
ReadS [CalendarTime]
(Int -> ReadS CalendarTime)
-> ReadS [CalendarTime]
-> ReadPrec CalendarTime
-> ReadPrec [CalendarTime]
-> Read CalendarTime
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CalendarTime
readsPrec :: Int -> ReadS CalendarTime
$creadList :: ReadS [CalendarTime]
readList :: ReadS [CalendarTime]
$creadPrec :: ReadPrec CalendarTime
readPrec :: ReadPrec CalendarTime
$creadListPrec :: ReadPrec [CalendarTime]
readListPrec :: ReadPrec [CalendarTime]
Read,Int -> CalendarTime -> ShowS
[CalendarTime] -> ShowS
CalendarTime -> String
(Int -> CalendarTime -> ShowS)
-> (CalendarTime -> String)
-> ([CalendarTime] -> ShowS)
-> Show CalendarTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CalendarTime -> ShowS
showsPrec :: Int -> CalendarTime -> ShowS
$cshow :: CalendarTime -> String
show :: CalendarTime -> String
$cshowList :: [CalendarTime] -> ShowS
showList :: [CalendarTime] -> ShowS
Show)
data TimeDiff
= TimeDiff {
TimeDiff -> Int
tdYear :: Int,
TimeDiff -> Int
tdMonth :: Int,
TimeDiff -> Int
tdDay :: Int,
TimeDiff -> Int
tdHour :: Int,
TimeDiff -> Int
tdMin :: Int,
TimeDiff -> Int
tdSec :: Int,
TimeDiff -> Integer
tdPicosec :: Integer
}
deriving (TimeDiff -> TimeDiff -> Bool
(TimeDiff -> TimeDiff -> Bool)
-> (TimeDiff -> TimeDiff -> Bool) -> Eq TimeDiff
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TimeDiff -> TimeDiff -> Bool
== :: TimeDiff -> TimeDiff -> Bool
$c/= :: TimeDiff -> TimeDiff -> Bool
/= :: TimeDiff -> TimeDiff -> Bool
Eq,Eq TimeDiff
Eq TimeDiff =>
(TimeDiff -> TimeDiff -> Ordering)
-> (TimeDiff -> TimeDiff -> Bool)
-> (TimeDiff -> TimeDiff -> Bool)
-> (TimeDiff -> TimeDiff -> Bool)
-> (TimeDiff -> TimeDiff -> Bool)
-> (TimeDiff -> TimeDiff -> TimeDiff)
-> (TimeDiff -> TimeDiff -> TimeDiff)
-> Ord TimeDiff
TimeDiff -> TimeDiff -> Bool
TimeDiff -> TimeDiff -> Ordering
TimeDiff -> TimeDiff -> TimeDiff
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TimeDiff -> TimeDiff -> Ordering
compare :: TimeDiff -> TimeDiff -> Ordering
$c< :: TimeDiff -> TimeDiff -> Bool
< :: TimeDiff -> TimeDiff -> Bool
$c<= :: TimeDiff -> TimeDiff -> Bool
<= :: TimeDiff -> TimeDiff -> Bool
$c> :: TimeDiff -> TimeDiff -> Bool
> :: TimeDiff -> TimeDiff -> Bool
$c>= :: TimeDiff -> TimeDiff -> Bool
>= :: TimeDiff -> TimeDiff -> Bool
$cmax :: TimeDiff -> TimeDiff -> TimeDiff
max :: TimeDiff -> TimeDiff -> TimeDiff
$cmin :: TimeDiff -> TimeDiff -> TimeDiff
min :: TimeDiff -> TimeDiff -> TimeDiff
Ord,ReadPrec [TimeDiff]
ReadPrec TimeDiff
Int -> ReadS TimeDiff
ReadS [TimeDiff]
(Int -> ReadS TimeDiff)
-> ReadS [TimeDiff]
-> ReadPrec TimeDiff
-> ReadPrec [TimeDiff]
-> Read TimeDiff
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TimeDiff
readsPrec :: Int -> ReadS TimeDiff
$creadList :: ReadS [TimeDiff]
readList :: ReadS [TimeDiff]
$creadPrec :: ReadPrec TimeDiff
readPrec :: ReadPrec TimeDiff
$creadListPrec :: ReadPrec [TimeDiff]
readListPrec :: ReadPrec [TimeDiff]
Read,Int -> TimeDiff -> ShowS
[TimeDiff] -> ShowS
TimeDiff -> String
(Int -> TimeDiff -> ShowS)
-> (TimeDiff -> String) -> ([TimeDiff] -> ShowS) -> Show TimeDiff
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TimeDiff -> ShowS
showsPrec :: Int -> TimeDiff -> ShowS
$cshow :: TimeDiff -> String
show :: TimeDiff -> String
$cshowList :: [TimeDiff] -> ShowS
showList :: [TimeDiff] -> ShowS
Show)
noTimeDiff :: TimeDiff
noTimeDiff :: TimeDiff
noTimeDiff = Int -> Int -> Int -> Int -> Int -> Int -> Integer -> TimeDiff
TimeDiff Int
0 Int
0 Int
0 Int
0 Int
0 Int
0 Integer
0
realToInteger :: Real a => a -> Integer
realToInteger :: forall a. Real a => a -> Integer
realToInteger a
ct = Double -> Integer
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (a -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac a
ct :: Double)
getClockTime :: IO ClockTime
{-# LINE 239 "System/Time.hsc" #-}
{-# LINE 244 "System/Time.hsc" #-}
type Timeval_tv_sec = CTime
type Timeval_tv_usec = CSUSeconds
{-# LINE 247 "System/Time.hsc" #-}
getClockTime :: IO ClockTime
getClockTime = do
Int -> (Ptr CTimeVal -> IO ClockTime) -> IO ClockTime
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes (Int
16) ((Ptr CTimeVal -> IO ClockTime) -> IO ClockTime)
-> (Ptr CTimeVal -> IO ClockTime) -> IO ClockTime
forall a b. (a -> b) -> a -> b
$ \ Ptr CTimeVal
p_timeval -> do
{-# LINE 250 "System/Time.hsc" #-}
throwErrnoIfMinus1_ "getClockTime" $ gettimeofday p_timeval nullPtr
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p_timeval :: IO Timeval_tv_sec
{-# LINE 252 "System/Time.hsc" #-}
usec <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p_timeval :: IO Timeval_tv_usec
{-# LINE 253 "System/Time.hsc" #-}
return (TOD (realToInteger sec) ((realToInteger usec) * 1000000))
{-# LINE 269 "System/Time.hsc" #-}
addToClockTime :: TimeDiff -> ClockTime -> ClockTime
addToClockTime :: TimeDiff -> ClockTime -> ClockTime
addToClockTime (TimeDiff Int
year Int
mon Int
day Int
hour Int
minute Int
sec Integer
psec)
(TOD Integer
c_sec Integer
c_psec) =
let
sec_diff :: Integer
sec_diff = Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
sec Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+
Integer
60 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
minute Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+
Integer
3600 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
hour Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+
Integer
24 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
3600 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
day
(Integer
d_sec, Integer
d_psec) = (Integer
c_psec Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
psec) Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
1000000000000
cal :: CalendarTime
cal = ClockTime -> CalendarTime
toUTCTime (Integer -> Integer -> ClockTime
TOD (Integer
c_sec Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
sec_diff Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
d_sec) Integer
d_psec)
new_mon :: Int
new_mon = Month -> Int
forall a. Enum a => a -> Int
fromEnum (CalendarTime -> Month
ctMonth CalendarTime
cal) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
r_mon
month' :: Month
month' = (Month, Int) -> Month
forall a b. (a, b) -> a
fst (Month, Int)
tmp
yr_diff :: Int
yr_diff = (Month, Int) -> Int
forall a b. (a, b) -> b
snd (Month, Int)
tmp
tmp :: (Month, Int)
tmp
| Int
new_mon Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 = (Int -> Month
forall a. Enum a => Int -> a
toEnum (Int
12 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
new_mon), (-Int
1))
| Int
new_mon Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
11 = (Int -> Month
forall a. Enum a => Int -> a
toEnum (Int
new_mon Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
12), Int
1)
| Bool
otherwise = (Int -> Month
forall a. Enum a => Int -> a
toEnum Int
new_mon, Int
0)
(Int
r_yr, Int
r_mon) = Int
mon Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Int
12
year' :: Int
year' = CalendarTime -> Int
ctYear CalendarTime
cal Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
year Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
r_yr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
yr_diff
in
CalendarTime -> ClockTime
toClockTime CalendarTime
cal{ctMonth=month', ctYear=year'}
diffClockTimes :: ClockTime -> ClockTime -> TimeDiff
diffClockTimes :: ClockTime -> ClockTime -> TimeDiff
diffClockTimes (TOD Integer
sa Integer
pa) (TOD Integer
sb Integer
pb) =
TimeDiff
noTimeDiff{ tdSec = fromIntegral (sa - sb)
, tdPicosec = pa - pb
}
normalizeTimeDiff :: TimeDiff -> TimeDiff
normalizeTimeDiff :: TimeDiff -> TimeDiff
normalizeTimeDiff TimeDiff
td =
let
rest0 :: Integer
rest0 = Int -> Integer
forall a. Integral a => a -> Integer
toInteger (TimeDiff -> Int
tdSec TimeDiff
td)
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
60 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (TimeDiff -> Int
tdMin TimeDiff
td)
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
60 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (TimeDiff -> Int
tdHour TimeDiff
td)
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
24 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (TimeDiff -> Int
tdDay TimeDiff
td)
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
30 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Int -> Integer
forall a. Integral a => a -> Integer
toInteger (TimeDiff -> Int
tdMonth TimeDiff
td)
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
365 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Int -> Integer
forall a. Integral a => a -> Integer
toInteger (TimeDiff -> Int
tdYear TimeDiff
td))))
(Integer
diffYears, Integer
rest1) = Integer
rest0 Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` (Integer
365 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
24 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
3600)
(Integer
diffMonths, Integer
rest2) = Integer
rest1 Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` (Integer
30 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
24 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
3600)
(Integer
diffDays, Integer
rest3) = Integer
rest2 Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` (Integer
24 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
3600)
(Integer
diffHours, Integer
rest4) = Integer
rest3 Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
3600
(Integer
diffMins, Integer
diffSecs) = Integer
rest4 Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
60
in
TimeDiff
td{ tdYear = fromInteger diffYears
, tdMonth = fromInteger diffMonths
, tdDay = fromInteger diffDays
, tdHour = fromInteger diffHours
, tdMin = fromInteger diffMins
, tdSec = fromInteger diffSecs
}
{-# LINE 351 "System/Time.hsc" #-}
zone :: Ptr CTm -> IO (Ptr CChar)
gmtoff :: Ptr CTm -> IO CLong
{-# LINE 361 "System/Time.hsc" #-}
zone x = ((\hsc_ptr -> peekByteOff hsc_ptr 48)) x
{-# LINE 362 "System/Time.hsc" #-}
gmtoff x = ((\hsc_ptr -> peekByteOff hsc_ptr 40)) x
{-# LINE 363 "System/Time.hsc" #-}
{-# LINE 410 "System/Time.hsc" #-}
{-# LINE 411 "System/Time.hsc" #-}
toCalendarTime :: ClockTime -> IO CalendarTime
{-# LINE 422 "System/Time.hsc" #-}
toCalendarTime :: ClockTime -> IO CalendarTime
toCalendarTime = (Ptr CTime -> Ptr CTimeVal -> IO CTimeVal)
-> Bool -> ClockTime -> IO CalendarTime
clockToCalendarTime_reentrant ((Ptr CTime -> Ptr CTimeVal -> IO (Ptr CTimeVal))
-> Ptr CTime -> Ptr CTimeVal -> IO CTimeVal
_throwAwayReturnPointer Ptr CTime -> Ptr CTimeVal -> IO (Ptr CTimeVal)
localtime_r) Bool
False
{-# LINE 426 "System/Time.hsc" #-}
toUTCTime :: ClockTime -> CalendarTime
{-# LINE 434 "System/Time.hsc" #-}
toUTCTime :: ClockTime -> CalendarTime
toUTCTime = IO CalendarTime -> CalendarTime
forall a. IO a -> a
unsafePerformIO (IO CalendarTime -> CalendarTime)
-> (ClockTime -> IO CalendarTime) -> ClockTime -> CalendarTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ptr CTime -> Ptr CTimeVal -> IO CTimeVal)
-> Bool -> ClockTime -> IO CalendarTime
clockToCalendarTime_reentrant ((Ptr CTime -> Ptr CTimeVal -> IO (Ptr CTimeVal))
-> Ptr CTime -> Ptr CTimeVal -> IO CTimeVal
_throwAwayReturnPointer Ptr CTime -> Ptr CTimeVal -> IO (Ptr CTimeVal)
gmtime_r) Bool
True
{-# LINE 438 "System/Time.hsc" #-}
{-# LINE 463 "System/Time.hsc" #-}
_throwAwayReturnPointer :: (Ptr CTime -> Ptr CTm -> IO (Ptr CTm))
-> (Ptr CTime -> Ptr CTm -> IO ( ))
_throwAwayReturnPointer :: (Ptr CTime -> Ptr CTimeVal -> IO (Ptr CTimeVal))
-> Ptr CTime -> Ptr CTimeVal -> IO CTimeVal
_throwAwayReturnPointer Ptr CTime -> Ptr CTimeVal -> IO (Ptr CTimeVal)
fun Ptr CTime
x Ptr CTimeVal
y = Ptr CTime -> Ptr CTimeVal -> IO (Ptr CTimeVal)
fun Ptr CTime
x Ptr CTimeVal
y IO (Ptr CTimeVal) -> IO CTimeVal -> IO CTimeVal
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CTimeVal -> IO CTimeVal
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# LINE 475 "System/Time.hsc" #-}
{-# LINE 477 "System/Time.hsc" #-}
clockToCalendarTime_reentrant :: (Ptr CTime -> Ptr CTm -> IO ()) -> Bool -> ClockTime
-> IO CalendarTime
clockToCalendarTime_reentrant :: (Ptr CTime -> Ptr CTimeVal -> IO CTimeVal)
-> Bool -> ClockTime -> IO CalendarTime
clockToCalendarTime_reentrant Ptr CTime -> Ptr CTimeVal -> IO CTimeVal
fun Bool
is_utc (TOD Integer
secs Integer
psec) = do
CTime -> (Ptr CTime -> IO CalendarTime) -> IO CalendarTime
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with (Integer -> CTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
secs :: CTime) ((Ptr CTime -> IO CalendarTime) -> IO CalendarTime)
-> (Ptr CTime -> IO CalendarTime) -> IO CalendarTime
forall a b. (a -> b) -> a -> b
$ \ Ptr CTime
p_timer -> do
Int -> (Ptr CTimeVal -> IO CalendarTime) -> IO CalendarTime
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes (Int
56) ((Ptr CTimeVal -> IO CalendarTime) -> IO CalendarTime)
-> (Ptr CTimeVal -> IO CalendarTime) -> IO CalendarTime
forall a b. (a -> b) -> a -> b
$ \ Ptr CTimeVal
p_tm -> do
{-# LINE 482 "System/Time.hsc" #-}
fun p_timer p_tm
clockToCalendarTime_aux is_utc p_tm psec
{-# LINE 485 "System/Time.hsc" #-}
clockToCalendarTime_aux :: Bool -> Ptr CTm -> Integer -> IO CalendarTime
clockToCalendarTime_aux :: Bool -> Ptr CTimeVal -> Integer -> IO CalendarTime
clockToCalendarTime_aux Bool
is_utc Ptr CTimeVal
p_tm Integer
psec = do
CInt
sec <- ((\Ptr CTimeVal
hsc_ptr -> Ptr CTimeVal -> Int -> IO CInt
forall b. Ptr b -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr CTimeVal
hsc_ptr Int
0)) Ptr CTimeVal
p_tm :: IO CInt
{-# LINE 489 "System/Time.hsc" #-}
minute <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) p_tm :: IO CInt
{-# LINE 490 "System/Time.hsc" #-}
hour <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p_tm :: IO CInt
{-# LINE 491 "System/Time.hsc" #-}
mday <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) p_tm :: IO CInt
{-# LINE 492 "System/Time.hsc" #-}
mon <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p_tm :: IO CInt
{-# LINE 493 "System/Time.hsc" #-}
year <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) p_tm :: IO CInt
{-# LINE 494 "System/Time.hsc" #-}
wday <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) p_tm :: IO CInt
{-# LINE 495 "System/Time.hsc" #-}
yday <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) p_tm :: IO CInt
{-# LINE 496 "System/Time.hsc" #-}
isdst <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) p_tm :: IO CInt
{-# LINE 497 "System/Time.hsc" #-}
zone' <- zone p_tm
CLong
tz <- Ptr CTimeVal -> IO CLong
gmtoff Ptr CTimeVal
p_tm
String
tzname' <- Ptr CChar -> IO String
peekCString Ptr CChar
zone'
let month :: Month
month | CInt
mon CInt -> CInt -> Bool
forall a. Ord a => a -> a -> Bool
>= CInt
0 Bool -> Bool -> Bool
&& CInt
mon CInt -> CInt -> Bool
forall a. Ord a => a -> a -> Bool
<= CInt
11 = Int -> Month
forall a. Enum a => Int -> a
toEnum (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
mon)
| Bool
otherwise = String -> Month
forall a. HasCallStack => String -> a
error (String
"toCalendarTime: illegal month value: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ CInt -> String
forall a. Show a => a -> String
show CInt
mon)
CalendarTime -> IO CalendarTime
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
-> Month
-> Int
-> Int
-> Int
-> Int
-> Integer
-> Day
-> Int
-> String
-> Int
-> Bool
-> CalendarTime
CalendarTime
(Int
1900 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
year)
Month
month
(CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
mday)
(CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
hour)
(CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
minute)
(CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
sec)
Integer
psec
(Int -> Day
forall a. Enum a => Int -> a
toEnum (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
wday))
(CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
yday)
(if Bool
is_utc then String
"UTC" else String
tzname')
(if Bool
is_utc then Int
0 else CLong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
tz)
(if Bool
is_utc then Bool
False else CInt
isdst CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0))
{-# LINE 519 "System/Time.hsc" #-}
toClockTime :: CalendarTime -> ClockTime
{-# LINE 532 "System/Time.hsc" #-}
toClockTime :: CalendarTime -> ClockTime
toClockTime (CalendarTime Int
year Month
mon Int
mday Int
hour Int
minute Int
sec Integer
psec
Day
_wday Int
_yday String
_tzname Int
tz Bool
_isdst) =
let isDst :: CInt
isDst = -CInt
1 :: CInt in
if Integer
psec Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0 Bool -> Bool -> Bool
|| Integer
psec Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
999999999999 then
String -> ClockTime
forall a. HasCallStack => String -> a
error String
"Time.toClockTime: picoseconds out of range"
else if Int
tz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< -Int
43200 Bool -> Bool -> Bool
|| Int
tz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
50400 then
String -> ClockTime
forall a. HasCallStack => String -> a
error String
"Time.toClockTime: timezone offset out of range"
else
IO ClockTime -> ClockTime
forall a. IO a -> a
unsafePerformIO (IO ClockTime -> ClockTime) -> IO ClockTime -> ClockTime
forall a b. (a -> b) -> a -> b
$ do
Int -> (Ptr CTimeVal -> IO ClockTime) -> IO ClockTime
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes (Int
56) ((Ptr CTimeVal -> IO ClockTime) -> IO ClockTime)
-> (Ptr CTimeVal -> IO ClockTime) -> IO ClockTime
forall a b. (a -> b) -> a -> b
$ \ Ptr CTimeVal
p_tm -> do
{-# LINE 549 "System/Time.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p_tm (fromIntegral sec :: CInt)
{-# LINE 550 "System/Time.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) p_tm (fromIntegral minute :: CInt)
{-# LINE 551 "System/Time.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p_tm (fromIntegral hour :: CInt)
{-# LINE 552 "System/Time.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) p_tm (fromIntegral mday :: CInt)
{-# LINE 553 "System/Time.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) p_tm (fromIntegral (fromEnum mon) :: CInt)
{-# LINE 554 "System/Time.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) p_tm (fromIntegral year - 1900 :: CInt)
{-# LINE 555 "System/Time.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) p_tm isDst
{-# LINE 556 "System/Time.hsc" #-}
t <- throwIf (== -1) (\_ -> "Time.toClockTime: invalid input")
(mktime p_tm)
gmtoffset <- gmtoff p_tm
let res = realToInteger t - fromIntegral tz + fromIntegral gmtoffset
return (TOD res psec)
{-# LINE 574 "System/Time.hsc" #-}
calendarTimeToString :: CalendarTime -> String
calendarTimeToString :: CalendarTime -> String
calendarTimeToString = TimeLocale -> String -> CalendarTime -> String
formatCalendarTime TimeLocale
defaultTimeLocale String
"%c"
formatCalendarTime :: TimeLocale -> String -> CalendarTime -> String
formatCalendarTime :: TimeLocale -> String -> CalendarTime -> String
formatCalendarTime TimeLocale
l String
fmt cal :: CalendarTime
cal@(CalendarTime Int
year Month
mon Int
day Int
hour Int
minute Int
sec Integer
_
Day
wday Int
yday String
tzname' Int
_ Bool
_) =
ShowS
doFmt String
fmt
where doFmt :: ShowS
doFmt (Char
'%':Char
'-':String
cs) = ShowS
doFmt (Char
'%'Char -> ShowS
forall a. a -> [a] -> [a]
:String
cs)
doFmt (Char
'%':Char
'_':String
cs) = ShowS
doFmt (Char
'%'Char -> ShowS
forall a. a -> [a] -> [a]
:String
cs)
doFmt (Char
'%':Char
c:String
cs) = Char -> String
decode Char
c String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
doFmt String
cs
doFmt (Char
c:String
cs) = Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: ShowS
doFmt String
cs
doFmt String
"" = String
""
decode :: Char -> String
decode Char
'A' = (String, String) -> String
forall a b. (a, b) -> a
fst (TimeLocale -> [(String, String)]
wDays TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday)
decode Char
'a' = (String, String) -> String
forall a b. (a, b) -> b
snd (TimeLocale -> [(String, String)]
wDays TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday)
decode Char
'B' = (String, String) -> String
forall a b. (a, b) -> a
fst (TimeLocale -> [(String, String)]
months TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Month -> Int
forall a. Enum a => a -> Int
fromEnum Month
mon)
decode Char
'b' = (String, String) -> String
forall a b. (a, b) -> b
snd (TimeLocale -> [(String, String)]
months TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Month -> Int
forall a. Enum a => a -> Int
fromEnum Month
mon)
decode Char
'h' = (String, String) -> String
forall a b. (a, b) -> b
snd (TimeLocale -> [(String, String)]
months TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Month -> Int
forall a. Enum a => a -> Int
fromEnum Month
mon)
decode Char
'C' = Int -> String
show2 (Int
year Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
100)
decode Char
'c' = ShowS
doFmt (TimeLocale -> String
dateTimeFmt TimeLocale
l)
decode Char
'D' = ShowS
doFmt String
"%m/%d/%y"
decode Char
'd' = Int -> String
show2 Int
day
decode Char
'e' = Int -> String
show2' Int
day
decode Char
'H' = Int -> String
show2 Int
hour
decode Char
'I' = Int -> String
show2 (Int -> Int
to12 Int
hour)
decode Char
'j' = Int -> String
show3 (Int
yday Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
decode Char
'k' = Int -> String
show2' Int
hour
decode Char
'l' = Int -> String
show2' (Int -> Int
to12 Int
hour)
decode Char
'M' = Int -> String
show2 Int
minute
decode Char
'm' = Int -> String
show2 (Month -> Int
forall a. Enum a => a -> Int
fromEnum Month
monInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
decode Char
'n' = String
"\n"
decode Char
'p' = (if Int
hour Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
12 then (String, String) -> String
forall a b. (a, b) -> a
fst else (String, String) -> String
forall a b. (a, b) -> b
snd) (TimeLocale -> (String, String)
amPm TimeLocale
l)
decode Char
'R' = ShowS
doFmt String
"%H:%M"
decode Char
'r' = ShowS
doFmt (TimeLocale -> String
time12Fmt TimeLocale
l)
decode Char
'T' = ShowS
doFmt String
"%H:%M:%S"
decode Char
't' = String
"\t"
decode Char
'S' = Int -> String
show2 Int
sec
decode Char
's' = let TOD Integer
esecs Integer
_ = CalendarTime -> ClockTime
toClockTime CalendarTime
cal in Integer -> String
forall a. Show a => a -> String
show Integer
esecs
decode Char
'U' = Int -> String
show2 ((Int
yday Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
7)
decode Char
'u' = Int -> String
forall a. Show a => a -> String
show (let n :: Int
n = Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday in
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
7 else Int
n)
decode Char
'V' =
let (Int
week, Int
days) =
(Int
yday Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
- if Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 then
Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 else Int
6) Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`divMod` Int
7
in Int -> String
show2 (if Int
days Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
4 then
Int
weekInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1
else if Int
week Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
53 else Int
week)
decode Char
'W' =
Int -> String
show2 ((Int
yday Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
- if Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 then
Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 else Int
6) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
7)
decode Char
'w' = Int -> String
forall a. Show a => a -> String
show (Day -> Int
forall a. Enum a => a -> Int
fromEnum Day
wday)
decode Char
'X' = ShowS
doFmt (TimeLocale -> String
timeFmt TimeLocale
l)
decode Char
'x' = ShowS
doFmt (TimeLocale -> String
dateFmt TimeLocale
l)
decode Char
'Y' = Int -> String
forall a. Show a => a -> String
show Int
year
decode Char
'y' = Int -> String
show2 (Int
year Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
100)
decode Char
'Z' = String
tzname'
decode Char
'%' = String
"%"
decode Char
c = [Char
c]
show2, show2', show3 :: Int -> String
show2 :: Int -> String
show2 Int
x
| Int
x' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
10 = Char
'0'Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> String
forall a. Show a => a -> String
show Int
x'
| Bool
otherwise = Int -> String
forall a. Show a => a -> String
show Int
x'
where x' :: Int
x' = Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
100
show2' :: Int -> String
show2' Int
x
| Int
x' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
10 = Char
' 'Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> String
forall a. Show a => a -> String
show Int
x'
| Bool
otherwise = Int -> String
forall a. Show a => a -> String
show Int
x'
where x' :: Int
x' = Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
100
show3 :: Int -> String
show3 Int
x = Int -> String
forall a. Show a => a -> String
show (Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
100) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
show2 (Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
100)
to12 :: Int -> Int
to12 :: Int -> Int
to12 Int
h = let h' :: Int
h' = Int
h Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
12 in if Int
h' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
12 else Int
h'
timeDiffToString :: TimeDiff -> String
timeDiffToString :: TimeDiff -> String
timeDiffToString = TimeLocale -> String -> TimeDiff -> String
formatTimeDiff TimeLocale
defaultTimeLocale String
"%c"
formatTimeDiff :: TimeLocale -> String -> TimeDiff -> String
formatTimeDiff :: TimeLocale -> String -> TimeDiff -> String
formatTimeDiff TimeLocale
l String
fmt (TimeDiff Int
year Int
month Int
day Int
hour Int
minute Int
sec Integer
_)
= ShowS
doFmt String
fmt
where
doFmt :: ShowS
doFmt String
"" = String
""
doFmt (Char
'%':Char
'-':String
cs) = ShowS
doFmt (Char
'%'Char -> ShowS
forall a. a -> [a] -> [a]
:String
cs)
doFmt (Char
'%':Char
'_':String
cs) = ShowS
doFmt (Char
'%'Char -> ShowS
forall a. a -> [a] -> [a]
:String
cs)
doFmt (Char
'%':Char
c:String
cs) = Char -> String
decode Char
c String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
doFmt String
cs
doFmt (Char
c:String
cs) = Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: ShowS
doFmt String
cs
decode :: Char -> String
decode Char
spec =
case Char
spec of
Char
'B' -> (String, String) -> String
forall a b. (a, b) -> a
fst (TimeLocale -> [(String, String)]
months TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Int -> Int
forall a. Enum a => a -> Int
fromEnum Int
month)
Char
'b' -> (String, String) -> String
forall a b. (a, b) -> b
snd (TimeLocale -> [(String, String)]
months TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Int -> Int
forall a. Enum a => a -> Int
fromEnum Int
month)
Char
'h' -> (String, String) -> String
forall a b. (a, b) -> b
snd (TimeLocale -> [(String, String)]
months TimeLocale
l [(String, String)] -> Int -> (String, String)
forall a. HasCallStack => [a] -> Int -> a
!! Int -> Int
forall a. Enum a => a -> Int
fromEnum Int
month)
Char
'c' -> String
defaultTimeDiffFmt
Char
'C' -> Int -> String
show2 (Int
year Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
100)
Char
'D' -> ShowS
doFmt String
"%m/%d/%y"
Char
'd' -> Int -> String
show2 Int
day
Char
'e' -> Int -> String
show2' Int
day
Char
'H' -> Int -> String
show2 Int
hour
Char
'I' -> Int -> String
show2 (Int -> Int
to12 Int
hour)
Char
'k' -> Int -> String
show2' Int
hour
Char
'l' -> Int -> String
show2' (Int -> Int
to12 Int
hour)
Char
'M' -> Int -> String
show2 Int
minute
Char
'm' -> Int -> String
show2 (Int -> Int
forall a. Enum a => a -> Int
fromEnum Int
month Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Char
'n' -> String
"\n"
Char
'p' -> (if Int
hour Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
12 then (String, String) -> String
forall a b. (a, b) -> a
fst else (String, String) -> String
forall a b. (a, b) -> b
snd) (TimeLocale -> (String, String)
amPm TimeLocale
l)
Char
'R' -> ShowS
doFmt String
"%H:%M"
Char
'r' -> ShowS
doFmt (TimeLocale -> String
time12Fmt TimeLocale
l)
Char
'T' -> ShowS
doFmt String
"%H:%M:%S"
Char
't' -> String
"\t"
Char
'S' -> Int -> String
show2 Int
sec
Char
's' -> Int -> String
show2 Int
sec
Char
'X' -> ShowS
doFmt (TimeLocale -> String
timeFmt TimeLocale
l)
Char
'x' -> ShowS
doFmt (TimeLocale -> String
dateFmt TimeLocale
l)
Char
'Y' -> Int -> String
forall a. Show a => a -> String
show Int
year
Char
'y' -> Int -> String
show2 (Int
year Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
100)
Char
'%' -> String
"%"
Char
c -> [Char
c]
defaultTimeDiffFmt :: String
defaultTimeDiffFmt =
((Int, (String, String)) -> ShowS)
-> String -> [(Int, (String, String))] -> String
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\ (Int
v,(String, String)
s) String
rest ->
(if Int
v Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0
then Int -> String
forall a. Show a => a -> String
show Int
v String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char
' 'Char -> ShowS
forall a. a -> [a] -> [a]
:(Int -> (String, String) -> String
forall {a} {a}. (Eq a, Num a) => a -> (a, a) -> a
addS Int
v (String, String)
s)
String -> ShowS
forall a. [a] -> [a] -> [a]
++ if String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
rest then String
"" else String
", "
else String
"") String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
rest
)
String
""
([Int] -> [(String, String)] -> [(Int, (String, String))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
year, Int
month, Int
day, Int
hour, Int
minute, Int
sec] (TimeLocale -> [(String, String)]
intervals TimeLocale
l))
addS :: a -> (a, a) -> a
addS a
v (a, a)
s = if a -> a
forall a. Num a => a -> a
abs a
v a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 then (a, a) -> a
forall a b. (a, b) -> a
fst (a, a)
s else (a, a) -> a
forall a b. (a, b) -> b
snd (a, a)
s
{-# LINE 728 "System/Time.hsc" #-}
type CTm = ()
{-# LINE 734 "System/Time.hsc" #-}
foreign import ccall unsafe "HsTime.h __hscore_localtime_r"
localtime_r :: Ptr CTime -> Ptr CTm -> IO (Ptr CTm)
{-# LINE 740 "System/Time.hsc" #-}
{-# LINE 741 "System/Time.hsc" #-}
foreign import ccall unsafe "HsTime.h __hscore_gmtime_r"
gmtime_r :: Ptr CTime -> Ptr CTm -> IO (Ptr CTm)
{-# LINE 747 "System/Time.hsc" #-}
foreign import ccall unsafe "time.h mktime"
mktime :: Ptr CTm -> IO CTime
{-# LINE 751 "System/Time.hsc" #-}
type CTimeVal = ()
type CTimeZone = ()
foreign import ccall unsafe "HsTime.h __hscore_gettimeofday"
gettimeofday :: Ptr CTimeVal -> Ptr CTimeZone -> IO CInt
{-# LINE 765 "System/Time.hsc" #-}
{-# LINE 766 "System/Time.hsc" #-}