Swiftpack.co - ralfebert/CalendarDate as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ralfebert.
ralfebert/CalendarDate 0.7.0
CalendarDate is a Swift type that represents a Date as year, month and day value.
⭐️ 5
🕓 2 years ago
.package(url: "https://github.com/ralfebert/CalendarDate.git", from: "0.7.0")

CalendarDate

CalendarDate is a Swift type that represents a Date as year, month and day value:

let date = CalendarDate(year: 2018, month: 5, day: 3)
let today = CalendarDate.today

Converting Foundation Date values from and to CalendarDate:

let today = CalendarDate(date: Date.now)
let date = today.date

Easy date calculations:

CalendarDate.today.adding(weeks: 3)
CalendarDate.today.adding(days: 3)

CalendarDate.today.daysTowards(date: CalendarDate.tomorrow) // returns 1

CalendarDate.tomorrow
CalendarDate.yesterday

date.isYesterday
date.isToday
date.isTomorrow

Formatting / parsing a ISO 8601 string ('yyyy-mm-dd'):

let string = date.description    // "2018-05-03"
let parsedDate = CalendarDate(string)

JSON coding:

JSONEncoder().encode(date)  // "2018-05-03"

GitHub

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

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