Swiftpack.co - raymondjavaxx/CalendarDate as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by raymondjavaxx.
raymondjavaxx/CalendarDate 1.1.1
Naive date and time for Swift
⭐️ 5
🕓 1 year ago
iOS macOS tvOS
.package(url: "https://github.com/raymondjavaxx/CalendarDate.git", from: "1.1.1")

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

GitHub

link
Stars: 5
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics