📆 Breeze through Date, DateComponents, and TimeInterval with Swift!

Overview

Datez 📆

Breeze through Date, DateComponents, and TimeInterval

Version Version Swift Platforms

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:

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)

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:

  • 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)

License

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

Comments
  • Added a video tutorial

    Added a video tutorial

    Salam,

    I just have a small question, in Datez there is no func to print the date as 2016-5-14 ? because I wrote in the video this func:

    func printDay(){
    
        theDay.text = "\(gregorianDate.components.year )-\(gregorianDate.components.month)-\(gregorianDate.components.day)"
    }
    

    I think it's already there in Datez but I can't find it because this is the first time I use Datez. Anyways, Datez is awesome I like it ..

    opened by Maryom 16
  • Manual Installation

    Manual Installation

    CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

    It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

    opened by lfarah 1
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    opened by ReadmeCritic 1
  • Feature: Discrete timer

    Feature: Discrete timer

    Implemented a timer that will fire for every discrete time unit. I think it's hard to describe without an example:

    let timer = DiscreteTimer(timeUnit: .minute, callback: ...)
    // callback will be triggered at the "head" of every subsequent minute starting now...
    // a date object with seconds and lower units zeroed out will also be passed in.
    // this is useful for equality checks in case you are looking to trigger something at a specific minute
    
    opened by Mazyod 0
  • update test

    update test

    Salam,

    I can't record the Gif because I can't run playground, because some files need to be updated. So I updated them in this PR. Also, I got two warnings:

    The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "DatezTests-ios" target.

    The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Datez-ios" target.

    When I tired to solve them I got error, so I will try again to solve them. I don't know how long it will take from me.

    opened by Maryom 0
Releases(v1.0.0)
  • v1.0.0(Dec 19, 2015)

    The library has been in private beta, and only made public after shipping it with my apps to the AppStore. You can rest assured it is battle tested.

    Source code(tar.gz)
    Source code(zip)
Owner
Kitz
Collection of quality Swift kits
Kitz
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Jan 3, 2023
Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects

SwiftyPick ?? ?? Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects. Purpose The idea behind t

Manu Herrera 19 May 12, 2022
A handy collection of Swift method and Tools to build project faster and more efficient.

SwifterKnife is a collection of Swift extension method and some tools that often use in develop project, with them you might build project faster and

李阳 4 Dec 29, 2022
TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.

TypeStyle TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app. Featu

Eugene Belinski 31 Dec 14, 2022
Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures

Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures. Have the best of both worlds

async_plus 132 Jan 6, 2023
A lightweight extension to Swift's CollectionDifference, supporting moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

DifferenceTracker is a lightweight extension to Swift's CollectionDifference. It defines moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

Giles Hammond 2 Nov 25, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Validate iOS, Android, and Mac localizations. Find errors in .strings, .stringsdict, and strings.xml files.

Locheck An Xcode and Android localization file validator. Make sure your .strings, .stringsdict, and strings.xml files do not have any errors! What do

Asana 73 Dec 13, 2022
Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.

SheeKit Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of UISheetPresentationController and other UIKit features. Overview She

Eugene Dudnyk 67 Dec 31, 2022
Tools and helpers to make building apps faster and safer.

The UBFoundation framework provides a set of useful tools and helpers to make building apps faster and safer.

Ubique 7 Dec 19, 2022
Paul Hudson redesigned and remastered the original MoonshotApp. And so I followed the tutorial

Moonshot App for iOS. parsing some json files, using generics, and creating multi page app. Application provides simple informations from the Apollo m

Pavel Surový 0 Dec 7, 2021
Easy CBOR encoding and decoding for iOS, macOS, tvOS and watchOS.

CBORCoding CBORCoding is a lightweight framework containing a coder pair for encoding and decoding Codable conforming types to and from CBOR document

Joe Newton 23 Nov 8, 2022
An open source Instapaper clone that features apps and extensions that use native UI Components for Mac and iOS.

TODO: Screenshot outdated Hipstapaper - iOS and Mac Reading List App A macOS, iOS, and iPadOS app written 100% in SwiftUI. Hipstapaper is an app that

Jeffrey Bergier 51 Nov 15, 2022
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

Fabrizio Brancati 992 Dec 2, 2022
💻 A fast and flexible O(n) difference algorithm framework for Swift collection.

A fast and flexible O(n) difference algorithm framework for Swift collection. The algorithm is optimized based on the Paul Heckel's algorithm. Made wi

Ryo Aoyama 3.3k Jan 4, 2023
How Swift standard types and classes were supposed to work.

How Swift standard types and classes were supposed to work. A collection of useful extensions for the Swift Standard Library, Foundation, and UIKit.

Goktug Yilmaz 3k Dec 22, 2022