From a0c4dc4554754b13f3367a18bc05f65a7fdafa6e Mon Sep 17 00:00:00 2001 From: Martin Gyupchanov Date: Tue, 11 Jul 2017 23:38:24 -0400 Subject: [PATCH] Add missing months property to TimePeriod --- DateToolsSwift/DateTools/TimePeriod.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/DateToolsSwift/DateTools/TimePeriod.swift b/DateToolsSwift/DateTools/TimePeriod.swift index 4a060a81..427e2e63 100644 --- a/DateToolsSwift/DateTools/TimePeriod.swift +++ b/DateToolsSwift/DateTools/TimePeriod.swift @@ -54,7 +54,18 @@ public extension TimePeriodProtocol { } return Int.max } - + + /** + * The duration of the `TimePeriod` in months. + * Returns the max int if beginning or end are nil. + */ + public var months: Int { + if self.beginning != nil && self.end != nil { + return self.beginning!.monthsEarlier(than: self.end!) + } + return Int.max + } + /** * The duration of the `TimePeriod` in weeks. * Returns the max int if beginning or end are nil.