Skip to content

Commit 3ddf6d5

Browse files
committed
#648 Swift5 Compatibility
1 parent 600a641 commit 3ddf6d5

25 files changed

+211
-199
lines changed
380 Bytes
Binary file not shown.

Sources/SwiftDate/Date/Date+Compare.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public extension Date {
2020
/// - refDate: reference date compare against to.
2121
/// - precision: The precision of the comparison (default is 5 minutes, or 300 seconds).
2222
/// - Returns: A boolean; true if close by, false otherwise.
23-
public func compareCloseTo(_ refDate: Date, precision: TimeInterval = 300) -> Bool {
23+
func compareCloseTo(_ refDate: Date, precision: TimeInterval = 300) -> Bool {
2424
return (abs(timeIntervalSince(refDate)) < precision)
2525
}
2626

@@ -30,7 +30,7 @@ public extension Date {
3030
///
3131
/// - Parameter compareType: comparison type.
3232
/// - Returns: `true` if comparison succeded, `false` otherwise
33-
public func compare(_ compareType: DateComparisonType) -> Bool {
33+
func compare(_ compareType: DateComparisonType) -> Bool {
3434
return inDefaultRegion().compare(compareType)
3535
}
3636

@@ -51,7 +51,7 @@ public extension Date {
5151
/// - orEqual: `true` to also check for equality
5252
/// - granularity: smallest unit that must, along with all larger units, be less for the given dates
5353
/// - Returns: Boolean
54-
public func isBeforeDate(_ refDate: Date, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
54+
func isBeforeDate(_ refDate: Date, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
5555
return inDefaultRegion().isBeforeDate(refDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
5656
}
5757

@@ -62,7 +62,7 @@ public extension Date {
6262
/// - orEqual: `true` to also check for equality
6363
/// - granularity: Smallest unit that must, along with all larger units, be greater for the given dates.
6464
/// - Returns: Boolean
65-
public func isAfterDate(_ refDate: Date, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
65+
func isAfterDate(_ refDate: Date, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
6666
return inDefaultRegion().isAfterDate(refDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
6767
}
6868

@@ -74,7 +74,7 @@ public extension Date {
7474
/// - orEqual: `true` to also check for equality on date and date2
7575
/// - granularity: smallest unit that must, along with all larger units, be greater for the given dates.
7676
/// - Returns: Boolean
77-
public func isInRange(date startDate: Date, and endDate: Date, orEqual: Bool = false, granularity: Calendar.Component = .nanosecond) -> Bool {
77+
func isInRange(date startDate: Date, and endDate: Date, orEqual: Bool = false, granularity: Calendar.Component = .nanosecond) -> Bool {
7878
return self.inDefaultRegion().isInRange(date: startDate.inDefaultRegion(), and: endDate.inDefaultRegion(), orEqual: orEqual, granularity: granularity)
7979
}
8080

@@ -86,7 +86,7 @@ public extension Date {
8686
/// dates to be considered the same.
8787
///
8888
/// - returns: `true` if the dates are the same down to the given granularity, otherwise `false`
89-
public func isInside(date: Date, granularity: Calendar.Component) -> Bool {
89+
func isInside(date: Date, granularity: Calendar.Component) -> Bool {
9090
return (compare(toDate: date, granularity: granularity) == .orderedSame)
9191
}
9292

@@ -96,15 +96,15 @@ public extension Date {
9696
///
9797
/// - Parameter date: The date to compare to self
9898
/// - Returns: The date that is earlier
99-
public func earlierDate(_ date: Date) -> Date {
99+
func earlierDate(_ date: Date) -> Date {
100100
return (timeIntervalSince1970 <= date.timeIntervalSince1970) ? self : date
101101
}
102102

103103
/// Return the later of two dates, between self and a given date.
104104
///
105105
/// - Parameter date: The date to compare to self
106106
/// - Returns: The date that is later
107-
public func laterDate(_ date: Date) -> Date {
107+
func laterDate(_ date: Date) -> Date {
108108
return (timeIntervalSince1970 >= date.timeIntervalSince1970) ? self : date
109109
}
110110

Sources/SwiftDate/Date/Date+Components.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ import Foundation
1111
public extension Date {
1212

1313
/// Indicates whether the month is a leap month.
14-
public var isLeapMonth: Bool {
14+
var isLeapMonth: Bool {
1515
return inDefaultRegion().isLeapMonth
1616
}
1717

1818
/// Indicates whether the year is a leap year.
19-
public var isLeapYear: Bool {
19+
var isLeapYear: Bool {
2020
return inDefaultRegion().isLeapYear
2121
}
2222

2323
/// Julian day is the continuous count of days since the beginning of
2424
/// the Julian Period used primarily by astronomers.
25-
public var julianDay: Double {
25+
var julianDay: Double {
2626
return inDefaultRegion().julianDay
2727
}
2828

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

@@ -39,7 +39,7 @@ public extension Date {
3939
/// - refDate: reference date (`nil` to use current date in the same region of the receiver)
4040
/// - component: time unit to extract.
4141
/// - Returns: value
42-
public func getInterval(toDate: Date?, component: Calendar.Component) -> Int64 {
42+
func getInterval(toDate: Date?, component: Calendar.Component) -> Int64 {
4343
return inDefaultRegion().getInterval(toDate: toDate?.inDefaultRegion(), component: component)
4444
}
4545
}

Sources/SwiftDate/Date/Date+Create.swift

+18-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public extension Date {
1414
///
1515
/// - Parameter list: list of dates
1616
/// - Returns: a tuple with the index of the oldest date and its instance.
17-
public static func oldestIn(list: [Date]) -> Date? {
17+
static func oldestIn(list: [Date]) -> Date? {
1818
guard list.count > 0 else { return nil }
1919
guard list.count > 1 else { return list.first! }
2020
return list.min(by: {
@@ -26,7 +26,7 @@ public extension Date {
2626
///
2727
/// - Parameter list: list of dates
2828
/// - Returns: a tuple with the index of the oldest date and its instance.
29-
public static func newestIn(list: [Date]) -> Date? {
29+
static func newestIn(list: [Date]) -> Date? {
3030
guard list.count > 0 else { return nil }
3131
guard list.count > 1 else { return list.first! }
3232
return list.max(by: {
@@ -43,7 +43,7 @@ public extension Date {
4343
/// - endDate: ending date
4444
/// - increment: increment function. It get the last generated date and require a valida `DateComponents` instance which define the increment
4545
/// - Returns: array of dates
46-
public static func enumerateDates(from startDate: Date, to endDate: Date, increment: ((Date) -> (DateComponents))) -> [Date] {
46+
static func enumerateDates(from startDate: Date, to endDate: Date, increment: ((Date) -> (DateComponents))) -> [Date] {
4747
var dates: [Date] = []
4848
var currentDate = startDate
4949

@@ -63,7 +63,7 @@ public extension Date {
6363
/// - endDate: ending date
6464
/// - increment: components to add
6565
/// - Returns: array of dates
66-
public static func enumerateDates(from startDate: Date, to endDate: Date, increment: DateComponents) -> [Date] {
66+
static func enumerateDates(from startDate: Date, to endDate: Date, increment: DateComponents) -> [Date] {
6767
return Date.enumerateDates(from: startDate, to: endDate, increment: { _ in
6868
return increment
6969
})
@@ -73,15 +73,15 @@ public extension Date {
7373
///
7474
/// - Parameter style: rounding mode.
7575
/// - Returns: rounded date
76-
public func dateRoundedAt(at style: RoundDateMode) -> Date {
76+
func dateRoundedAt(at style: RoundDateMode) -> Date {
7777
return inDefaultRegion().dateRoundedAt(style).date
7878
}
7979

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

@@ -90,7 +90,7 @@ public extension Date {
9090
///
9191
/// - Parameter units: sequence of transformations as time unit components
9292
/// - Returns: new date at the beginning of the passed components, intermediate results if fails.
93-
public func dateAtStartOf(_ units: [Calendar.Component]) -> Date {
93+
func dateAtStartOf(_ units: [Calendar.Component]) -> Date {
9494
return units.reduce(self) { (currentDate, currentUnit) -> Date in
9595
return currentDate.dateAtStartOf(currentUnit)
9696
}
@@ -101,7 +101,7 @@ public extension Date {
101101
/// - parameter unit: A TimeUnit value.
102102
///
103103
/// - returns: A new Moment instance.
104-
public func dateAtEndOf(_ unit: Calendar.Component) -> Date {
104+
func dateAtEndOf(_ unit: Calendar.Component) -> Date {
105105
return inDefaultRegion().dateAtEndOf(unit).date
106106
}
107107

@@ -110,7 +110,7 @@ public extension Date {
110110
///
111111
/// - Parameter units: sequence of transformations as time unit components
112112
/// - Returns: new date at the end of the passed components, intermediate results if fails.
113-
public func dateAtEndOf(_ units: [Calendar.Component]) -> Date {
113+
func dateAtEndOf(_ units: [Calendar.Component]) -> Date {
114114
return units.reduce(self) { (currentDate, currentUnit) -> Date in
115115
return currentDate.dateAtEndOf(currentUnit)
116116
}
@@ -120,7 +120,7 @@ public extension Date {
120120
///
121121
/// - Parameter components: components to alter with their new values.
122122
/// - Returns: new altered `DateInRegion` instance
123-
public func dateBySet(_ components: [Calendar.Component: Int]) -> Date? {
123+
func dateBySet(_ components: [Calendar.Component: Int]) -> Date? {
124124
return DateInRegion(self, region: SwiftDate.defaultRegion).dateBySet(components)?.date
125125
}
126126

@@ -133,7 +133,7 @@ public extension Date {
133133
/// - ms: milliseconds to set (`nil` to leave it unaltered)
134134
/// - options: options for calculation
135135
/// - Returns: new altered `DateInRegion` instance
136-
public func dateBySet(hour: Int?, min: Int?, secs: Int?, ms: Int? = nil, options: TimeCalculationOptions = TimeCalculationOptions()) -> Date? {
136+
func dateBySet(hour: Int?, min: Int?, secs: Int?, ms: Int? = nil, options: TimeCalculationOptions = TimeCalculationOptions()) -> Date? {
137137
let srcDate = DateInRegion(self, region: SwiftDate.defaultRegion)
138138
return srcDate.dateBySet(hour: hour, min: min, secs: secs, ms: ms, options: options)?.date
139139
}
@@ -142,15 +142,15 @@ public extension Date {
142142
///
143143
/// - Parameter components: components to truncate.
144144
/// - Returns: new date with truncated components.
145-
public func dateTruncated(_ components: [Calendar.Component]) -> Date? {
145+
func dateTruncated(_ components: [Calendar.Component]) -> Date? {
146146
return DateInRegion(self, region: SwiftDate.defaultRegion).dateTruncated(at: components)?.date
147147
}
148148

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

@@ -161,23 +161,23 @@ public extension Date {
161161
/// - count: value of the offset.
162162
/// - component: component to offset.
163163
/// - Returns: new altered date.
164-
public func dateByAdding(_ count: Int, _ component: Calendar.Component) -> DateInRegion {
164+
func dateByAdding(_ count: Int, _ component: Calendar.Component) -> DateInRegion {
165165
return DateInRegion(self, region: SwiftDate.defaultRegion).dateByAdding(count, component)
166166
}
167167

168168
/// Return related date starting from the receiver attributes.
169169
///
170170
/// - Parameter type: related date to obtain.
171171
/// - Returns: instance of the related date.
172-
public func dateAt(_ type: DateRelatedType) -> Date {
172+
func dateAt(_ type: DateRelatedType) -> Date {
173173
return inDefaultRegion().dateAt(type).date
174174
}
175175

176176
/// Create a new date at now and extract the related date using passed rule type.
177177
///
178178
/// - Parameter type: related date to obtain.
179179
/// - Returns: instance of the related date.
180-
public static func nowAt(_ type: DateRelatedType) -> Date {
180+
static func nowAt(_ type: DateRelatedType) -> Date {
181181
return Date().dateAt(type)
182182
}
183183

@@ -191,7 +191,7 @@ public extension Date {
191191
/// - year: year target.
192192
/// - region: region target, omit to use `SwiftDate.defaultRegion`
193193
/// - Returns: Ordered list of the dates for given weekday into given month.
194-
public static func datesForWeekday(_ weekday: WeekDay, inMonth month: Int, ofYear year: Int,
194+
static func datesForWeekday(_ weekday: WeekDay, inMonth month: Int, ofYear year: Int,
195195
region: Region = SwiftDate.defaultRegion) -> [Date] {
196196
let fromDate = DateInRegion(Date(year: year, month: month, day: 1, hour: 0, minute: 0), region: region)
197197
let toDate = fromDate.dateAt(.endOfMonth)
@@ -207,7 +207,7 @@ public extension Date {
207207
/// - endDate: to date of the range.
208208
/// - region: region target, omit to use `SwiftDate.defaultRegion`
209209
/// - Returns: Ordered list of the dates for given weekday in passed range.
210-
public static func datesForWeekday(_ weekday: WeekDay, from startDate: Date, to endDate: Date,
210+
static func datesForWeekday(_ weekday: WeekDay, from startDate: Date, to endDate: Date,
211211
region: Region = SwiftDate.defaultRegion) -> [Date] {
212212
let fromDate = DateInRegion(startDate, region: region)
213213
let toDate = DateInRegion(endDate, region: region)

Sources/SwiftDate/DateInRegion/DateInRegion+Compare.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ public extension DateInRegion {
115115
/// - refDate: reference date compare against to.
116116
/// - precision: The precision of the comparison (default is 5 minutes, or 300 seconds).
117117
/// - Returns: A boolean; true if close by, false otherwise.
118-
public func compareCloseTo(_ refDate: DateInRegion, precision: TimeInterval = 300) -> Bool {
118+
func compareCloseTo(_ refDate: DateInRegion, precision: TimeInterval = 300) -> Bool {
119119
return (abs(date.timeIntervalSince(refDate.date)) <= precision)
120120
}
121121

122122
/// Compare the date with the rule specified in the `compareType` parameter.
123123
///
124124
/// - Parameter compareType: comparison type.
125125
/// - Returns: `true` if comparison succeded, `false` otherwise
126-
public func compare(_ compareType: DateComparisonType) -> Bool {
126+
func compare(_ compareType: DateComparisonType) -> Bool {
127127
switch compareType {
128128
case .isToday:
129129
return compare(.isSameDay(region.nowInThisRegion()))
@@ -247,7 +247,7 @@ public extension DateInRegion {
247247
/// - orEqual: `true` to also check for equality
248248
/// - granularity: smallest unit that must, along with all larger units, be less for the given dates
249249
/// - Returns: Boolean
250-
public func isBeforeDate(_ date: DateInRegion, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
250+
func isBeforeDate(_ date: DateInRegion, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
251251
let result = compare(toDate: date, granularity: granularity)
252252
return (orEqual ? (result == .orderedSame || result == .orderedAscending) : result == .orderedAscending)
253253
}
@@ -259,7 +259,7 @@ public extension DateInRegion {
259259
/// - orEqual: `true` to also check for equality
260260
/// - granularity: Smallest unit that must, along with all larger units, be greater for the given dates.
261261
/// - Returns: Boolean
262-
public func isAfterDate(_ refDate: DateInRegion, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
262+
func isAfterDate(_ refDate: DateInRegion, orEqual: Bool = false, granularity: Calendar.Component) -> Bool {
263263
let result = compare(toDate: refDate, granularity: granularity)
264264
return (orEqual ? (result == .orderedSame || result == .orderedDescending) : result == .orderedDescending)
265265
}
@@ -272,7 +272,7 @@ public extension DateInRegion {
272272
/// dates to be considered the same.
273273
///
274274
/// - returns: `true` if the dates are the same down to the given granularity, otherwise `false`
275-
public func isInside(date: DateInRegion, granularity: Calendar.Component) -> Bool {
275+
func isInside(date: DateInRegion, granularity: Calendar.Component) -> Bool {
276276
return (compare(toDate: date, granularity: granularity) == .orderedSame)
277277
}
278278

@@ -284,7 +284,7 @@ public extension DateInRegion {
284284
/// - orEqual: `true` to also check for equality on date and date2, default is `true`
285285
/// - granularity: smallest unit that must, along with all larger units, be greater
286286
/// - Returns: Boolean
287-
public func isInRange(date startDate: DateInRegion, and endDate: DateInRegion, orEqual: Bool = true, granularity: Calendar.Component = .nanosecond) -> Bool {
287+
func isInRange(date startDate: DateInRegion, and endDate: DateInRegion, orEqual: Bool = true, granularity: Calendar.Component = .nanosecond) -> Bool {
288288
return isAfterDate(startDate, orEqual: orEqual, granularity: granularity) && isBeforeDate(endDate, orEqual: orEqual, granularity: granularity)
289289
}
290290

@@ -294,15 +294,15 @@ public extension DateInRegion {
294294
///
295295
/// - Parameter date: The date to compare to self
296296
/// - Returns: The date that is earlier
297-
public func earlierDate(_ date: DateInRegion) -> DateInRegion {
297+
func earlierDate(_ date: DateInRegion) -> DateInRegion {
298298
return (self.date.timeIntervalSince1970 <= date.date.timeIntervalSince1970) ? self : date
299299
}
300300

301301
/// Return the later of two dates, between self and a given date.
302302
///
303303
/// - Parameter date: The date to compare to self
304304
/// - Returns: The date that is later
305-
public func laterDate(_ date: DateInRegion) -> DateInRegion {
305+
func laterDate(_ date: DateInRegion) -> DateInRegion {
306306
return (self.date.timeIntervalSince1970 >= date.date.timeIntervalSince1970) ? self : date
307307
}
308308

0 commit comments

Comments
 (0)