Tusker/Tusker/Caching/CacheExpiry.swift

31 lines
589 B
Swift
Raw Normal View History

2021-01-18 23:46:59 +00:00
//
// CacheExpiry.swift
// Tusker
//
// Created by Shadowfacts on 1/18/21.
// Copyright © 2021 Shadowfacts. All rights reserved.
//
import Foundation
enum CacheExpiry {
case never
case seconds(TimeInterval)
case date(Date)
var date: Date {
switch self {
case .never:
return .distantFuture
case let .seconds(seconds):
return Date().addingTimeInterval(seconds)
case let .date(date):
return date
}
}
var isExpired: Bool {
return date.timeIntervalSinceNow < 0
}
}