Skip to content

UTCTime serialization not idempotent

decode . encode is not idempotent for UTCTime:

import Data.Time
import Data.Binary

test = do
  t <- getCurrentTime
  putStrLn $ "time: " ++ show t
  let b = encode t
      t' = decode b :: UTCTime
  putStrLn $ "  t': " ++ show t'

Running this code yields:

time: 2011-05-06 18:50:40.972389 UTC
  t': 2011-05-06 00:00:00.001148625728 UTC
Trac metadata
Trac field Value
Version 7.0.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries (other)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information