Date

extension Date
  • Create a new string using this date.

    Declaration

    Swift

    public func string(_ pattern: DateFormatPattern) -> String

    Parameters

    pattern

    the date pattern

    Return Value

    A new string formatted

  • Create a new date setting hour, minute, and second to 0

    Declaration

    Swift

    public func startOfDay(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    the beginning of the date

  • Create a new date setting hour to 23, minute to 59, and second to 59

    Declaration

    Swift

    public func endOfDay(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    the ending of the date

  • Create a new date with yesterday values.

    Declaration

    Swift

    public func yesterday(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a yesterday date

  • Create a new date with tomorrow values.

    Declaration

    Swift

    public func tomorrow(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a tomorrow date

  • Create a new first date of this month

    Declaration

    Swift

    public func firstDayOfMonth(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a first date of this month

  • Create a new last date of this month

    Declaration

    Swift

    public func lastDayOfMonth(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a last date of this month

  • Create a new date with next month values

    Declaration

    Swift

    public func nextMonth(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a next month date

  • Create a new date with previous month values

    Declaration

    Swift

    public func previousMonth(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a previous month date

  • Number of days between this and another date, no matter what the order.

    Declaration

    Swift

    public func numberOfDays(to date: Date, calendar: Calendar = Calendar.current) -> Int

    Parameters

    date

    the other date.

    calendar

    the calendar.

    Return Value

    the number of days.

  • Check if this date is today.

    Declaration

    Swift

    public func isToday(calendar: Calendar = Calendar.current) -> Bool

    Parameters

    calendar

    a calendar

    Return Value

    true iff this date is today, otherwise false

  • Check if this date is equal to other date.

    Declaration

    Swift

    public func isEqual(to date: Date, granularity: Calendar.Component, calendar: Calendar = Calendar.current) -> Bool

    Parameters

    date

    the other date.

    granularity

    the granularity.

    calendar

    the calendar.

  • Check if this date is less than other date.

    Declaration

    Swift

    public func isLess(than date: Date, granularity: Calendar.Component, calendar: Calendar = Calendar.current) -> Bool

    Parameters

    date

    the other date.

    granularity

    the granularity.

    calendar

    the calendar.

  • Check if this date is less than or equal to other date.

    Declaration

    Swift

    public func isLess(thanOrEqual date: Date, granularity: Calendar.Component, calendar: Calendar = Calendar.current) -> Bool

    Parameters

    date

    the other date.

    granularity

    the granularity.

    calendar

    the calendar.

  • Check if this date is greater than other date.

    Declaration

    Swift

    public func isGreater(than date: Date, granularity: Calendar.Component, calendar: Calendar = Calendar.current) -> Bool

    Parameters

    date

    the other date.

    granularity

    the granularity.

    calendar

    the calendar.

  • Check if this date is greater than or equal to other date.

    Declaration

    Swift

    public func isGreater(thanOrEqual date: Date, granularity: Calendar.Component, calendar: Calendar = Calendar.current) -> Bool

    Parameters

    date

    the other date.

    granularity

    the granularity.

    calendar

    the calendar.

Renamed

  • Create a new date setting hour, minute, and second to 0

    Declaration

    Swift

    @available(*, renamed: "startOfDay(calendar:﹚", message: "This function will be removed in future release.")
    public func startDay(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    the beginning of the date

  • Create a new last date of this month

    Declaration

    Swift

    @available(*, renamed: "lastDayOfMonth(calendar:﹚", message: "This function will be removed in future release.")
    public func endDayMonth(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a last date of this month

  • Create a new first date of this month

    Declaration

    Swift

    @available(*, renamed: "firstDayOfMonth(calendar:﹚", message: "This function will be removed in future release.")
    public func startDayMonth(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    a first date of this month

  • Create a new date setting hour to 23, minute to 59, and second to 59

    Declaration

    Swift

    @available(*, renamed: "endOfDay(calendar:﹚", message: "This function will be removed in future release.")
    public func endDay(calendar: Calendar = Calendar.current) -> Date

    Parameters

    calendar

    a calendar

    Return Value

    the ending of the date

  • Calculate difference between dates and return a string containing human readable time ago.

    Declaration

    Swift

    public func timeAgo(
        since date: Date = Date(),
        calendar: Calendar = Calendar.current,
        preferredLanguages: [String]? = nil
    ) -> String

    Parameters

    date

    the other date.

    calendar

    the calendar.

    Return Value

    a string for time ago.