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
let now = NSDate()
let cst = NSTimeZone(name: "CST")!
let dateInCST = now.beginningOfDay.change(timeZone: cst)
dateInCST.timeZone //=> CST (CDT) offset -18000 (Daylight)
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)
firstCommitDate < 1.year.ago // false
(1.year.ago...now).contains(firstCommitDate) // true
firstCommitDate > now // false
# Podfile
pod "Timepiece"
# Cartfile
github "naoty/Timepiece"
Timepiece supports tvOS at tvOS
branch. This branch will be merged to master
after Xcode 7.1 is released.
- 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.