Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

TimAEllis/SwiftDateTimeExtensions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rails-style date/time arithmetics in Swift

Admit it, you've always been jealous of you friend the Rails developer being able to write nice, readable date operations like these:

some_future_date = 4.months.from_now
the_past = (2.days + 3.years).ago

Well, with Swift you can now have those in your iOS app as well! We can simply extent the Int data type with some computed properties to convert the values into NSDateComponents. Then let's also add operator functions for addition and subtraction working with two NSDateComponents and we can write lines like these, too:

println("now:                   \(NSDate.date())")
println("8 days later:          \(8.days.fromNow)")
println("2 weeks before:        \(2.weeks.ago)")
println("5 days, 3 month later: \((5.days + 3.months).fromNow)")

About

Rails-style date/time arithmetics in Swift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%