SysTime.fromISOString

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 13 04:56:31 PDT 2017


On Sat, 2017-05-13 at 04:24 -0700, Jonathan M Davis via Digitalmars-d-
learn wrote:
> […]
> 
> YYYY-MM is still truncated and therefore only permitted if
> applications
> agree to it.

But didn't that come is as standard in the 2000 standard along with --
MM-DD for yearless date?

> > 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.

I'm still going to fight for YYYY-MM, but not to the extent of buying
the latest standard document from ISO!

> 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.

OK, we have my error, two different calls. Of course this means for a
string from the users you have to attempt a parse in one format and
then on exception try the other format. From a programmer perspective
trying to build a SysTime from user input is really awkward. Unless I
am missing a magic parse function.

> > > 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.

From the perspective of someone trying to parse "Input ISO format
string" really, really awkward. I do not want to use Vladimirs parse
since it copes with to many formats, I just want IS8601 compliant parse
(hence not using parse822Format.

You have pointed out why I was getting the error, but I think you can
accept that the tools that are there for converting strings to IS dates
need a bit of amendment to make them easy for programmers to work with.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20170513/dc839957/attachment.sig>


More information about the Digitalmars-d-learn mailing list