Commit eb2261ce authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Move lib/Time tests into the old-time package

parent c8755c9a
TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
import System.Locale
import System.Time
main :: IO ()
main = do let clockTime = TOD 32400 0 -- 00:00:00 on 1 Jan 1970
calTime <- toCalendarTime clockTime
-- We check for 001 or 365 (timezone locale will determine which one)
-- and output 001 for testing output consistently.
putStrLn $ case (formatCalendarTime defaultTimeLocale "%j" calTime) of
"001" -> "001" -- good!
"365" -> "001" -- good!
n -> n -- error!
test('time002', normal, compile_and_run, [''])
test('time003', normal, compile_and_run, [''])
test('time004', normal, compile_and_run, [''])
test('T5430', normal, compile_and_run, [''])
import System.Time
-- !!! check that we can read the current ClockTime, convert it
-- !!! to CalendarTime and back again, and that all three times when
-- !!! converted to strings compare equal.
main = do
t <- getClockTime
let clock = show t
c <- toCalendarTime t
let cal = calendarTimeToString c
let t2 = toClockTime c
clock2 = show t2
if (clock == cal && clock == clock2)
then putStrLn "Ok."
else putStrLn "Failed."
import System.Time
main :: IO ()
main = do
time <- getClockTime
print (plausible (show time))
let (CalendarTime year month mday hour min sec psec
wday yday timezone gmtoff isdst) = toUTCTime time
time2 = wdays !! fromEnum wday ++
(' ' : months !! fromEnum month) ++
(' ' : shows2 mday (' ' : shows2 hour (':' : shows2 min (':' : shows2 sec
(' ' : timezone ++ ' ' : shows year "\n")))))
print (plausible time2)
where
wdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
shows2 x = showString (pad2 x)
pad2 x = case show x of
c@[_] -> '0' : c
cs -> cs
plausible str = filter (== ':') str == "::"
\ No newline at end of file
import System.Time
main :: IO ()
main = do
time <- getClockTime
let (CalendarTime year month mday hour min sec psec
wday yday timezone gmtoff isdst) = toUTCTime time
time' = toClockTime (CalendarTime (year - 1) month mday hour min sec psec
wday yday timezone gmtoff isdst)
print (length (show time) == length (show time'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment