-- Stability : provisional
-- Portability : portable
--
--- $Id: Time.hsc,v 1.12 2002/04/24 16:31:45 simonmar Exp $
---
-- The standard Time library.
--
-----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- getClockTime returns the current time in its internal representation.
+getClockTime :: IO ClockTime
#if HAVE_GETTIMEOFDAY
getClockTime = do
allocaBytes (#const sizeof(struct timeval)) $ \ p_timeval -> do
# endif
# ifndef mingw32_TARGET_OS
foreign import ccall unsafe "&tzname" tzname :: Ptr (Ptr CChar)
-foreign import ccall unsafe "timezone" timezone :: Ptr CLong
# else
foreign import ccall unsafe "__hscore_timezone" timezone :: Ptr CLong
foreign import ccall unsafe "__hscore_tzname" tzname :: Ptr (Ptr CChar)
# endif /* ! HAVE_TZNAME */
-- Get the offset in secs from UTC, if (struct tm) doesn't supply it. */
-#if defined(mingw32_TARGET_OS)
-#define timezone _timezone
-#endif
-
# if HAVE_ALTZONE
-foreign import ccall "&altzone" :: Ptr CTime
-foreign import ccall "&timezone" :: Ptr CTime
+foreign import ccall "&altzone" altzone :: Ptr CTime
+foreign import ccall "&timezone" timezone :: Ptr CTime
gmtoff x = do
dst <- (#peek struct tm,tm_isdst) x
tz <- if dst then peek altzone else peek timezone
return (fromIntegral tz)
# define GMTOFF(x) (((struct tm *)x)->tm_isdst ? altzone : timezone )
# else /* ! HAVE_ALTZONE */
+
+#if !defined(mingw32_TARGET_OS)
+foreign import ccall unsafe "timezone" timezone :: Ptr CLong
+#endif
+
-- Assume that DST offset is 1 hour ...
gmtoff x = do
dst <- (#peek struct tm,tm_isdst) x
tz <- peek timezone
+#if defined(mingw32_TARGET_OS)
+ -- According to the MSVC documentation for _tzset, _timezone is > 0
+ -- for locations west of the Prime Meridian. Code elsewhere in this
+ -- module assume that >0 gmt offsets means east, so flip the sign.
+ tz <- return (-tz)
+#endif
if dst then return (fromIntegral tz - 3600) else return tz
# endif /* ! HAVE_ALTZONE */
#endif /* ! HAVE_TM_ZONE */