Implement Time.parse and Time.format in Inko
Currently Time.parse
and Time.format
use a VM instruction that in turn uses the "time" crate. Unfortunately the "time" crate has some issues that are really annoying. For example, when parsing 02-17
using the format %m-%d
the year is set to 0, which translates to 1900 (since the "time" crate starts at year 1900 and not 1970). The same goes for the day when left out, and a variety of other values. Since there is no way to detect if a value was set as a default or explicitly (e.g. when parsing 1900
with format %Y
we can't tell the difference) there's also no way to correct such cases (e.g. defaulting to the current year).
"chrono" in turn has its own issues. In particular the biggest issue is that it doesn't seem to provide a permissive parsing API. For example, it doesn't seem to support parsing of any string unless it includes the year, month, day, hour, minute, and second. In other words, as far as I could figure out it's simply impossible to parse 2018
into 2018-01-01 00:00:00
or something along those lines.
One way to work around this would be to implement Time.parse
and Time.format
in Inko itself. This would give us full control, though it would require writing non-trivial parsers/formatters. On top of that we'd also have to expose the various time structure fields (year, month, etc) directly so they can be set when constructing the resulting Time
.
Another option would be to still use VM instructions for Time.parse
and Time.format
but use our own parser written in Rust. However if I have to write a parser I'd prefer to eat my own dog food and do it in Inko.