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.
This commit is contained in:
Timofey Solomko
2018-03-25 23:42:53 +03:00
parent 019bbf0629
commit 112fa8bbb0
2 changed files with 9 additions and 13 deletions
+3 -7
View File
@@ -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)
}
}
+6 -6
View File
@@ -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
}