Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible regression in time 1.8.0.1 / ghc 8.2 rc2 when converting UTCTime to a string #74

Closed
DougBurke opened this issue May 12, 2017 · 6 comments

Comments

@DougBurke
Copy link

In testing out one of my packages with ghc 8.2 rc2, I found a failing test which I've boiled down to the following: is this a bug in time, or in ghc, or allowed behavior?

The problem is that I am trying to round-trip the string '1970-01-01T00:00:00Z' to UTCTime and then back to a string, and with time 1.8.0.1 this returns '1970-01-01T00:00:00.Z' - note the decimal point.

Details below:

% cat prob.hs
module Main where

import Data.Time
import Data.Maybe

fmt :: String
fmt = "%FT%T%QZ"

torig :: String
torig = "1970-01-01T00:00:00Z"

tconv :: UTCTime
tconv = fromJust (parseTimeM True defaultTimeLocale fmt torig)

tnew :: String
tnew = formatTime defaultTimeLocale fmt tconv

main :: IO ()
main = do
  putStrLn ("Original:  " ++ torig)
  putStrLn ("Converted: " ++ tnew)

I see the following on a ubuntu laptop

a) ghc 8.0.2, time 1.6.0.1

% ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.2
% ghc-pkg list time
/usr/lib/ghc/package.conf.d
    time-1.6.0.1
/home/djburke/.ghc/x86_64-linux-8.0.2/package.conf.d
    (no packages)
% runghc prob.hs
Original:  1970-01-01T00:00:00Z
Converted: 1970-01-01T00:00:00Z

b) ghc 8.2 rc2, time 1.8.0.1

% ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.2.0.20170507
% ghc-pkg list time
/home/djburke/local/ghc-8.2.0.20170507/lib/ghc-8.2.0.20170507/package.conf.d
    time-1.8.0.1
% runghc prob.hs
Original:  1970-01-01T00:00:00Z
Converted: 1970-01-01T00:00:00.Z
@bgamari
Copy link
Contributor

bgamari commented May 12, 2017

It looks like this regressed with 85904c5.

@DougBurke
Copy link
Author

Ta for digging that up - my reading of the commit - particularly the test formatUnitTest "%Q" 0 "." - is that this is an intentional change in the behavior of %Q, but there's enough moving parts here (and I have little enough spare brain power) that I'll leave it to @AshleyYakeley to determine what the best thing to do here.

@AshleyYakeley
Copy link
Member

Yes, this is a bug. The documentation for %Q says "For a whole number of seconds, %Q produces the empty string." To always get a decimal point (the current wrong behaviour of %Q), one should use ".%-q".

@AshleyYakeley
Copy link
Member

Fixed in c29513e.

@AshleyYakeley
Copy link
Member

I will do a point release for this.

@DougBurke
Copy link
Author

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants