Intuitive NSDate extensions in Swift
let now = NSDate()
let nextWeek = now + 1.week
let dayAfterTomorrow = now + 2.days
// shortcuts #1
let today = NSDate.today()
let tomorrow = NSDate.tomorrow()
let yesterday = NSDate.yesterday()
// shortcuts #2
let dayBeforeYesterday = 2.days.ago
let tokyoOlympicYear = 5.years.later
let birthday = NSDate.date(year: 1987, month: 6, day: 2)
let firstCommitDate = NSDate.date(year: 2014, month: 8, day: 15, hour: 20, minute: 25, second: 43)
let now = NSDate()
let christmas = now.change(month: 12, day: 25)
let thisSunday = now.change(weekday: 1)
// shortcuts
let newYearDay = now.beginningOfYear
let timeLimit = now.endOfHour
5.minutes.later.stringFromFormat("yyyy-MM-dd HH:mm:SS")
//=> "2015-03-01 12:05:00"
"1987-06-02".dateFromFormat("yyyy-MM-dd")
//=> NSDate.date(year: 1987, month: 6, day: 2)
if (lastCommitDate > 1.week.ago) {
// ...
}
if (now - lastLoginDate > 1.month) {
// ...
}
Timepiece is available through CocoaPods, to install it simply add the following line to your Podfile:
platform :ios, "8.0"
pod "Timepiece"
- Fork
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
Timepiece is available under the MIT license. See the LICENSE file for more info.