SkillAgentSearch skills...

SwiftDateTimeExtensions

Rails-style date/time arithmetics in Swift

Install / Use

/learn @schluete/SwiftDateTimeExtensions
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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)")
View on GitHub
GitHub Stars23
CategoryDevelopment
Updated4y ago
Forks6

Languages

Swift

Security Score

60/100

Audited on Sep 26, 2021

No findings