WIP - Sharing
This commit is contained in:
@@ -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!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user