Regarding the original topic, I don’t have a clear opinion on what’s the “correct” behavior for the DateTime
+ Nanosecond
operation; I think there are some good points on both sides, but it’s hard (for me) to reason about the potential use cases where this situation might occur or about the relative primacy of different abstract principles. I do think, nevertheless, that we should be clear about the intended use cases for the stdlib DateTime
versus the use cases where a custom format (see TimesDates.jl, AstroTime.jl) might be better suited, since the desired format for each user is different. There is no hypothetical standard DateTime object that is optimal for everyone.
For example, there are several suggestions in this thread to basically double the bit size of the DateTime format so that we gain extra precision and the original concerns are moot. That would not be a problem for most of my use cases, but I worry that we would be increasing the memory footprint and reducing the performance of “data science” use cases, where you might have one or several DateTime
fields over millions of rows. In fact, I think those use cases where you don’t have high precision requirements, but you want a baseline DateTime type to facilitate interoperability between table/dataframe packages and analysis packages, should be prioritized in the standard library.
As for “high-precision” (or “scientific”) users in the other extreme, namely space, astronomy and geophysics, it seems to me that it’s definitely better to rely on external packages that provide the domain-specific optimized format. This is not just because of number format issues, but also because at those precision regimes there are far more issues than just numeric precision. There are different time scales that advance at different rates (UT, TAI, TDB…) and the conversions between them are not trivial: either they require external data files (like the IERS tables) or a computationally heavy operation that might be truncated to different degrees according to performance/precision preferences. Thus, I think it would not be a good idea to burden the standard library with all those domain-specific choices and concerns, particularly when they might be limiting in other aspects (e.g. ability to represent dates in the past). In that sense, I would be cautious about domain-specific standards as well, unless they work
well for other contexts.
There might be some “intermediate precision” use cases as well, requiring e.g. precision at the nano-second level, where the current type falls short. Perhaps it’s a system reading a sensor at high frequency, or an oscilloscope, or something similar. Maybe it’s worth to define a stdlib HighPrecisionDateTime
for that case instead of an external type, I don’t have a strong opinion. It’s still important to highlight here that there might be “externally-sourced” issues if you want to do very precise arithmetic with DateTimes (defined in Universal Time) and real-time periods (which are only “correct” when interpreted as a difference of TAI epochs, not as a difference of UT epochs), or when handling different clock references.
Finally, regarding high-frequency trading, I’m not sure what are their requirements: surely you want accuracy, but also optimal performance? Wouldn’t that require another custom time format where you sacrifice the range of representable DateTimes instead of either?