Overview

Working with time components in SwiftDate is pretty easy; both DateInRegion and plain Date implements the same set of properties and function to query for time units or manage dates.

Keep in mind: when using Date objects you are working with a Date instance which is expressed in .defaultRegion.

Initial value of this property is Region.GMT() which define a region located in GMT TimeZone and with current device's Locale and Calendar.

You can change the default region by calling Date static func .setDefaultRegion().

era

The number of era units for the receiver.

Declaration
public var era: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

year

The number of years units for the receiver.

Declaration
public var year: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

month

The number of months units for the receiver.

Declaration
public var month: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

day

The number of days units for the receiver.

Declaration
public var day: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

hour

The number of hour units for the receiver.

Declaration
public var hour: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

nearestHour

Nearest rounded hour from the date.

Declaration
public var nearestHour: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

minute

The number of minute units for the receiver.

Declaration
public var minute: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

second

The number of second units for the receiver.

Declaration
public var second: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

nanosecond

The number of nanosecond units for the receiver.

Declaration
public var nanosecond: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

yearForWeekOfYear

The number of week-numbering units for the receiver.

Declaration
public var yearForWeekOfYear: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

weekOfYear

The week date of the year for the receiver.

Declaration
public var weekOfYear: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

weekday

The number of weekday units for the receiver.

Weekday units are the numbers 1 though n, where n is the number of days in the week.
For example, in the Gregorian calendar, n is 7 and Sunday is represented by 1.

Declaration
public var weekday: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

weekdayOrdinal

The ordinal number of weekday units for the receiver.
Weekday ordinal units represent the position of the weekday within the next larger calendar unit , such as the month.
For example, 2 is the weekday ordinal unit for the second Friday of the month.

Declaration
public var weekdayOrdinal: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

weekdayName

Week day name of the date

Declaration
public var weekdayName: String
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

monthDays

Number of days into current's date month expressed in current region calendar and locale

Declaration
public var monthDays: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

quarter

The number of quarter units for the receiver.

Declaration
public var quarter: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

weekOfMonth

The week number in the month for the receiver.

Declaration
public var weekOfMonth: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

monthName

Month name of the date.

Declaration
public var monthName: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

shortMonthName

Short month name of the date.

Declaration
public var monthName: Int
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

leapMonth

Boolean value that indicates whether the month is a leap month.

It return true if the month is a leap month, false otherwise.

Declaration
public var leapMonth: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

leapYear

Boolean value that indicates whether the month is a leap year.

It return true if the month is a leap year, false otherwise.

Declaration
public var leapYear: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

julianDay

Julian day is the continuous count of days since the beginning of the Julian Period used primarily by astronomers.

Declaration
public var julianDay: Double
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

modifiedJulianDay

The Modified Julian Date (MJD) was introduced by the Smithsonian Astrophysical Observatory in 1957 to record the orbit of Sputnik via an IBM 704 (36-bit machine) and using only 18 bits until August 7, 2576.

Declaration
public var modifiedJulianDay: Double
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

previousWeekend

Returns two DateInRegion objects indicating the start and the end of the previous weekend before the date..
Object is a tuple of two DateInRegion objects indicating the start and the end of the previous weekend previous the date.
The weekend returned when the receiver is in a weekend is the previous weekend not the current one.

Declaration
public var previousWeekend: (startDate: DateInRegion, endDate: DateInRegion)?
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

thisWeekend

Returns two DateInRegion objects indicating the start and the end of the current weekend. The object is a tuple of two DateInRegion objects indicating the start and the end of the current weekend. If this is unto a weekend, then nil is returned.

Declaration
public var thisWeekend: (startDate: DateInRegion, endDate: DateInRegion)?
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

nextWeekend

Returns two DateInRegion objects indicating the start and the end of the next weekend after the date.
Object is a tuple of two DateInRegion objects indicating the start and the end of the next weekend after the date.
The weekend returned when the receiver is in a weekend is the next weekend not the current one.

Declaration
public var nextWeekend: (startDate: DateInRegion, endDate: DateInRegion)?
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

isToday

Returns whether the given date is in today as boolean.

Declaration
public var isToday: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

isYesterday

Returns whether the given date is in yesterday as boolean.

Declaration
public var isYesterday: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

isTomorrow

Returns whether the given date is in tomorrow as boolean.

Declaration
public var isTomorrow: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

isInWeekend

Returns whether the given date is in the weekend.

Declaration
public var isInWeekend: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

isInPast

Return true if given date represent a passed date

Declaration
public var isInPast: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

isInFuture

Return true if given date represent a future date

Declaration
public var isInFuture: Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

isInSameDayOf()

Returns whether the given date is on the same day as the receiver in the time zone and calendar of the receiver.

Declaration
public func isInSameDayOf(date: DateInRegion) -> Bool
public func isInSameDayOf(date: Date) -> Bool
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

startOfDay

Return the instance representing the first moment date of the given date expressed in the context of the calendar of the receiver.

Declaration
public var startOfDay: DateInRegion
public var startOfDay: Date
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

endOfDay

Return the instance representing the last moment date of the given date expressed in the context of the calendar of the receiver.

Declaration
public var endOfDay: DateInRegion
public var endOfDay: Date
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

nextMonth

Return a new instance of the date plus one month

Declaration
public var nextMonth: DateInRegion
public var nextMonth: Date
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

prevMonth

Return a new instance of the date minus one month

Declaration
public var prevMonth: DateInRegion
public var prevMonth: Date
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

startOf()

Takes a date unit and returns a date at the start of that unit.

Declaration
public func startOf(component: Calendar.Component) -> DateInRegion
public func startOf(component: Calendar.Component) -> Date
Parameters
  • component: time unit component to use as reference
Note

This value is interpreted in the context of the calendar and timezone with which it is used; if caller is DateInRegion the context is defined by the associated .region. If the caller is a plain Date the context is defined by the value of

Date.defaultRegion

Copyright © 2016 Daniele Margutti - All right reserved