From 2c1321b6001ed95ab3a8ee2e364da375b396b42a Mon Sep 17 00:00:00 2001 From: Seyyed Parsa Neshaei Date: Tue, 6 Jul 2021 21:00:31 +0430 Subject: [PATCH] Fixing issue #715 - Slightly different results for dateAt(.endOfDay) and dateAtEndOf(.day) --- Sources/SwiftDate/Date/Date+Create.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftDate/Date/Date+Create.swift b/Sources/SwiftDate/Date/Date+Create.swift index 965f5c35..f46a2ffa 100644 --- a/Sources/SwiftDate/Date/Date+Create.swift +++ b/Sources/SwiftDate/Date/Date+Create.swift @@ -106,7 +106,14 @@ public extension Date { /// /// - returns: A new Moment instance. func dateAtEndOf(_ unit: Calendar.Component) -> Date { - return inDefaultRegion().dateAtEndOf(unit).date + switch unit { + case .day: + return inDefaultRegion().dateAt(.endOfDay).date + case .month: + return inDefaultRegion().dateAt(.endOfMonth).date + default: + return inDefaultRegion().dateAtEndOf(unit).date + } } /// Return a new DateInRegion that is initialized at the end of the specified components