Skip to content

Commit 4dc40e7

Browse files
committed
Cleanup of return for single line statements
1 parent d981727 commit 4dc40e7

16 files changed

+84
-123
lines changed

Sources/SwiftDate/Date/Date+Compare.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public extension Date {
2525
/// - precision: The precision of the comparison (default is 5 minutes, or 300 seconds).
2626
/// - Returns: A boolean; true if close by, false otherwise.
2727
func compareCloseTo(_ refDate: Date, precision: TimeInterval = 300) -> Bool {
28-
return (abs(timeIntervalSince(refDate)) < precision)
28+
(abs(timeIntervalSince(refDate)) < precision)
2929
}
3030

3131
// MARK: - Extendend Compare
@@ -35,7 +35,7 @@ public extension Date {
3535
/// - Parameter compareType: comparison type.
3636
/// - Returns: `true` if comparison succeded, `false` otherwise
3737
func compare(_ compareType: DateComparisonType) -> Bool {
38-
return inDefaultRegion().compare(compareType)
38+
inDefaultRegion().compare(compareType)
3939
}
4040

4141
/// Returns a ComparisonResult value that indicates the ordering of two given dates based on
@@ -45,7 +45,7 @@ public extension Date {
4545
/// - parameter granularity: The smallest unit that must, along with all larger units be less for the given dates
4646
/// - returns: `ComparisonResult`
4747
func compare(toDate refDate: Date, granularity: Calendar.Component) -> ComparisonResult {
48-
return inDefaultRegion().compare(toDate: refDate.inDefaultRegion(), granularity: granularity)
48+
inDefaultRegion().compare(toDate: refDate.inDefaultRegion(), granularity: granularity)
4949
}
5050

5151
/// Compares whether the receiver is before/before equal `date` based on their components down to a given unit granularity.
@@ -56,7 +56,7 @@ public extension Date {
5656
/// - granularity: smallest unit that must, along with all larger units, be less for the given dates
5757
/// - Returns: Boolean
5858
func isBeforeDate(_ refDate: Date, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
59-
return inDefaultRegion().isBeforeDate(refDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
59+
inDefaultRegion().isBeforeDate(refDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
6060
}
6161

6262
/// Compares whether the receiver is after `date` based on their components down to a given unit granularity.
@@ -67,7 +67,7 @@ public extension Date {
6767
/// - granularity: Smallest unit that must, along with all larger units, be greater for the given dates.
6868
/// - Returns: Boolean
6969
func isAfterDate(_ refDate: Date, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
70-
return inDefaultRegion().isAfterDate(refDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
70+
inDefaultRegion().isAfterDate(refDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
7171
}
7272

7373
/// Returns a value between 0.0 and 1.0 or nil, that is the position of current date between 2 other dates.
@@ -77,7 +77,7 @@ public extension Date {
7777
/// - endDate: range lower bound date
7878
/// - Returns: `nil` if current date is not between `startDate` and `endDate`. Otherwise returns position between `startDate` and `endDate`.
7979
func positionInRange(date startDate: Date, and endDate: Date) -> Double? {
80-
return inDefaultRegion().positionInRange(date: startDate.inDefaultRegion(), and: endDate.inDefaultRegion())
80+
inDefaultRegion().positionInRange(date: startDate.inDefaultRegion(), and: endDate.inDefaultRegion())
8181
}
8282

8383
/// Return true if receiver date is contained in the range specified by two dates.
@@ -89,7 +89,7 @@ public extension Date {
8989
/// - granularity: smallest unit that must, along with all larger units, be greater for the given dates.
9090
/// - Returns: Boolean
9191
func isInRange(date startDate: Date, and endDate: Date, orEqual: Bool = false, granularity: Calendar.Component = .nanosecond) -> Bool {
92-
return inDefaultRegion().isInRange(date: startDate.inDefaultRegion(), and: endDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
92+
inDefaultRegion().isInRange(date: startDate.inDefaultRegion(), and: endDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
9393
}
9494

9595
/// Compares equality of two given dates based on their components down to a given unit
@@ -101,7 +101,7 @@ public extension Date {
101101
///
102102
/// - returns: `true` if the dates are the same down to the given granularity, otherwise `false`
103103
func isInside(date: Date, granularity: Calendar.Component) -> Bool {
104-
return (compare(toDate: date, granularity: granularity) == .orderedSame)
104+
(compare(toDate: date, granularity: granularity) == .orderedSame)
105105
}
106106

107107
// MARK: - Date Earlier/Later
@@ -111,15 +111,15 @@ public extension Date {
111111
/// - Parameter date: The date to compare to self
112112
/// - Returns: The date that is earlier
113113
func earlierDate(_ date: Date) -> Date {
114-
return timeIntervalSince(date) <= 0 ? self : date
114+
timeIntervalSince(date) <= 0 ? self : date
115115
}
116116

117117
/// Return the later of two dates, between self and a given date.
118118
///
119119
/// - Parameter date: The date to compare to self
120120
/// - Returns: The date that is later
121121
func laterDate(_ date: Date) -> Date {
122-
return timeIntervalSince(date) >= 0 ? self : date
122+
timeIntervalSince(date) >= 0 ? self : date
123123
}
124124

125125
}

Sources/SwiftDate/Date/Date+Components.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ public extension Date {
1616

1717
/// Indicates whether the month is a leap month.
1818
var isLeapMonth: Bool {
19-
return inDefaultRegion().isLeapMonth
19+
inDefaultRegion().isLeapMonth
2020
}
2121

2222
/// Indicates whether the year is a leap year.
2323
var isLeapYear: Bool {
24-
return inDefaultRegion().isLeapYear
24+
inDefaultRegion().isLeapYear
2525
}
2626

2727
/// Julian day is the continuous count of days since the beginning of
2828
/// the Julian Period used primarily by astronomers.
2929
var julianDay: Double {
30-
return inDefaultRegion().julianDay
30+
inDefaultRegion().julianDay
3131
}
3232

3333
/// The Modified Julian Date (MJD) was introduced by the Smithsonian Astrophysical Observatory
3434
/// in 1957 to record the orbit of Sputnik via an IBM 704 (36-bit machine)
3535
/// and using only 18 bits until August 7, 2576.
3636
var modifiedJulianDay: Double {
37-
return inDefaultRegion().modifiedJulianDay
37+
inDefaultRegion().modifiedJulianDay
3838
}
3939

4040
/// Return elapsed time expressed in given components since the current receiver and a reference date.
@@ -44,6 +44,6 @@ public extension Date {
4444
/// - component: time unit to extract.
4545
/// - Returns: value
4646
func getInterval(toDate: Date?, component: Calendar.Component) -> Int64 {
47-
return inDefaultRegion().getInterval(toDate: toDate?.inDefaultRegion(), component: component)
47+
inDefaultRegion().getInterval(toDate: toDate?.inDefaultRegion(), component: component)
4848
}
4949
}

Sources/SwiftDate/Date/Date+Create.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public extension Date {
6868
/// - increment: components to add
6969
/// - Returns: array of dates
7070
static func enumerateDates(from startDate: Date, to endDate: Date, increment: DateComponents) -> [Date] {
71-
return Date.enumerateDates(from: startDate, to: endDate, increment: { _ in
71+
Date.enumerateDates(from: startDate, to: endDate, increment: { _ in
7272
return increment
7373
})
7474
}
@@ -78,15 +78,15 @@ public extension Date {
7878
/// - Parameter style: rounding mode.
7979
/// - Returns: rounded date
8080
func dateRoundedAt(at style: RoundDateMode) -> Date {
81-
return inDefaultRegion().dateRoundedAt(style).date
81+
inDefaultRegion().dateRoundedAt(style).date
8282
}
8383

8484
/// Returns a new DateInRegion that is initialized at the start of a specified unit of time.
8585
///
8686
/// - Parameter unit: time unit value.
8787
/// - Returns: instance at the beginning of the time unit; `self` if fails.
8888
func dateAtStartOf(_ unit: Calendar.Component) -> Date {
89-
return inDefaultRegion().dateAtStartOf(unit).date
89+
inDefaultRegion().dateAtStartOf(unit).date
9090
}
9191

9292
/// Return a new DateInRegion that is initialized at the start of the specified components
@@ -95,7 +95,7 @@ public extension Date {
9595
/// - Parameter units: sequence of transformations as time unit components
9696
/// - Returns: new date at the beginning of the passed components, intermediate results if fails.
9797
func dateAtStartOf(_ units: [Calendar.Component]) -> Date {
98-
return units.reduce(self) { (currentDate, currentUnit) -> Date in
98+
units.reduce(self) { (currentDate, currentUnit) -> Date in
9999
return currentDate.dateAtStartOf(currentUnit)
100100
}
101101
}
@@ -106,7 +106,7 @@ public extension Date {
106106
///
107107
/// - returns: A new Moment instance.
108108
func dateAtEndOf(_ unit: Calendar.Component) -> Date {
109-
return inDefaultRegion().dateAtEndOf(unit).date
109+
inDefaultRegion().dateAtEndOf(unit).date
110110
}
111111

112112
/// Return a new DateInRegion that is initialized at the end of the specified components
@@ -115,7 +115,7 @@ public extension Date {
115115
/// - Parameter units: sequence of transformations as time unit components
116116
/// - Returns: new date at the end of the passed components, intermediate results if fails.
117117
func dateAtEndOf(_ units: [Calendar.Component]) -> Date {
118-
return units.reduce(self) { (currentDate, currentUnit) -> Date in
118+
units.reduce(self) { (currentDate, currentUnit) -> Date in
119119
return currentDate.dateAtEndOf(currentUnit)
120120
}
121121
}
@@ -125,7 +125,7 @@ public extension Date {
125125
/// - Parameter components: components to alter with their new values.
126126
/// - Returns: new altered `DateInRegion` instance
127127
func dateBySet(_ components: [Calendar.Component: Int]) -> Date? {
128-
return DateInRegion(self, region: SwiftDate.defaultRegion).dateBySet(components)?.date
128+
DateInRegion(self, region: SwiftDate.defaultRegion).dateBySet(components)?.date
129129
}
130130

131131
/// Create a new date by altering specified time components.
@@ -147,15 +147,15 @@ public extension Date {
147147
/// - Parameter components: components to truncate.
148148
/// - Returns: new date with truncated components.
149149
func dateTruncated(_ components: [Calendar.Component]) -> Date? {
150-
return DateInRegion(self, region: SwiftDate.defaultRegion).dateTruncated(at: components)?.date
150+
DateInRegion(self, region: SwiftDate.defaultRegion).dateTruncated(at: components)?.date
151151
}
152152

153153
/// Creates a new instance by truncating the components starting from given components down the granurality.
154154
///
155155
/// - Parameter component: The component to be truncated from.
156156
/// - Returns: new date with truncated components.
157157
func dateTruncated(from component: Calendar.Component) -> Date? {
158-
return DateInRegion(self, region: SwiftDate.defaultRegion).dateTruncated(from: component)?.date
158+
DateInRegion(self, region: SwiftDate.defaultRegion).dateTruncated(from: component)?.date
159159
}
160160

161161
/// Offset a date by n calendar components.
@@ -166,23 +166,23 @@ public extension Date {
166166
/// - component: component to offset.
167167
/// - Returns: new altered date.
168168
func dateByAdding(_ count: Int, _ component: Calendar.Component) -> DateInRegion {
169-
return DateInRegion(self, region: SwiftDate.defaultRegion).dateByAdding(count, component)
169+
DateInRegion(self, region: SwiftDate.defaultRegion).dateByAdding(count, component)
170170
}
171171

172172
/// Return related date starting from the receiver attributes.
173173
///
174174
/// - Parameter type: related date to obtain.
175175
/// - Returns: instance of the related date.
176176
func dateAt(_ type: DateRelatedType) -> Date {
177-
return inDefaultRegion().dateAt(type).date
177+
inDefaultRegion().dateAt(type).date
178178
}
179179

180180
/// Create a new date at now and extract the related date using passed rule type.
181181
///
182182
/// - Parameter type: related date to obtain.
183183
/// - Returns: instance of the related date.
184184
static func nowAt(_ type: DateRelatedType) -> Date {
185-
return Date().dateAt(type)
185+
Date().dateAt(type)
186186
}
187187

188188
/// Return the dates for a specific weekday inside given month of specified year.

Sources/SwiftDate/Date/Date+Math.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ import Foundation
1717
/// let difference = lhs - rhs
1818
/// rhs + difference = lhs
1919
public func - (lhs: Date, rhs: Date) -> DateComponents {
20-
return SwiftDate.defaultRegion.calendar.dateComponents(DateComponents.allComponentsSet, from: rhs, to: lhs)
20+
SwiftDate.defaultRegion.calendar.dateComponents(DateComponents.allComponentsSet, from: rhs, to: lhs)
2121
}
2222

2323
/// Adds date components to a date and returns a new date.
2424
public func + (lhs: Date, rhs: DateComponents) -> Date {
25-
return rhs.from(lhs)!
25+
rhs.from(lhs)!
2626
}
2727

2828
/// Adds date components to a date and returns a new date.
2929
public func + (lhs: DateComponents, rhs: Date) -> Date {
30-
return (rhs + lhs)
30+
(rhs + lhs)
3131
}
3232

3333
/// Subtracts date components from a date and returns a new date.
3434
public func - (lhs: Date, rhs: DateComponents) -> Date {
35-
return (lhs + (-rhs))
35+
(lhs + (-rhs))
3636
}
3737

3838
public func + (lhs: Date, rhs: TimeInterval) -> Date {
39-
return lhs.addingTimeInterval(rhs)
39+
lhs.addingTimeInterval(rhs)
4040
}

Sources/SwiftDate/Date/Date.swift

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@
1212

1313
import Foundation
1414

15-
#if os(Linux)
16-
17-
#else
1815
internal enum AssociatedKeys: String {
1916
case customDateFormatter = "SwiftDate.CustomDateFormatter"
2017
}
21-
#endif
2218

2319
extension Date: DateRepresentable {
2420

@@ -27,18 +23,9 @@ extension Date: DateRepresentable {
2723

2824
/// For absolute Date object the default region is obtained from the global `defaultRegion` variable.
2925
public var region: Region {
30-
return SwiftDate.defaultRegion
26+
SwiftDate.defaultRegion
3127
}
3228

33-
#if os(Linux)
34-
public var customFormatter: DateFormatter? {
35-
get {
36-
debugPrint("Not supported on Linux")
37-
return nil
38-
}
39-
set { debugPrint("Not supported on Linux") }
40-
}
41-
#else
4229
/// Assign a custom formatter if you need a special behaviour during formatting of the object.
4330
/// Usually you will not need to do it, SwiftDate uses the local thread date formatter in order to
4431
/// optimize the formatting process. By default is `nil`.
@@ -51,11 +38,10 @@ extension Date: DateRepresentable {
5138
set(associatedValue: newValue, key: AssociatedKeys.customDateFormatter.rawValue, object: self as AnyObject)
5239
}
5340
}
54-
#endif
5541

5642
/// Extract the date components.
5743
public var dateComponents: DateComponents {
58-
return region.calendar.dateComponents(DateComponents.allComponentsSet, from: self)
44+
region.calendar.dateComponents(DateComponents.allComponentsSet, from: self)
5945
}
6046

6147
/// Initialize a new date object from string expressed in given region.
@@ -134,29 +120,29 @@ extension Date: DateRepresentable {
134120
///
135121
/// - Returns: `DateInRegion`
136122
public func inDefaultRegion() -> DateInRegion {
137-
return DateInRegion(self, region: SwiftDate.defaultRegion)
123+
DateInRegion(self, region: SwiftDate.defaultRegion)
138124
}
139125

140126
/// Express given absolute date in the context of passed region.
141127
///
142128
/// - Parameter region: destination region.
143129
/// - Returns: `DateInRegion`
144130
public func `in`(region: Region) -> DateInRegion {
145-
return DateInRegion(self, region: region)
131+
DateInRegion(self, region: region)
146132
}
147133

148134
/// Return a date in the distant past.
149135
///
150136
/// - Returns: Date instance.
151137
public static func past() -> Date {
152-
return Date.distantPast
138+
Date.distantPast
153139
}
154140

155141
/// Return a date in the distant future.
156142
///
157143
/// - Returns: Date instance.
158144
public static func future() -> Date {
159-
return Date.distantFuture
145+
Date.distantFuture
160146
}
161147

162148
}

0 commit comments

Comments
 (0)