timex icon indicating copy to clipboard operation
timex copied to clipboard

Should `set` validate the resulting date/time value?

Open maennchen opened this issue 8 years ago • 1 comments

Steps to reproduce

iex(1)> {:ok, date} = Date.new(2018, 1, 31)
{:ok, ~D[2018-01-31]}
iex(2)> Timex.set(date, month: 2)
~D[2018-02-31]

Description of issue

Expected result: ~D[2018-02-28] or at least an error.

maennchen avatar Feb 13 '18 17:02 maennchen

So set doesn't guarantee that the resulting date/time is valid, only that the value being set is valid, e.g. that a month is between 1 and 12. It is intended for use as a way to manipulate the date/time directly, but puts some responsibility on the caller to validate the results. While this could be done as an enhancement, I think I'd like to have a better idea of what the use case is before I make that change.

bitwalker avatar Apr 15 '18 19:04 bitwalker