From efe4423a9a2b1dc2a4d413917a933828d3f8dc0f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 5 Apr 2024 09:43:57 -0700 Subject: [PATCH] readEntry: fix computation of modification time. It should be a UNIX time (seconds since UNIX epoch), but computed relative to the *local* time zone, not UTC. Closes #67. --- src/Codec/Archive/Zip.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Codec/Archive/Zip.hs b/src/Codec/Archive/Zip.hs index 06ccfe7..a7cc529 100644 --- a/src/Codec/Archive/Zip.hs +++ b/src/Codec/Archive/Zip.hs @@ -72,8 +72,9 @@ module Codec.Archive.Zip import Data.Time.Calendar ( toGregorian, fromGregorian ) import Data.Time.Clock ( UTCTime(..) ) +import Data.Time.LocalTime ( TimeZone(..), TimeOfDay(..), timeToTimeOfDay, + getTimeZone ) import Data.Time.Clock.POSIX ( posixSecondsToUTCTime, utcTimeToPOSIXSeconds ) -import Data.Time.LocalTime ( TimeOfDay(..), timeToTimeOfDay ) import Data.Bits ( shiftL, shiftR, (.&.), (.|.), xor, testBit ) import Data.Binary import Data.Binary.Get @@ -85,7 +86,7 @@ import Text.Printf import System.FilePath import System.Directory (doesDirectoryExist, getDirectoryContents, - createDirectoryIfMissing, getModificationTime) + createDirectoryIfMissing, getModificationTime,) import Control.Monad ( when, unless, zipWithM_ ) import qualified Control.Exception as E import System.IO ( stderr, hPutStrLn ) @@ -315,7 +316,11 @@ readEntry opts path = do return B.empty else B.fromStrict <$> S.readFile path - modEpochTime <- (floor . utcTimeToPOSIXSeconds) <$> getModificationTime path + modTime <- getModificationTime path + tzone <- getTimeZone modTime + let modEpochTime = -- UNIX time computed relative to LOCAL time zone! (#67) + floor (utcTimeToPOSIXSeconds modTime) + + fromIntegral (timeZoneMinutes tzone * 60) let entry = toEntry path' modEpochTime contents entryE <-