Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Sources/Foundation/Unit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,20 @@ public final class UnitDuration : Dimension {
*/

private struct Symbol {
static let picoseconds = "ps"
static let nanoseconds = "ns"
static let microseconds = "µs"
static let milliseconds = "ms"
static let seconds = "s"
static let minutes = "m"
static let hours = "h"
}

private struct Coefficient {
static let picoseconds = 1e-12
static let nanoseconds = 1e-9
static let microseconds = 1e-6
static let milliseconds = 1e-3
static let seconds = 1.0
static let minutes = 60.0
static let hours = 3600.0
Expand All @@ -642,6 +650,30 @@ public final class UnitDuration : Dimension {
self.init(symbol: symbol, converter: UnitConverterLinear(coefficient: coefficient))
}

public class var picoseconds: UnitDuration {
get {
return UnitDuration(symbol: Symbol.picoseconds, coefficient: Coefficient.picoseconds)
}
}

public class var nanoseconds: UnitDuration {
get {
return UnitDuration(symbol: Symbol.nanoseconds, coefficient: Coefficient.nanoseconds)
}
}

public class var microseconds: UnitDuration {
get {
return UnitDuration(symbol: Symbol.microseconds, coefficient: Coefficient.microseconds)
}
}

public class var milliseconds: UnitDuration {
get {
return UnitDuration(symbol: Symbol.milliseconds, coefficient: Coefficient.milliseconds)
}
}

public class var seconds: UnitDuration {
get {
return UnitDuration(symbol: Symbol.seconds, coefficient: Coefficient.seconds)
Expand Down