Powerful NSDate & Time Zones Management, made in Swift 2
Clone or download
Pull request Compare This branch is 739 commits behind malcommac:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Documentation
Examples/Playground/SwiftDate.playground
Generators
Sources
XCode
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTION.md
LICENSE
README.md
SwiftDate.podspec
swiftdate-logo.png

README.md

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.