Giter VIP home page Giter VIP logo

swiftdate's Introduction

SwiftDate

Carthage compatible CI Status Version License Platform

Welcome to SwiftDate 3 a Date Management Library for Apple's platforms: the goal of this project is to allow developers to manage easily dates operation and timezones conversions in Swift. SwiftDate allows you to:

  • Perform calculations with dates: aDate + 2.weeks + 1.hours or (1.years - 2.hours + 16.minutes).fromNow()
  • Compare dates with math operators <,>,==,<=,>=. For example you can do aDate1 >= aDate2 or aDate1.inTimeRange("15:20","20:20")
  • Easily get time components. E.g. aDateInRegion.day or hour, minutes etc.
  • Easy/optimized way to get and transform a date from and to strings (with relative date supports* like '2 hours, 5 minutes' etc.)
  • Easy conversions to and from timezone, locale and calendar. Use helper class DateInRegion and perform conversions with components and operations!
  • Many shortcuts to get intervals and common dates (isYesterday,isTomorrow...)
  • Compatible with Swift 2.0+ and iOS/Mac/WatchOS/tvOS platforms
  • ... many many other shiny things!

What is NSDate really?

NSDate is the central class of the date/time handling in Foundation framework. It encapsulates a moment in time that is internally stored as the number of seconds since Jan 1, 2001 at 00:00 UTC. It is universal as such that it is the same moment everywhere around the world and beyond (we do not have star date yet ;-) ). We call it 'absolute time'.

See absolute time as the moment that someone in the USA has a telephone conversation with someone in Dubai. Both have that conversation at the same moment (absolute time) but the local time will be different due to time zones, different calendars, different alphabets and/or different date notation methods. You need helper classes like NSCalendar to represent an NSDate object and perform calculations on it.

This important concept is the root of several problems for programmers when dealing with time conversions across time zones, calendars and locales in Cocoa. Here SwiftDate comes to the rescue.

It is time for SwiftDate

SwiftDate introduces the concepts of DateRegion and DateInRegion. The former contains everything to represent a moment in time in the calendar, time zone and locale of the region specified. The latter is a combination of an absolute time (NSDate) with a DateRegion object. See it as an object that encapsulates a moment in time in a certain region.

In SwiftDate you can work with date components both for DateInRegion and NSDate. When you work with NSDate you are working with an absolute time and components are evaluated against your local region. When you work with the DateInRegion class then all methods and properties are represented with a region that you can specify.

Reference documentation

Author

This library was created by Daniele Margutti with contribution of Jeroen Houtzager. Any help is welcome; feel free to post your issue or pull request, in the spirit of open source software.

Older Versions

SwiftDate 1.2 branch last revision is available here. This version is unsupported.

swiftdate's People

Contributors

akuraru avatar bitomule avatar caubert avatar fhisa avatar fjohn666 avatar hout avatar jairobjunior avatar jakecraige avatar jondwillis avatar knao124 avatar malcommac avatar marknorgren avatar maximusmccann avatar mrichtsfeld avatar nebulafox avatar pettomartino avatar simonrice avatar stormxx avatar toriaezunama avatar ya-s-u avatar

Watchers

 avatar

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.