Code Monkey home page Code Monkey logo

datez's Introduction

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.

datez's People

Contributors

maryom avatar matrixsenpai avatar mazyod avatar readmecritic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datez's Issues

Design header

Every github project needs a nice header nowadays โ—

Date component counting

As in the readme, the library is missing the ability to count date components (total minutes, hours, days, ... etc)

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.