Add more Calendar+Date functions

This commit is contained in:
Daniel Saidi 2021-09-08 11:18:41 +02:00
parent ce65d545d0
commit 9521f80e38
2 changed files with 55 additions and 6 deletions

View File

@ -12,8 +12,9 @@ This version also cleans up the code and makes changes to conform to the latest
### ✨ New features
* `Url+Global` has a new `userSubscriptions` url.
* `Calendar+Date` has new `same` functions to provide the comparison date.
* `String+Split` has a new `split(by:)` components splitting function.
* `Url+Global` has a new `userSubscriptions` url.
### 💥 Breaking changes

View File

@ -10,19 +10,67 @@ import Foundation
public extension Calendar {
func isDateThisWeek(_ date: Date) -> Bool {
isDate(date, equalTo: Date(), toGranularity: .weekOfYear)
/**
Whether or not this calendar thinks that a certain date
is the same day as another date.
*/
func isDate(_ date1: Date, sameDayAs date2: Date) -> Bool {
isDate(date1, equalTo: date2, toGranularity: .day)
}
/**
Whether or not this calendar thinks that a certain date
is the same month as another date.
*/
func isDate(_ date1: Date, sameMonthAs date2: Date) -> Bool {
isDate(date1, equalTo: date2, toGranularity: .month)
}
/**
Whether or not this calendar thinks that a certain date
is the same week as another date.
*/
func isDate(_ date1: Date, sameWeekAs date2: Date) -> Bool {
isDate(date1, equalTo: date2, toGranularity: .weekOfYear)
}
/**
Whether or not this calendar thinks that a certain date
is the same year as another date.
*/
func isDate(_ date1: Date, sameYearAs date2: Date) -> Bool {
isDate(date1, equalTo: date2, toGranularity: .year)
}
/**
Whether or not this calendar thinks that a certain date
is this month.
*/
func isDateThisMonth(_ date: Date) -> Bool {
isDate(date, equalTo: Date(), toGranularity: .month)
isDate(date, sameMonthAs: Date())
}
/**
Whether or not this calendar thinks that a certain date
is this week.
*/
func isDateThisWeek(_ date: Date) -> Bool {
isDate(date, sameWeekAs: Date())
}
/**
Whether or not this calendar thinks that a certain date
is this year.
*/
func isDateThisYear(_ date: Date) -> Bool {
isDate(date, equalTo: Date(), toGranularity: .year)
isDate(date, sameYearAs: Date())
}
/**
Whether or not this calendar thinks that a certain date
is today.
*/
func isDateToday(_ date: Date) -> Bool {
isDate(date, equalTo: Date(), toGranularity: .day)
isDate(date, sameDayAs: Date())
}
}