Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/CurrentTime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Data.Time

main :: IO ()
main = do
now <- getCurrentTime
putStrLn (show (utctDay now) ++ "," ++ show (utctDayTime now))
putStrLn (show (utcToZonedTime utc now :: ZonedTime))
myzone <- getCurrentTimeZone
putStrLn (show (utcToZonedTime myzone now :: ZonedTime))
now <- getCurrentTime
putStrLn (show (utctDay now) ++ "," ++ show (utctDayTime now))
putStrLn (show (utcToZonedTime utc now :: ZonedTime))
myzone <- getCurrentTimeZone
putStrLn (show (utcToZonedTime myzone now :: ZonedTime))
20 changes: 10 additions & 10 deletions test/RealToFracBenchmark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Prelude

main :: IO ()
main = do
ts <-
replicateM 100000 $ do
t <-
posixSecondsToUTCTime . realToFrac
<$> ((*) . fromInteger <$> randomRIO (-15 * 10 ^ 21, 15 * 10 ^ 21) <*> randomIO :: IO Double) ::
IO UTCTime
rnf t `seq` return t
now <- getCurrentTime
print . sum $ map (diffUTCTime now) ts
print =<< flip diffUTCTime now <$> getCurrentTime
ts <-
replicateM 100000 $ do
t <-
posixSecondsToUTCTime . realToFrac
<$> ((*) . fromInteger <$> randomRIO (-15 * 10 ^ 21, 15 * 10 ^ 21) <*> randomIO :: IO Double) ::
IO UTCTime
rnf t `seq` return t
now <- getCurrentTime
print . sum $ map (diffUTCTime now) ts
print =<< flip diffUTCTime now <$> getCurrentTime
57 changes: 25 additions & 32 deletions test/ShowDST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ monthBeginning zone year month = localTimeToUTC zone (LocalTime (fromGregorian y

findTransition :: UTCTime -> UTCTime -> IO [(UTCTime, TimeZone, TimeZone)]
findTransition a b = do
za <- getTimeZone a
zb <- getTimeZone b
if za == zb
then return []
za <- getTimeZone a
zb <- getTimeZone b
if za == zb
then return []
else do
let c = addUTCTime ((diffUTCTime b a) / 2) a
if a == c
then return [(b, za, zb)]
else do
let
c = addUTCTime ((diffUTCTime b a) / 2) a
if a == c
then return [(b, za, zb)]
else do
tp <- findTransition a c
tq <- findTransition c b
return (tp ++ tq)
tp <- findTransition a c
tq <- findTransition c b
return (tp ++ tq)

showZoneTime :: TimeZone -> UTCTime -> String
showZoneTime zone time = show (utcToZonedTime zone time)
Expand All @@ -29,23 +28,17 @@ showTransition (time, zone1, zone2) = (showZoneTime zone1 time) ++ " => " ++ (sh

main :: IO ()
main = do
now <- getCurrentTime
zone <- getTimeZone now
let
(year, _, _) = toGregorian (localDay (utcToLocalTime zone now))
putStrLn ("DST adjustments for " ++ show year ++ ":")
let
t0 = monthBeginning zone year 1
let
t1 = monthBeginning zone year 4
let
t2 = monthBeginning zone year 7
let
t3 = monthBeginning zone year 10
let
t4 = monthBeginning zone (year + 1) 1
tr1 <- findTransition t0 t1
tr2 <- findTransition t1 t2
tr3 <- findTransition t2 t3
tr4 <- findTransition t3 t4
mapM_ (putStrLn . showTransition) (tr1 ++ tr2 ++ tr3 ++ tr4)
now <- getCurrentTime
zone <- getTimeZone now
let (year, _, _) = toGregorian (localDay (utcToLocalTime zone now))
putStrLn ("DST adjustments for " ++ show year ++ ":")
let t0 = monthBeginning zone year 1
let t1 = monthBeginning zone year 4
let t2 = monthBeginning zone year 7
let t3 = monthBeginning zone year 10
let t4 = monthBeginning zone (year + 1) 1
tr1 <- findTransition t0 t1
tr2 <- findTransition t1 t2
tr3 <- findTransition t2 t3
tr4 <- findTransition t3 t4
mapM_ (putStrLn . showTransition) (tr1 ++ tr2 ++ tr3 ++ tr4)
10 changes: 5 additions & 5 deletions test/ShowDefaultTZAbbreviations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import Data.Time

showTZ :: TimeZone -> String
showTZ tz =
(formatTime defaultTimeLocale "%Z %z" tz)
++ ( if timeZoneSummerOnly tz
then " DST"
else ""
)
(formatTime defaultTimeLocale "%Z %z" tz)
++ ( if timeZoneSummerOnly tz
then " DST"
else ""
)

main :: IO ()
main = mapM_ (\tz -> putStrLn (showTZ tz)) (knownTimeZones defaultTimeLocale)
4 changes: 2 additions & 2 deletions test/TimeZone.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import Data.Time

main :: IO ()
main = do
zone <- getCurrentTimeZone
putStrLn (timeZoneOffsetString zone)
zone <- getCurrentTimeZone
putStrLn (timeZoneOffsetString zone)
46 changes: 23 additions & 23 deletions test/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ import Test.Types ()

tests :: TestTree
tests =
testGroup
"Time"
[ testGroup
"Calendar"
[ addDaysTest
, testCalendarProps
, testCalendars
, clipDates
, convertBack
, longWeekYears
, testDayPeriod
, testMonthDay
, testMonthOfYear
, testEaster
, testValid
, testWeek
, testYear
, testDuration
]
, testGroup "Clock" [testClockConversion, testResolutions, testTAI, testLift]
-- , testGroup "Format" [testFormat, testParseTime, testISO8601]
, testGroup "LocalTime" [{- testTime, -} testTimeOfDay, testCalendarDiffTime]
]
testGroup
"Time"
[ testGroup
"Calendar"
[ addDaysTest,
testCalendarProps,
testCalendars,
clipDates,
convertBack,
longWeekYears,
testDayPeriod,
testMonthDay,
testMonthOfYear,
testEaster,
testValid,
testWeek,
testYear,
testDuration
],
testGroup "Clock" [testClockConversion, testResolutions, testTAI, testLift],
-- , testGroup "Format" [testFormat, testParseTime, testISO8601]
testGroup "LocalTime" [{- testTime, -} testTimeOfDay, testCalendarDiffTime]
]

main :: IO ()
main = defaultMain tests
Loading