I was wondering why the feature Int#[seconds..day,month] has been cut in two different TimeSpan?
In crystal, it’s currently impossible to write:
x = 1.month + 1.day
The performance impact of having only unified TimeSpan is very limited (store 8 more bytes per TimeSpan). And in case of “logic” issue, I think we should just add the months first in any case, before adding the days:
# now -> "29-01-2018"
time_span = 1.day + 1.month
now + time_span # -> 01-03-2018 (We add first the month, leading to 28th february then add the day.)
A month is always a month. There are no problems with adding ( or subtracting) a month from a time instance.
Ambiguity only exist when converting the time span of “1 month” to a smaller duration unit like days.
In a hilarious coincidence, I just opened PR #7454 to address this because Neo4j’s Duration type (one of its new temporal types) couldn’t map to anything in the Neo4j driver.
Neo4j’s LocalDateTime is possible due because Crystal has Time::Location.local, which is amazing, so I wanted to stick with the core library as much as possible.