From b99a6bfd1fa2c4425e546c9274ee0df734c1aa72 Mon Sep 17 00:00:00 2001 From: Seyyed Parsa Neshaei Date: Tue, 6 Jul 2021 20:52:22 +0430 Subject: [PATCH 1/2] Fixing issue #717 - Get the total second from mm:ss format --- Sources/SwiftDate/Date/Date.swift | 5 +++++ Sources/SwiftDate/DateRepresentable.swift | 3 +++ Sources/SwiftDate/Formatters/RelativeFormatter/langs/en.json | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftDate/Date/Date.swift b/Sources/SwiftDate/Date/Date.swift index 9e7b8011..060a8cd1 100644 --- a/Sources/SwiftDate/Date/Date.swift +++ b/Sources/SwiftDate/Date/Date.swift @@ -57,6 +57,11 @@ extension Date: DateRepresentable { public var dateComponents: DateComponents { return region.calendar.dateComponents(DateComponents.allComponentsSet, from: self) } + + /// Get the total number of seconds in the registered 'time'. + public var totalSeconds: Int { + return ((hour * 60) + minute) * 60 + second; + } /// Initialize a new date object from string expressed in given region. /// diff --git a/Sources/SwiftDate/DateRepresentable.swift b/Sources/SwiftDate/DateRepresentable.swift index 717fd21f..50c48457 100644 --- a/Sources/SwiftDate/DateRepresentable.swift +++ b/Sources/SwiftDate/DateRepresentable.swift @@ -52,6 +52,9 @@ public protocol DateRepresentable { /// Second unit of the receiver. var second: Int { get } + + /// Total seconds of the receiver. + var totalSeconds: Int { get } /// Nanosecond unit of the receiver. var nanosecond: Int { get } diff --git a/Sources/SwiftDate/Formatters/RelativeFormatter/langs/en.json b/Sources/SwiftDate/Formatters/RelativeFormatter/langs/en.json index 223f7020..aa9c236f 100644 --- a/Sources/SwiftDate/Formatters/RelativeFormatter/langs/en.json +++ b/Sources/SwiftDate/Formatters/RelativeFormatter/langs/en.json @@ -230,4 +230,4 @@ "current" : "this qtr." } } -} \ No newline at end of file +} From 19af098b0d607076f127dec8909fc530ad63fac8 Mon Sep 17 00:00:00 2001 From: Seyyed Parsa Neshaei Date: Tue, 6 Jul 2021 20:53:26 +0430 Subject: [PATCH 2/2] Fixed issue #717 - Get the total second from mm:ss format --- Sources/SwiftDate/DateInRegion/DateInRegion.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/SwiftDate/DateInRegion/DateInRegion.swift b/Sources/SwiftDate/DateInRegion/DateInRegion.swift index 98133f70..0d521742 100644 --- a/Sources/SwiftDate/DateInRegion/DateInRegion.swift +++ b/Sources/SwiftDate/DateInRegion/DateInRegion.swift @@ -30,6 +30,9 @@ public struct DateInRegion: DateRepresentable, Decodable, Encodable, CustomStrin public var dateComponents: DateComponents { return region.calendar.dateComponents(DateComponents.allComponentsSet, from: date) } + + /// Get the total number of seconds in the registered 'time'. + public var totalSeconds: Int /// Description of the date public var description: String {