CalendarDate 1.1.1

CalendarDate 1.1.1

Maintained by Ramon Torres.



Build

CalendarDate

Calendar dates for Swift, built around DateComponents. Provides value objects for representing dates and times that are not directly bound to specific UTC offsets or timezones. This is useful when working with future events, as in the case of event and appointment scheduling apps.

CalendarDate provides the following value types:

  • CalendarTime: Represents a wall time, such as "2:00PM".
  • CalendarDate: Represents a calendar date, such as a birthday.
  • CalendarDateTime: Groups CalendarDate and CalendarTime to represent a date + time.

How to use it

You can initialize a CalendarDateTime value directly and convert it to a Swift Date when you need to display it to the user.

let meetingDate = CalendarDateTime(year: 2020, month: 4, day: 1, hour: 10, minute: 30)
let meetingTimezone = TimeZone(identifier: "America/New_York")

let date = meetingDate.asDate(timezone: meetingTimezone!)

let formatter = DateFormatter()
formatter.dateStyle = .long
formatter.timeStyle = .long
formatter.timeZone = TimeZone(identifier: "America/New_York") // Or .current

formatter.string(from: date) // -> "April 1, 2020 at 10:30:00 AM EDT"

Codable

The value types provided by this library all conform to Codable.

Value Type Codable format
CalendarTime hh:mm:ss
CalendarDate YYYY-MM-DD
CalendarDateTime YYYY-MM-DDThh:mm:ss

Recommended reads