Skip to content

Latest commit

History

History
167 lines (115 loc) 路 1.91 KB

File metadata and controls

167 lines (115 loc) 路 1.91 KB

EXTENSION

Date

public extension Date

Properties

year

var year: Int

Returns the year from the date.

month

var month: Int

Returns month as Int starting from 1...12.

week

var week: Int

Returns week as Int starting from 1...52

weekday

var weekday: Int

weekOfMonth

var weekOfMonth: Int

day

var day: Int

hour

var hour: Int

minute

var minute: Int

second

var second: Int

nanos

var nanos: Int

yesterday

var yesterday: Date

today

var today: Date

tomorrow

var tomorrow: Date

dayAfter

var dayAfter: Date

dayBefore

var dayBefore: Date

isLastDayOfMonth

var isLastDayOfMonth: Bool

startOfDay

var startOfDay: Date

Start of current day

endOfDay

var endOfDay: Date

End of current day

Methods

adjust(_:offset:)

func adjust(_ type: Calendar.Component, offset: Int) -> Date

Offset component by amount

  • Parameters:
    • type: Component
    • offset: Offset to add
  • Returns: Date

Parameters

Name Description
type Component
offset Offset to add

toRelativeFormat(currentDate:numericDates:)

func toRelativeFormat(
    currentDate: Date = Date(),
    numericDates: Bool = true
) -> String

Get relative String back from Date ex: 1 year ago, 1 month ago ...

  • Parameters:
    • currentDate: Current Date
    • numericDates: Display the numeric value in string ex: 1 year ago vs Last year
  • Returns: String

Parameters

Name Description
currentDate Current Date
numericDates Display the numeric value in string ex: 1 year ago vs Last year