Ticket #1486 (closed bug: fixed)

Opened 6 years ago

Last modified 6 years ago

utcToLocalTime converting in the wrong direction on Windows

Reported by: Olivier Boudry Owned by:
Priority: normal Milestone: Not GHC
Component: libraries (other) Version: 6.6.1
Keywords: Cc: ashley@…
Operating System: Windows Architecture: x86
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

I found a strange UTC to Local Time conversion bug on the Windows version of GHC 6.6.1.

Code to reproduce it:

    import Monad
    import Data.Time
    import Locale

    main = do
        t <- (liftM2 utcToLocalTime) getCurrentTimeZone getCurrentTime
        let s = formatTime defaultTimeLocale "%r" t
        putStrLn s
        z <- (liftM timeZoneName) getCurrentTimeZone
        putStrLn z

Running this program around 04:35 PM I get the following results

On Linux (a recent Ubuntu with GHC 6.6.1 compiled from source)

04:35:48 PM
EDT

On Windows (GHC 6.6.1 from installer) I get

12:36:04 AM
Eastern Daylight Time

Looks like the Windows version is counting in the wrong direction. I made some tests in GHCi on both machines an get this:

On Windows:

Prelude> :m Monad Data.Time Locale
Prelude Locale Data.Time Monad> z <- getCurrentTimeZone
Eastern Daylight Time
Prelude Locale Data.Time Monad> timeZoneMinutes z
240

On Linux: (same commands)

Prelude Locale Data.Time Monad> timeZoneMinutes z
-240

Cheers,

Olivier.

Attachments

HsTime.c Download (1.0 KB) - added by Olivier Boudry 6 years ago.
Modified HsTime?.c

Change History

Changed 6 years ago by igloo

  • description modified (diff)

Changed 6 years ago by igloo

  • cc ashley@… added
  • milestone set to Not GHC

I can reproduce this, but it's not imediately obvious to me what's wrong with the code.

Also, in cygwin, I by default have

$ echo $TZ
GMTST0GMTST-1,M3.5.0/1,M10.5.0/2

and ghci says

Prelude Data.Time> getCurrentTimeZone
ST0

If I set TZ to abcdefghijkl then it says def

Changed 6 years ago by Olivier Boudry

I think the problem is that:

tm_gmtoff is secs EAST of UTC _timezone is secs WEST of UTC.

The have reverse meaning so to get it working properly you should negate the Win32 result.

return - (dst ? _timezone - 3600 : _timezone);

I played with timezones on both Unix and Win32 and the timezone offset in minutes was always the reverse on Win32 (240/-240, 120/-120), etc...

I didn't managed to build just the time library on my PC. Tried with MinGW but it didn't worked so I couldn't test the proposed fix.

Cheers,

Olivier.

Changed 6 years ago by Olivier Boudry

Modified HsTime?.c

Changed 6 years ago by Olivier Boudry

I finally managed to compile the time module with GHC-6.6.1. I modified it (line 25 of attached HsTime?.c file) as proposed in the previous comment.

I tested it changing my timezone for a set of negatives and positives time zones and always got the same time as displayed by Windows' clock. The fix seems to work and the bug was due to Win32 counting reverse as other OS.

Cheers,

Olivier.

Changed 6 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

Patch applied, thanks!

Note: See TracTickets for help on using tickets.