Skip to content

Commit efe4423

Browse files
committed
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.
1 parent c4f8de6 commit efe4423

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎src/Codec/Archive/Zip.hs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ module Codec.Archive.Zip
7272

7373
import Data.Time.Calendar ( toGregorian, fromGregorian )
7474
import Data.Time.Clock ( UTCTime(..) )
75+
import Data.Time.LocalTime ( TimeZone(..), TimeOfDay(..), timeToTimeOfDay,
76+
getTimeZone )
7577
import Data.Time.Clock.POSIX ( posixSecondsToUTCTime, utcTimeToPOSIXSeconds )
76-
import Data.Time.LocalTime ( TimeOfDay(..), timeToTimeOfDay )
7778
import Data.Bits ( shiftL, shiftR, (.&.), (.|.), xor, testBit )
7879
import Data.Binary
7980
import Data.Binary.Get
@@ -85,7 +86,7 @@ import Text.Printf
8586
import System.FilePath
8687
import System.Directory
8788
(doesDirectoryExist, getDirectoryContents,
88-
createDirectoryIfMissing, getModificationTime)
89+
createDirectoryIfMissing, getModificationTime,)
8990
import Control.Monad ( when, unless, zipWithM_ )
9091
import qualified Control.Exception as E
9192
import System.IO ( stderr, hPutStrLn )
@@ -315,7 +316,11 @@ readEntry opts path = do
315316
return B.empty
316317
else
317318
B.fromStrict <$> S.readFile path
318-
modEpochTime <- (floor . utcTimeToPOSIXSeconds) <$> getModificationTime path
319+
modTime <- getModificationTime path
320+
tzone <- getTimeZone modTime
321+
let modEpochTime = -- UNIX time computed relative to LOCAL time zone! (#67)
322+
floor (utcTimeToPOSIXSeconds modTime) +
323+
fromIntegral (timeZoneMinutes tzone * 60)
319324
let entry = toEntry path' modEpochTime contents
320325

321326
entryE <-

0 commit comments

Comments
 (0)