SysTime.fromISOString
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 13 04:24:48 PDT 2017
On Saturday, May 13, 2017 12:06:57 Russel Winder via Digitalmars-d-learn
wrote:
> On Sat, 2017-05-13 at 01:52 -0700, Jonathan M Davis via Digitalmars-d-
> learn wrote:
> My reading is that YYYY-MM is an allowed form: I was wrong to suggest
> YYYY was allowed.
YYYY-MM is still truncated and therefore only permitted if applications
agree to it.
> For times hh:mm is allowed as well as hh:mm:ss.
Rereading the spec, yes, HH:MM is permitted instead of HH:MM:SS, but HH is
not, and any truncation of YYYY-MM-DD is considered a truncation and
therefore only permitted if the applications involved agree to it.
So, arguably fromISOString and fromISOExtString should be changed to allow
HHMM and HH:MM respectively but not HH, YYYY-MM, YYYYMM, or YYYY.
> fromIsoString should allow for YYYYMMDDTHHMMSS and YYYY-MM-DDThh:mm:ss
> shouldn't it?
YYYYMMDDTHHMMSS is the ISO basic format, and YYYY-MM-DDTHH:MM:SS is the ISO
extended format (so, they're both from the same standard, but they're not
the same format). fromISOString handles the ISO basic format, and
fromISOExtString handles the ISO extended format.
> > Regardless, if you know that you're just dealing with a year, and
> > that's it,
> > you can just call to!int on it and pass it to the constructor of
> > SysTime,
> > DateTime, or Date (depending on which you want to use) with whatever
> > values
> > you want to set for the month, day, etc. Using a function like
> > fromISOString
> > would just be overkill if all you have is a year, even if it did
> > accept
> > truncated representations. But the truncated representations are not
> > required by the standard, so they're not supported.
>
> Indeed. However I believe the standard defines more than is accepted.
> The code:
>
> auto newDate = Date.fromISOString(date_buffer);
>
> leads to:
>
> core.time.TimeException@/usr/include/d/std/datetime.d(12932): Invalid ISO
> String: 2015-05-10
>
> I'd suggest 2015-05-10 is a perfectly good ISO8601 compliant date and
> so highlights a bug/
fromISOString is throwing, because you're giving it the extended format. For
that, you need to use fromISOExtString.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list