DateUnit

public struct DateUnit

DateUnit for use in adding and subtracting units from Temporal.Date, Temporal.DateTime, and Temporal.Time.

DateUnit uses Calendar.Component under the hood to ensure date oddities are accounted for.

let tomorrow = Temporal.Date.now() + .days(1)
let twoWeeksFromNow = Temporal.Date.now() + .weeks(2)
let nextYear = Temporal.Date.now() + .years(1)

let yesterday = Temporal.Date.now() - .days(1)
let sixMonthsAgo = Temporal.Date.now() - .months(6)
  • One day. Equivalent to 1 x Calendar.Component.day

    Declaration

    Swift

    public static let oneDay: DateUnit
  • One week. Equivalent to 7 x Calendar.Component.day

    Declaration

    Swift

    public static let oneWeek: DateUnit
  • One month. Equivalent to 1 x Calendar.Component.month

    Declaration

    Swift

    public static let oneMonth: DateUnit
  • One year. Equivalent to 1 x Calendar.Component.year

    Declaration

    Swift

    public static let oneYear: DateUnit
  • DateUnit amount of days. One day is 1 x Calendar.Component.day

    let fiveDays = DateUnit.days(5)
    // or
    let fiveDays: DateUnit = .days(5)
    

    Declaration

    Swift

    public static func days(_ value: Int) -> DateUnit

    Parameters

    value

    Amount of days in this DateUnit

    Return Value

    A DateUnit with the defined number of days.

  • DateUnit amount of weeks. One week is 7 x the Calendar.Component.day

    let twoWeeks = DateUnit.weeks(2)
    // or
    let twoWeeks: DateUnit = .weeks(2)
    

    Declaration

    Swift

    public static func weeks(_ value: Int) -> DateUnit

    Parameters

    value

    Amount of weeks in this DateUnit

    Return Value

    A DateUnit with the defined number of weeks.

  • DateUnit amount of months. One month is 1 x Calendar.Component.month

    let sixMonths = DateUnit.months(6)
    // or
    let sixMonths: DateUnit = .months(6)
    

    Declaration

    Swift

    public static func months(_ value: Int) -> DateUnit

    Parameters

    value

    Amount of months in this DateUnit

    Return Value

    A DateUnit with the defined number of months.

  • DateUnit amount of years. One year is 1 x Calendar.Component.year

    let oneYear = DateUnit.years(1)
    // or
    let oneYear: DateUnit = .years(1)
    

    Declaration

    Swift

    public static func years(_ value: Int) -> DateUnit

    Parameters

    value

    Amount of years in this DateUnit

    Return Value

    A DateUnit with the defined number of years.