Home

Awesome

<h1 align="center"> Datez :calendar: <h6 align="center"> Breeze through Date, DateComponents, and TimeInterval </h6> </h1> <p align="center"> <img alt="Version" src="https://img.shields.io/badge/version-4.1.0-blue.svg" /> <a alt="Github CI" href="https://github.com/SwiftKitz/Datez/actions"> <img alt="Version" src="https://github.com/SwiftKitz/Datez/workflows/Swift/badge.svg" /> </a> <img alt="Swift" src="https://img.shields.io/badge/swift-5.3-orange.svg" /> <img alt="Platforms" src="https://img.shields.io/badge/platform-ios%20%7C%20osx%20%7C%20watchos%20%7C%20tvos-lightgrey.svg" /> <img src="resources/Demo.gif"> </p>

Highlights

Features

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<br /> 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)

Getting Started

Swift Package Manager

TODO: Write me

CocoaPods

CocoaPods is fully supported. Simply add the following line to your Podfile:

pod 'Datez'

Submodule

For manual installation, you can grab the source directly or through git submodules, then simply:

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:<br /> I needed to explicitly choose between Gregorian and IslamicCivil, so that is integrated.

Wrong Date Calculation:<br /> 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)

License

Datez is released under the MIT license. See LICENSE for details.