Date
struct Date : ReferenceConvertible, Comparable, Equatable
-
Mechanica
Checks if date is the in the future.
Declaration
Swift
public var isFuture: Bool { get }
-
Mechanica
Checks if date is the in the past.
Declaration
Swift
public var isPast: Bool { get }
-
Mechanica
Returns the UNIX timestamp from
self
.Example:
Date().unixTimestamp -> 1484233862.826291
Declaration
Swift
public var unixTimestamp: Double { get }
-
Mechanica
Returns the number of seconds between two date.
Declaration
Swift
public func secondsSince(_ date: Date) -> Double
Parameters
date
date to compate self to.
Return Value
number of seconds between self and given date.
-
Mechanica
Returns the number of minutes between two date.
Declaration
Swift
public func minutesSince(_ date: Date) -> Double
Parameters
date
date to compate self to.
Return Value
number of minutes between self and given date.
-
Mechanica
Returns the number of hours between two date.
Declaration
Swift
public func hoursSince(_ date: Date) -> Double
Parameters
date
date to compate self to.
Return Value
number of hours between self and given date.
-
Mechanica
Returns the number of days between two date.
Declaration
Swift
public func daysSince(_ date: Date) -> Double
Parameters
date
date to compare self to.
Return Value
number of days between self and given date.
-
Mechanica
Checks if a date is between two other dates.
Declaration
Swift
public func isBetween(_ startDate: Date, _ endDate: Date, includingBounds: Bool = false) -> Bool
Parameters
startDate
start date to compare self to.
endDate
endDate date to compare self to.
includingBounds
true if the start and end date should be included (default is false)
Return Value
true if the date is between the two given dates.
-
Mechanica
Generates a random date between two dates.
Example:
Date.random() Date.random(from: Date()) Date.random(upTo: Date()) Date.random(from: Date(), upTo: Date())
Declaration
Swift
public static func random(from fromDate: Date = .distantPast, upTo toDate: Date = .distantFuture) -> Date
Parameters
fromDate
minimum date (default is Date.distantPast)
toDate
maximum date (default is Date.distantFuture)
Return Value
random date between two dates.
-
Mechanica
Creates a new
Date
instance from an UNIX timestamp.Example:
let date = Date(unixTimestamp: 1484239783.922743) //
Jan 12, 2017, 7:49 PM
Declaration
Swift
public init(unixTimestamp: Double)
Parameters
unixTimestamp
UNIX timestamp.