From 112fa8bbb09f08c79fa2a31f8a66086ab53cc251 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 25 Mar 2018 23:42:53 +0300 Subject: [PATCH] Date init from ntfs timestamp is no longer failable The only reason for it to be was to propagate optionality of UInt64 argument. Instead we can if-let ntfs timestamp and call this initializer with non-optional argument. We also now force-unwrap ntfsReferenceDate, since it is likely to be a system problem if we cannot create definetely correct date from its components. --- Sources/Common/Extensions.swift | 10 +++------- Sources/ZIP/ZipEntryInfo.swift | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Sources/Common/Extensions.swift b/Sources/Common/Extensions.swift index 318a9d7e..556d36d4 100644 --- a/Sources/Common/Extensions.swift +++ b/Sources/Common/Extensions.swift @@ -50,14 +50,10 @@ extension Date { private static let ntfsReferenceDate = DateComponents(calendar: Calendar(identifier: .iso8601), timeZone: TimeZone(abbreviation: "UTC"), year: 1601, month: 1, day: 1, - hour: 0, minute: 0, second: 0).date + hour: 0, minute: 0, second: 0).date! - init?(_ ntfsTime: UInt64?) { - if let time = ntfsTime, let ntfsReferenceDate = Date.ntfsReferenceDate { - self.init(timeInterval: TimeInterval(time) / 10_000_000, since: ntfsReferenceDate) - } else { - return nil - } + init(_ ntfsTime: UInt64) { + self.init(timeInterval: TimeInterval(ntfsTime) / 10_000_000, since: .ntfsReferenceDate) } } diff --git a/Sources/ZIP/ZipEntryInfo.swift b/Sources/ZIP/ZipEntryInfo.swift index e7e86dda..ca0c13e4 100644 --- a/Sources/ZIP/ZipEntryInfo.swift +++ b/Sources/ZIP/ZipEntryInfo.swift @@ -114,9 +114,9 @@ public struct ZipEntryInfo: ContainerEntryInfo { if let mtimestamp = cdEntry.modificationTimestamp { // Extended Timestamp extra field. self.modificationTime = Date(timeIntervalSince1970: TimeInterval(mtimestamp)) - } else if let mtime = Date(cdEntry.ntfsMtime) { + } else if let mtime = cdEntry.ntfsMtime { // NTFS extra field. - self.modificationTime = mtime + self.modificationTime = Date(mtime) } else { // Native ZIP modification time. let dosDate = cdEntry.lastModFileDate.toInt() @@ -140,9 +140,9 @@ public struct ZipEntryInfo: ContainerEntryInfo { if let ctimestamp = localHeader.creationTimestamp { // Extended Timestamp extra field. self.creationTime = Date(timeIntervalSince1970: TimeInterval(ctimestamp)) - } else if let ctime = Date(cdEntry.ntfsCtime) { + } else if let ctime = cdEntry.ntfsCtime { // NTFS extra field. - self.creationTime = ctime + self.creationTime = Date(ctime) } else { self.creationTime = nil } @@ -151,9 +151,9 @@ public struct ZipEntryInfo: ContainerEntryInfo { if let atimestamp = localHeader.accessTimestamp { // Extended Timestamp extra field. self.accessTime = Date(timeIntervalSince1970: TimeInterval(atimestamp)) - } else if let atime = Date(cdEntry.ntfsAtime) { + } else if let atime = cdEntry.ntfsAtime { // NTFS extra field. - self.accessTime = atime + self.accessTime = Date(atime) } else { self.accessTime = nil }