[x] I've read, understood, and done my best to follow the Contributing guidelines before opening this issue.
I used Date.year extension to update year component of a date.
year component to be changed.
Year didn't change.
var date = Date()
print("Year before change: \(date.year)") // "Year before change: 2017"
date.year = 2010
print("Year after change: \(date.year)") // "Year after change: 2017", should be 2010
@omaralbeik Can you try date.year = 1 and let me know what the output is? 馃
Nevermind, I thought maybe we were using the wrong method. Not sure on this one
i'll look into this if that's ok
I found this stack overflow thread about it.
apparently Calendar.current.date(bySetting: .year, value: newValue, of: self) is returning nil for some reason.
@kaphacius Absolutely!, contributions are always welcome and appreciated 馃槂
it returns nil if the year is in the past for some reason. i'll use a different way of constructing a Date
@SD10, @kaphacius I think we should add tests for dates at past and future for other components as well
i'll add tests for past dates soon-ish :)
This is really strange, the apple docs for date(bySetting:value:of:) do not say anything about the case when it could return nil :(
Fun fact: this StackOverflow thread that @omaralbeik found has a link to this related issue on other GitHub repo with some alternatives to overcome this too.
Does this bug affect any other Date extensions that have a similar implementation?
Most helpful comment
i'll look into this if that's ok