Skip to content
Closed
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
34 changes: 33 additions & 1 deletion Sources/Foundation/Unit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,17 @@ public final class UnitDuration : Dimension {
static let seconds = "s"
static let minutes = "m"
static let hours = "h"
static let millisconds = "ms"
static let microseconds = "µs"
static let nanoseconds = "ns"
static let picoseconds = "ps"
}

private struct Coefficient {
static let picoseconds = 1e-12
static let nanoseconds = 1e-9
static let microseconds = 1e-6
static let millisconds = 1e-3
static let seconds = 1.0
static let minutes = 60.0
static let hours = 3600.0
Expand All @@ -641,6 +649,30 @@ public final class UnitDuration : Dimension {
private convenience init(symbol: String, coefficient: Double) {
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 millisconds: UnitDuration {
get {
return UnitDuration(symbol: Symbol.millisconds, coefficient: Coefficient.millisconds)
}
}

public class var seconds: UnitDuration {
get {
Expand All @@ -659,7 +691,7 @@ public final class UnitDuration : Dimension {
return UnitDuration(symbol: Symbol.hours, coefficient: Coefficient.hours)
}
}

public override class func baseUnit() -> UnitDuration {
return .seconds
}
Expand Down