Commit fe5601da by Sarkizz

公开方法

parent 374db0dc
......@@ -8,7 +8,7 @@
import Foundation
enum TIConvertDateType {
public enum TIConvertDateType {
case now
case s1970
case reference
......@@ -16,7 +16,7 @@ enum TIConvertDateType {
}
extension Date {
static func defaultFormatter() -> DateFormatter {
public static func defaultFormatter() -> DateFormatter {
let formatter = DateFormatter()
formatter.locale = .current
formatter.timeZone = .current
......@@ -24,7 +24,7 @@ extension Date {
return formatter
}
func string(_ format: String = "yyyy.MM.dd hh:mm:ss", local: Locale = .current, timeZone: TimeZone = .current) -> String {
public func string(_ format: String = "yyyy.MM.dd hh:mm:ss", local: Locale = .current, timeZone: TimeZone = .current) -> String {
let formatter = DateFormatter()
formatter.locale = local
formatter.dateFormat = format
......@@ -32,11 +32,11 @@ extension Date {
return formatter.string(from: self)
}
func countdown(to date: Date, handler: @escaping CountdownHandler) -> Countdown {
public func countdown(to date: Date, handler: @escaping CountdownHandler) -> Countdown {
return Countdown(with: self, endTime: date).inSecond().handler(handler)
}
func countdown(from date: Date, handler: @escaping CountdownHandler) -> Countdown {
public func countdown(from date: Date, handler: @escaping CountdownHandler) -> Countdown {
return Countdown(with: date, endTime: self).inSecond().handler(handler)
}
}
......@@ -105,7 +105,7 @@ extension Date {
}
extension TimeInterval {
func date(_ type: TIConvertDateType = .reference) -> Date {
public func date(_ type: TIConvertDateType = .reference) -> Date {
switch type {
case .now:
return Date(timeIntervalSinceNow: self)
......@@ -118,16 +118,16 @@ extension TimeInterval {
}
}
func countdown(_ handler: @escaping CountdownHandler) -> Countdown {
public func countdown(_ handler: @escaping CountdownHandler) -> Countdown {
return Countdown(with: self).inSecond().handler(handler)
}
func `repeat`(_ handler: @escaping CountdownRepeatingBlock) -> Countdown {
public func `repeat`(_ handler: @escaping CountdownRepeatingBlock) -> Countdown {
return Countdown(repeatInSec: self).repeat(handler)
}
}
enum CountdownSec {
public enum CountdownSec {
case up(_ sec: Int, _ stop: CountdownSecUpStopBlock?)
case down(_ sec: Int)
......@@ -150,13 +150,13 @@ enum CountdownSec {
}
}
typealias CountdownHandler = (_ day: Int, _ hour: Int, _ minute: Int, _ second: Int) -> Void
typealias CountdownSecUpStopBlock = (_ timeInterval: TimeInterval) -> Bool
typealias CountdownRepeatingBlock = (_ cd: Countdown?) -> Void
public typealias CountdownHandler = (_ day: Int, _ hour: Int, _ minute: Int, _ second: Int) -> Void
public typealias CountdownSecUpStopBlock = (_ timeInterval: TimeInterval) -> Bool
public typealias CountdownRepeatingBlock = (_ cd: Countdown?) -> Void
final class Countdown {
public final class Countdown {
private static let defaultRepeating: TimeInterval = 1
public static let defaultRepeating: TimeInterval = 1
private var startTime: Date?
private var endTime: Date?
......@@ -175,24 +175,24 @@ final class Countdown {
}
convenience init(with startTime: Date, endTime: Date) {
public convenience init(with startTime: Date, endTime: Date) {
self.init()
self.startTime = startTime
self.endTime = endTime
}
convenience init(with startTime: String, endTime: String, formatter: DateFormatter = Date.defaultFormatter()) {
public convenience init(with startTime: String, endTime: String, formatter: DateFormatter = Date.defaultFormatter()) {
self.init()
self.startTime = formatter.date(from: startTime)
self.endTime = formatter.date(from: endTime)
}
convenience init(with timeInterval: TimeInterval) {
public convenience init(with timeInterval: TimeInterval) {
self.init()
self.countdownInterval = timeInterval
}
convenience init(repeatInSec: TimeInterval) {
public convenience init(repeatInSec: TimeInterval) {
self.init()
self.repeatInSec = repeatInSec
}
......@@ -231,11 +231,11 @@ extension Countdown {
return self
}
func resume() {
public func resume() {
timer.resume()
}
func resetTimer() {
public func resetTimer() {
timer.cancel()
timer = nil
}
......@@ -325,7 +325,7 @@ extension Countdown {
}
extension Int {
func countup(stop: CountdownSecUpStopBlock?, handler: @escaping CountdownHandler) -> Countdown {
public func countup(stop: CountdownSecUpStopBlock?, handler: @escaping CountdownHandler) -> Countdown {
return Countdown().limitCound(self).inSecond(.up(1, stop)).handler(handler)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment