Selaa lähdekoodia

Merge pull request #1199 from RomanPodymov/master

Time constants
Wei Wang 6 vuotta sitten
vanhempi
commit
cc73b44fae
4 muutettua tiedostoa jossa 25 lisäystä ja 18 poistoa
  1. 1 1
      Gemfile
  2. 12 13
      Gemfile.lock
  3. 10 2
      Sources/Cache/Storage.swift
  4. 2 2
      Tests/KingfisherTests/StorageExpirationTests.swift

+ 1 - 1
Gemfile

@@ -4,4 +4,4 @@ source "https://rubygems.org"
 
 gem "fastlane"
 gem "jazzy"
-gem "cocoapods", "~> 1.7.beta"
+gem "cocoapods", "~> 1.7.1"

+ 12 - 13
Gemfile.lock

@@ -12,10 +12,10 @@ GEM
     atomos (0.1.3)
     babosa (1.0.2)
     claide (1.0.2)
-    cocoapods (1.7.0.rc.2)
+    cocoapods (1.7.1)
       activesupport (>= 4.0.2, < 5)
       claide (>= 1.0.2, < 2.0)
-      cocoapods-core (= 1.7.0.rc.2)
+      cocoapods-core (= 1.7.1)
       cocoapods-deintegrate (>= 1.0.3, < 2.0)
       cocoapods-downloader (>= 1.2.2, < 2.0)
       cocoapods-plugins (>= 1.0.0, < 2.0)
@@ -31,7 +31,7 @@ GEM
       nap (~> 1.0)
       ruby-macho (~> 1.4)
       xcodeproj (>= 1.8.2, < 2.0)
-    cocoapods-core (1.7.0.rc.2)
+    cocoapods-core (1.7.1)
       activesupport (>= 4.0.2, < 6)
       fuzzy_match (~> 2.0.4)
       nap (~> 1.0)
@@ -67,7 +67,7 @@ GEM
     faraday_middleware (0.13.1)
       faraday (>= 0.7.4, < 1.0)
     fastimage (2.1.5)
-    fastlane (2.123.0)
+    fastlane (2.124.0)
       CFPropertyList (>= 2.3, < 4.0.0)
       addressable (>= 2.3, < 3.0.0)
       babosa (>= 1.0.2, < 2.0.0)
@@ -87,7 +87,6 @@ GEM
       highline (>= 1.7.2, < 2.0.0)
       json (< 3.0.0)
       mini_magick (~> 4.5.1)
-      multi_json
       multi_xml (~> 0.5)
       multipart-post (~> 2.0.0)
       plist (>= 3.1.0, < 4.0.0)
@@ -104,7 +103,7 @@ GEM
       xcodeproj (>= 1.8.1, < 2.0.0)
       xcpretty (~> 0.3.0)
       xcpretty-travis-formatter (>= 0.0.3)
-    ffi (1.10.0)
+    ffi (1.11.1)
     fourflusher (2.2.0)
     fuzzy_match (2.0.4)
     gh_inspector (1.1.3)
@@ -148,7 +147,7 @@ GEM
       sqlite3 (~> 1.3)
       xcinvoke (~> 0.3.0)
     json (2.2.0)
-    jwt (2.1.0)
+    jwt (2.2.1)
     liferaft (0.0.6)
     memoist (0.16.0)
     mime-types (3.2.2)
@@ -180,7 +179,7 @@ GEM
     retriable (3.1.2)
     rouge (2.0.7)
     ruby-macho (1.4.0)
-    rubyzip (1.2.2)
+    rubyzip (1.2.3)
     sass (3.7.4)
       sass-listen (~> 4.0.0)
     sass-listen (4.0.0)
@@ -201,10 +200,10 @@ GEM
     terminal-table (1.8.0)
       unicode-display_width (~> 1.1, >= 1.1.1)
     thread_safe (0.3.6)
-    tty-cursor (0.6.1)
-    tty-screen (0.6.5)
-    tty-spinner (0.9.0)
-      tty-cursor (~> 0.6.0)
+    tty-cursor (0.7.0)
+    tty-screen (0.7.0)
+    tty-spinner (0.9.1)
+      tty-cursor (~> 0.7)
     tzinfo (1.2.5)
       thread_safe (~> 0.1)
     uber (0.1.0)
@@ -230,7 +229,7 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
-  cocoapods (~> 1.7.beta)
+  cocoapods (~> 1.7.1)
   fastlane
   jazzy
 

+ 10 - 2
Sources/Cache/Storage.swift

@@ -26,6 +26,14 @@
 
 import Foundation
 
+/// Constants for some time intervals
+struct TimeConstants {
+    static let secondsInOneMinute = 60
+    static let minutesInOneHour = 60
+    static let hoursInOneDay = 24
+    static let secondsInOneDay = secondsInOneMinute * minutesInOneHour * hoursInOneDay
+}
+
 /// Represents the expiration strategy used in storage.
 ///
 /// - never: The item never expires.
@@ -48,7 +56,7 @@ public enum StorageExpiration {
         switch self {
         case .never: return .distantFuture
         case .seconds(let seconds): return date.addingTimeInterval(seconds)
-        case .days(let days): return date.addingTimeInterval(TimeInterval(60 * 60 * 24 * days))
+        case .days(let days): return date.addingTimeInterval(TimeInterval(TimeConstants.secondsInOneDay * days))
         case .date(let ref): return ref
         case .expired: return .distantPast
         }
@@ -66,7 +74,7 @@ public enum StorageExpiration {
         switch self {
         case .never: return .infinity
         case .seconds(let seconds): return seconds
-        case .days(let days): return TimeInterval(60 * 60 * 24 * days)
+        case .days(let days): return TimeInterval(TimeConstants.secondsInOneDay * days)
         case .date(let ref): return ref.timeIntervalSinceNow
         case .expired: return -(.infinity)
         }

+ 2 - 2
Tests/KingfisherTests/StorageExpirationTests.swift

@@ -48,7 +48,7 @@ class StorageExpirationTests: XCTestCase {
     
     func testExpirationDays() {
         let e = StorageExpiration.days(1)
-        let oneDayInSecond: TimeInterval = 60 * 60 * 24
+        let oneDayInSecond = TimeInterval(TimeConstants.secondsInOneDay)
         XCTAssertEqual(
             e.estimatedExpirationSinceNow.timeIntervalSince1970,
             Date().timeIntervalSince1970 + oneDayInSecond,
@@ -58,7 +58,7 @@ class StorageExpirationTests: XCTestCase {
     }
     
     func testExpirationDate() {
-        let oneDayInSecond: TimeInterval = 60 * 60 * 24
+        let oneDayInSecond = TimeInterval(TimeConstants.secondsInOneDay)
         let targetDate = Date().addingTimeInterval(oneDayInSecond)
         let e = StorageExpiration.date(targetDate)
         XCTAssertEqual(