by shellac · 11y ago · 0 comments
Has any language initially shipped with a non-broken date / time library? (See: SQL, java, python,...)
Clearly a very hard thing to get right, but post-JodaTime there a fewer excuses for APIs like:
> AddDate(y, m, d) to add a given number of years, months, days:
which pretty much defines 'deceptively simple'.
We still don't have great libraries yet, but they're coming, slowly. Chrono is pretty good.
> Chrono is pretty good.
For purposes of comparison to other libraries, here's a link to Chrono's documentation: https://lifthrasiir.github.io/rust-chrono/chrono/This honestly strikes me a very good response. Saddling a still-growing community with sub-par core datatypes is worse than their absence.
> So if "no library" counts as a "non-broken" library...
Of course if I had phrased my question in terms of the 'first shipped date / time library' then Rust still has a chance to follow this illustrious trajectory for languages (i.e. really mess up). :-)
var date = DateTime.UtcNow.AddDays(24).AddYears(-10);
In use: var billFor = 12; // months
var firstDayOfMonth = DateTime.Today
.AddDays(1 - DateTime.Today.Day);
var billDates = Enumerable.Range(billFor)
.Select(n => firstDayOfMonth.AddMonths(n));