Conversation
Hello Guillaume, |
|
The crux of the discussion is the following: should we go the python way and keep dates that always have timezone info, albeit often an implicit one (usually the timezone of your computer) or should we go the rust/jiff way and separate between datetime without a timezone and datetime with a timezone. First solution has less friction but more potential footguns, second one has no footguns but more friction. For now I think I will distinguish types internally, but keep solution one which is current solution. Any opinion about this? |
be65684 to
1d43918
Compare
|
Let's first all agree that proper time handling is really hard ! If I followed your question correctly Guillaume, I would argue I'd lean more in the jiff logic than the python one. Implicit behaviour with time only leads to hard to spot/reproduce issues Rationale: I would thus argue that a "simple variant" is perfectly valid in case no TZ is present, but ideally, xan would need to be able to be super accurate if provided with all the needed information. It would be perfectly acceptable for xan to refuse to bridge the no-TZ / with-TZ divide, unless it would be somehow possible in the api to explictely provide a timezone for TZ-less data. To illustrate
Not sure if all of the above is clear :-) |
8d639a3 to
99422cd
Compare
|
Just a note on the PR proposed by @solesby . When I was testing the returns 130.04166666666666 instead of the plain 130 I was expecting. Without deep diving in the code I suspect it has to do with the math done by jiff operating on more granular units that "days" and some daylight saving kicking in during that period. |
|
I agree with @mvanleeu on both comments. I think the key is to keep it very easy to use on command line without being "wrong". Dates will generally be timezone naive, or have timezones. Operating on columns where there is a mismatch should throw exception. When/if necessary, the default timezone should be UTC so that a command/script will always behave the same on any machine. There should be an optional parameter to set/override this default for naive dates, e.g.
While I wouldn't oppose, additional functions for more precise or granular time math, I would keep them as additional functions or with defaults so that the basic "about how long was that" is easy without reading documentation. The naive result of Balancing ease vs precision might be simply splitting API into simple functions like |
Add basic date functions to moonblade. This enables doing things like:
now()— returns the current date/timedate_add( dt, span )— return thedtplus the timespandate_sub( dt, span )— return thedtminus the timespandays( dt1, dt2 )— return the number of days between the two dates (positive ifdt1is beforedt2)A
spanis an ISO 8601 format, e.g."P5DT8H1M"or friendly format, e.g."10 days". See more in Span documentation