From 74b305ca7fa7e4f7033f20c8659a34cc800358ed Mon Sep 17 00:00:00 2001 From: Jeffrey McNally-Dawes Date: Thu, 25 Apr 2019 15:50:00 -0600 Subject: [PATCH] Add convenience methods for date comparison Added before, onOrBefore, after, and onOrAfter methods to the date class to allow for easier reading in comparison to <, <=, >, >=. --- Extended/Classes/Date.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Extended/Classes/Date.swift b/Extended/Classes/Date.swift index c357d97..d4e15bb 100644 --- a/Extended/Classes/Date.swift +++ b/Extended/Classes/Date.swift @@ -98,4 +98,25 @@ extension Date { return cal.date(from: components) } + + /// Returns true if self is before the given date, false otherwise. + func before(_ date: Date) -> Bool { + return self < date + } + + /// Returns true if self is before or equal the given date, false otherwise. + func onOrBefore(_ date: Date) -> Bool { + return self <= date + } + + /// Returns true if self is after the given date, false otherwise. + func after(_ date: Date) -> Bool { + return self > date + } + + /// Returns true if self is after or equal to the given date, false otherwise. + func onOrAfter(_ date: Date) -> Bool { + return self >= date + } + }