Hello everyone,
I'd like to share a package I've been working on called DayType.
The problem DayType solves
Swift's Date APIs are great, but they are also limited by their focus on representing points in time. This means that when you want to work with just a calendar date such as someone’s birthday, a deadline or a booking for an event - you're often having to sanitise time components, manage time zones and perform a variety of related functions in case something drifts across a midnight boundary.
DayType solves this by providing a Day type to represent a calendar date, and nothing else. No time components, timezone or calendars. No stripping time, start of day, midnight or other manipulations and validations needed.
Just dates.
For example:
let birthday = try Day(1985, 8, 29)
let today = Day.today
let daysUntil = birthday - today
let buyPresentDate = birthday - 2
for day in today ... birthday {
// iterate every day in a range
}
Plus:
-
Calendar grid generation for building calendar UIs.
-
Codable property wrappers covering a variety of common server date formats. (
@Epoch.Seconds,@ISO8601.Default,@DayString.DMY, etc.) -
Common protocol conformance to
Comparable,HashableandStrideable. -
SwiftData support (with a documented workaround for a current SwiftData limitation).
-
A SwiftUI calendar picker capable of selecting both singular dates and date ranges.
Feedback and questions welcome!