#ifdef __NHC__
#include <time.h>
-# ifdef __sun
+# if defined(__sun) || defined(__CYGWIN32__)
# define HAVE_TZNAME 1
# else
# define HAVE_TM_ZONE 1
60 * toInteger min +
3600 * toInteger hour +
24 * 3600 * toInteger day
- cal = toUTCTime (TOD (c_sec + sec_diff) (c_psec + psec))
- -- FIXME! ^^^^
+ (d_sec, d_psec) = (c_psec + psec) `quotRem` 1000000000000
+ cal = toUTCTime (TOD (c_sec + sec_diff + d_sec) d_psec)
new_mon = fromEnum (ctMonth cal) + r_mon
month' = fst tmp
yr_diff = snd tmp
-- errors
normalizeTimeDiff td =
let
- rest0 = tdSec td
- + 60 * (tdMin td
- + 60 * (tdHour td
- + 24 * (tdDay td
- + 30 * (tdMonth td
- + 365 * tdYear td))))
+ rest0 = toInteger (tdSec td)
+ + 60 * (toInteger (tdMin td)
+ + 60 * (toInteger (tdHour td)
+ + 24 * (toInteger (tdDay td)
+ + 30 * toInteger (tdMonth td)
+ + 365 * toInteger (tdYear td))))
(diffYears, rest1) = rest0 `quotRem` (365 * 24 * 3600)
(diffMonths, rest2) = rest1 `quotRem` (30 * 24 * 3600)
(diffHours, rest4) = rest3 `quotRem` 3600
(diffMins, diffSecs) = rest4 `quotRem` 60
in
- td{ tdYear = diffYears
- , tdMonth = diffMonths
- , tdDay = diffDays
- , tdHour = diffHours
- , tdMin = diffMins
- , tdSec = diffSecs
+ td{ tdYear = fromInteger diffYears
+ , tdMonth = fromInteger diffMonths
+ , tdDay = fromInteger diffDays
+ , tdHour = fromInteger diffHours
+ , tdMin = fromInteger diffMins
+ , tdSec = fromInteger diffSecs
}
#ifndef __HUGS__
#else /* ! HAVE_TM_ZONE */
# if HAVE_TZNAME || defined(_WIN32)
-# if cygwin32_TARGET_OS
+# if cygwin32_HOST_OS
# define tzname _tzname
# endif
-# ifndef mingw32_TARGET_OS
+# ifndef mingw32_HOST_OS
foreign import ccall unsafe "time.h &tzname" tzname :: Ptr (Ptr CChar)
# else
foreign import ccall unsafe "__hscore_timezone" timezone :: Ptr CLong
return (-fromIntegral (realToInteger tz))
# else /* ! HAVE_DECL_ALTZONE */
-#if !defined(mingw32_TARGET_OS)
+#if !defined(mingw32_HOST_OS)
foreign import ccall "time.h &timezone" timezone :: Ptr CLong
#endif
-> (Ptr CTime -> Ptr CTm -> IO ( ))
throwAwayReturnPointer fun x y = fun x y >> return ()
+#if !HAVE_LOCALTIME_R || !HAVE_GMTIME_R
clockToCalendarTime_static :: (Ptr CTime -> IO (Ptr CTm)) -> Bool -> ClockTime
-> IO CalendarTime
clockToCalendarTime_static fun is_utc (TOD secs psec) = do
with (fromIntegral secs :: CTime) $ \ p_timer -> do
p_tm <- fun p_timer -- can't fail, according to POSIX
clockToCalendarTime_aux is_utc p_tm psec
+#endif
+#if HAVE_LOCALTIME_R || HAVE_GMTIME_R
clockToCalendarTime_reentrant :: (Ptr CTime -> Ptr CTm -> IO ()) -> Bool -> ClockTime
-> IO CalendarTime
clockToCalendarTime_reentrant fun is_utc (TOD secs psec) = do
allocaBytes (#const sizeof(struct tm)) $ \ p_tm -> do
fun p_timer p_tm
clockToCalendarTime_aux is_utc p_tm psec
+#endif
clockToCalendarTime_aux :: Bool -> Ptr CTm -> Integer -> IO CalendarTime
clockToCalendarTime_aux is_utc p_tm psec = do
where x' = x `rem` 100
show3 x = show (x `quot` 100) ++ show2 (x `rem` 100)
- where x' = x `rem` 1000
to12 :: Int -> Int
to12 h = let h' = h `mod` 12 in if h' == 0 then 12 else h'
#endif
foreign import ccall unsafe "time.h mktime"
mktime :: Ptr CTm -> IO CTime
-foreign import ccall unsafe "time.h time"
- time :: Ptr CTime -> IO CTime
#if HAVE_GETTIMEOFDAY
type CTimeVal = ()
foreign import ccall unsafe "time.h gettimeofday"
gettimeofday :: Ptr CTimeVal -> Ptr () -> IO CInt
-#endif
-
-#if HAVE_FTIME
+#elif HAVE_FTIME
type CTimeB = ()
-#ifndef mingw32_TARGET_OS
+#ifndef mingw32_HOST_OS
foreign import ccall unsafe "time.h ftime" ftime :: Ptr CTimeB -> IO CInt
#else
foreign import ccall unsafe "time.h ftime" ftime :: Ptr CTimeB -> IO ()
#endif
+#else
+foreign import ccall unsafe "time.h time" time :: Ptr CTime -> IO CTime
#endif
#endif /* ! __HUGS__ */