ForwardWidgets
Widgets for Douban and Trakt watchlists plus personalized recommendations, live TV streaming including PlutoTV, Yatu raβ¦
π Breeze through Date, DateComponents, and TimeInterval with Swift!
Two Custom Structs Only (value types FTW!):
DateView: An Date associated with an CalendarCalendarComponents: Like DateComponents, but Calendar agnostic.Absolutely Zero Hardcode:
Only hardcode now is to clear the date components, by setting the value to 0 or 1. Nothing like:
minutes = seconds * 60.
Modular Composition Design:
Only one way to achieve something, instead of copy pasting code everywhere, with tons of head scratching.
You can try them in the playground shipped with the framework!
Quickly and Explicitly Access Date Components:
let someDate = Date() let currentCalendar = someDate.currentCalendar.components.year let gregorianDay = someDate.gregorian.components.day let hijriMonth = someDate.islamicCivil.components.month
Easy and Concise Date Manipulation:
let date = Date() let gregorianDate = date.gregorian // Adding components let tomorrow = gregorianDate + 1.day // Relative accessors let firstThingTomorrow = tomorrow.beginningOfDay // Easy tweaking let firstThingTomorrowButIn1984 = firstThingTomorrow.update(year: 1984) // now, lets get the date let newDate = firstThingTomorrowButIn1984.date
Convenient Date Operators:
// Just calling timeIntervalSinceDate let difference = Date(timeIntervalSinceNow: 5.minutes.timeInterval) - Date() // Just calling dateByAddingTimeInterval let afterFiftyHours = Date() + 50.hours.timeInterval // Just calling compare: let compareResult = Date(timeIntervalSinceNow: 8.hours.timeInterval) < Date()
[Bonus]: Durations
This is marked as bonus since it's not ideal at all for precise calculation, but super useful when you just need some convenience. Examples would be setting expiration intervals and estimating components from TimeInterval
// Easily access TimeInterval to construct durations let expirationInterval = 300.days.timeInterval // Convert back to a single date component let months = expirationInterval.totalMonths // 9 // Or multiple components let components = expirationInterval.components // components β CalendarComponents(day: 6, month: 9)
Add Datez to your Package.swift:
dependencies: [
.package(url: "https://github.com/SwiftKitz/Datez.git", from: "5.0.0")
]
Or add it through Xcode: File > Add Package Dependencies, then enter the repository URL.
This framework doesn't reinvent anything Apple already built. Under the hood, it leverages the Date, Calendar, and DateComponents classes to do all the work. It simply tries to simplify the API for Swift developers. Period.
After experiencing what using a great Swift API feels like, by using RealmSwift and SwiftyJSON, I started to believe in the importance of a clean and concise Swift API, and its impact on our productivity and stress levels.
What's wrong with other date libraries?
Assuming the underlying Calendar:
I needed to explicitly choose between Gregorian and IslamicCivil, so that is integrated.
Wrong Date Calculation:
Most frameworks I've seen make assumptions about the number of days in a month, or hardcode the number of hours ... etc.
Mazyod (@Mazyod)
Datez is released under the MIT license. See LICENSE for details.
more like this
Widgets for Douban and Trakt watchlists plus personalized recommendations, live TV streaming including PlutoTV, Yatu raβ¦
Comprehensive analytics dashboard for AI coding agents β Cursor, Windsurf, Claude Code, VS Code Copilot, Zed, Antigraviβ¦
Free open-source Cloudflare R2 desktop client and S3 GUI for macOS, Windows, and Linux. Manage Cloudflare R2, AWS S3, Mβ¦
search projects, people, and tags