diff --git a/Sources/Sugar/Helpers/SecondsConverter.swift b/Sources/Sugar/Helpers/SecondsConverter.swift new file mode 100644 index 0000000..38f171e --- /dev/null +++ b/Sources/Sugar/Helpers/SecondsConverter.swift @@ -0,0 +1,20 @@ +// These helpers are not ideal for calculating specific moments in time (past/future). +// See https://nshipster.com/timeinterval-date-dateinterval/ for more information. +// Instead these helpers should be used for e.g. setting a expiration time of something. +public extension Numeric { + public var minsInSecs: Self { + return self * 60 + } + + public var hoursInSecs: Self { + return self.minsInSecs * 60 + } + + public var daysInSecs: Self { + return self.hoursInSecs * 24 + } + + public var weeksInSecs: Self { + return self.daysInSecs * 7 + } +}