Skip to content

Commit 9cd921e

Browse files
committed
Implements SwiftDate/malcommac#780
1 parent 04c7abf commit 9cd921e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sources/SwiftDate/Date/Date+Math.swift

+10
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@ import Foundation
1616
/// Follows this mathematical pattern:
1717
/// let difference = lhs - rhs
1818
/// rhs + difference = lhs
19+
///
1920
public func - (lhs: Date, rhs: Date) -> DateComponents {
2021
SwiftDate.defaultRegion.calendar.dateComponents(DateComponents.allComponentsSet, from: rhs, to: lhs)
2122
}
2223

2324
/// Adds date components to a date and returns a new date.
25+
///
2426
public func + (lhs: Date, rhs: DateComponents) -> Date {
2527
rhs.from(lhs)!
2628
}
2729

2830
/// Adds date components to a date and returns a new date.
31+
///
2932
public func + (lhs: DateComponents, rhs: Date) -> Date {
3033
(rhs + lhs)
3134
}
3235

36+
/// Adds ``DateInRegion`` to a date and returns a new date.
37+
///
38+
public func + (lhs: Date, rhs: DateInRegion) -> Date {
39+
return (lhs + rhs.date.dateComponents)
40+
}
41+
3342
/// Subtracts date components from a date and returns a new date.
43+
///
3444
public func - (lhs: Date, rhs: DateComponents) -> Date {
3545
(lhs + (-rhs))
3646
}

0 commit comments

Comments
 (0)