From 6a9e2ba8639ffcb92ca744b4a02806557cadb059 Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 22 Aug 2018 13:12:39 +0800 Subject: [PATCH] Fix issues about building on linux --- Sources/Schedule/Interval.swift | 10 ++++++++++ Sources/Schedule/Period.swift | 6 +++--- Sources/Schedule/Time.swift | 12 ++++++------ Tests/ScheduleTests/DateTimeTests.swift | 18 +++++++++--------- Tests/ScheduleTests/Misc.swift | 11 ----------- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/Sources/Schedule/Interval.swift b/Sources/Schedule/Interval.swift index 6dc1baa..67339e3 100644 --- a/Sources/Schedule/Interval.swift +++ b/Sources/Schedule/Interval.swift @@ -102,6 +102,16 @@ extension Interval { self.init(nanoseconds: seconds * pow(10, 9)) } + /// The length of this interval in microseconds. + public var microseconds: Double { + return nanoseconds / pow(10, 3) + } + + /// The length of this interval in milliseconds. + public var milliseconds: Double { + return nanoseconds / pow(10, 6) + } + /// The length of this interval in seconds. public var seconds: Double { return nanoseconds / pow(10, 9) diff --git a/Sources/Schedule/Period.swift b/Sources/Schedule/Period.swift index 3ad6ad5..c189adc 100644 --- a/Sources/Schedule/Period.swift +++ b/Sources/Schedule/Period.swift @@ -137,9 +137,9 @@ public struct Period { public func tidied(to unit: Unit) -> Period { var period = self if case .nanosecond = unit { return period } - if period.nanoseconds.magnitude >= UInt(NSEC_PER_SEC) { - period.seconds += period.nanoseconds / Int(NSEC_PER_SEC) - period.nanoseconds %= Int(NSEC_PER_SEC) + if period.nanoseconds.magnitude >= UInt(1.second.nanoseconds) { + period.seconds += period.nanoseconds / Int(1.second.nanoseconds) + period.nanoseconds %= Int(1.second.nanoseconds) } if case .second = unit { return period } diff --git a/Sources/Schedule/Time.swift b/Sources/Schedule/Time.swift index d1e74ac..c8d8069 100644 --- a/Sources/Schedule/Time.swift +++ b/Sources/Schedule/Time.swift @@ -30,10 +30,10 @@ public struct Time { /// Time(hour: 25) => nil /// Time(hour: 1, minute: 61) => nil public init?(hour: Int, minute: Int = 0, second: Int = 0, nanosecond: Int = 0) { - guard (0..<24).contains(hour) else { return nil } - guard (0..<60).contains(minute) else { return nil } - guard (0..<60).contains(second) else { return nil } - guard (0..