WIP - Sharing

This commit is contained in:
Trey t
2022-02-13 10:20:43 -06:00
parent c85801b099
commit b878d908c4
16 changed files with 877 additions and 289 deletions

View File

@@ -59,6 +59,30 @@ extension Date: RawRepresentable {
public init?(rawValue: String) {
self = Date(timeIntervalSinceReferenceDate: Double(rawValue) ?? 0.0)
}
func startOfMonth() -> Date {
let interval = Calendar.current.dateInterval(of: .month, for: self)
return (interval?.start.toLocalTime())! // Without toLocalTime it give last months last date
}
func endOfMonth() -> Date {
let interval = Calendar.current.dateInterval(of: .month, for: self)
return interval!.end
}
func toLocalTime() -> Date {
let timezone = TimeZone.current
let seconds = TimeInterval(timezone.secondsFromGMT(for: self))
return Date(timeInterval: seconds, since: self)
}
var weekday: Int {
Calendar.current.component(.weekday, from: self)
}
var firstDayOfTheMonth: Date {
Calendar.current.dateComponents([.calendar, .year,.month], from: self).date!
}
}