I'm using a package call DateToolsSwift. Now, whenever I want to add a day to a Date object, I would do like this
let date = Date().add(TimeChunk(seconds: 0, minutes: 0, hours: 0, days: 3, weeks: 0, months: 0, years: 0))
This code is too long and it does't feel right. So my question is, is this the way to do it in DateToolsSwift? Or I'm doing it wrong?
The DateToolsSwift package defines extension methods in Integer+DateTools.swift which allow the simple creation of
TimeChunk
s, e.g. 3.days
or 2.weeks
. Therefore you can do
let date = Date().add(3.days)
or, since DateToolsSwift also defines a custom +
operator,
let date = Date() + 3.days