Skip to content

Commit

Permalink
feat: Add start and end of day dates (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Dec 9, 2024
1 parent 000f9f3 commit 285c696
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/CareKitEssentials/Extensions/Calendar+Dates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ public extension Date {
var isLastDayOfMonth: Bool {
return dayAfter.month != month
}
// Reference: https://stackoverflow.com/a/20158940/4639041
var startOfDay: Date {
return Calendar.current.startOfDay(for: self)
}
var endOfDay: Date {
var components = DateComponents()
components.day = 1
components.second = -1
return Calendar.current.date(byAdding: components, to: startOfDay)!
}
}

0 comments on commit 285c696

Please sign in to comment.