Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SwiftKitz/Datez
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
https://github.com/SwiftKitz/Datez
calendar carthage cocoapods date datetime ios macos swift timeinterval tvos watchos
Last synced: 3 months ago
JSON representation
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
- Host: GitHub
- URL: https://github.com/SwiftKitz/Datez
- Owner: SwiftKitz
- License: mit
- Created: 2015-11-07T17:52:39.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-04T08:18:18.000Z (almost 4 years ago)
- Last Synced: 2024-07-03T19:45:27.716Z (4 months ago)
- Topics: calendar, carthage, cocoapods, date, datetime, ios, macos, swift, timeinterval, tvos, watchos
- Language: Swift
- Homepage: https://swiftkitz.github.io/
- Size: 12.8 MB
- Stars: 261
- Watchers: 13
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Datez - Swift library for dealing with `NSDate`, `NSCalendar`, and `NSDateComponents`. (Utility / Web View)
- awesome-swift - Datez - Library for dealing with `NSDate`, `NSCalendar`, `NSDateComponents`, and `NSTimeInterval`. (Libs / Date)
- awesome-swift - Datez - Library for dealing with `NSDate`, `NSCalendar`, `NSDateComponents`, and `NSTimeInterval`. (Libs / Date)
- awesome-ios-star - Datez - Swift library for dealing with `NSDate`, `NSCalendar`, and `NSDateComponents`. (Utility / Web View)
- fucking-awesome-swift - Datez - Library for dealing with `NSDate`, `NSCalendar`, `NSDateComponents`, and `NSTimeInterval`. (Libs / Date)
- awesome-swift-cn - Datez - Swift library for dealing with `NSDate`, `NSCalendar`, `NSDateComponents`, and `NSTimeInterval`. (Libs / Date)
- awesome-swift - Datez - Breeze through Date, DateComponents, and TimeInterval with Swift! ` 📝 7 months ago ` (Date [🔝](#readme))
README
Datez :calendar:
Breeze through Date, DateComponents, and TimeInterval## Highlights
+ __Two Custom Structs Only _(value types FTW!)_:__
- __`DateView`__: An `Date` associated with an `Calendar`
- __`CalendarComponents`__: 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.## Features
You can try them in the playground shipped with the framework!
__Quickly and Explicitly Access Date Components:__
```swift
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:__
```swift
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:__
```swift
// 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````swift
// 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)
```## Getting Started
### Swift Package Manager
```
TODO: Write me
```### CocoaPods
[CocoaPods][cocoapods-link] is fully supported. Simply add the following line to your [Podfile][podfile-docs]:
```ruby
pod 'Datez'
```### Submodule
For manual installation, you can grab the source directly or through git submodules, then simply:
+ Drop the `Datez.xcodeproj` file as a subproject (make sure `Copy resources` is __not__ enabled)
+ Navigate to your root project settings. Under "Embedded Binaries", click the "+" button and select the `Datez.framework`## Motivation
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.## Author
Mazyod ([@Mazyod](http://twitter.com/mazyod))
## License
Datez is released under the MIT license. See LICENSE for details.
[carthage-link]: https://github.com/Carthage/Carthage
[cartfile-docs]: https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile
[cocoapods-link]: https://cocoapods.org/
[podfile-docs]: https://guides.cocoapods.org/syntax/podfile.html