I often stumble over datetime strings in this format.
2014-09-26 10:20:30 +0200
Most notably MySQL and Ruby's Time class use it. I haven't yet found a good way to parse this format into a DateTime.
The function fromSimpleString will only accept date formats with abbreviated months as in `2014-Sep-26 10:20:30 +0200`, fromISOExtString OTOH requires a 'T' between the date and uses a different format for the timezone.
So it would be nice if Date.fromSimpleString accepted "2014-09-26".
Workarounds aren't really possible, e.g. because SimpleTimeZone.fromISOString isn't accessible.
Comment #1 by code — 2014-09-26T04:27:12Z
Replacing the T with a space seems to be a small deviation from ISO8601 used by some people for better readability, so the correct place for this would be fromISOExtString.
Comment #2 by issues.dlang — 2014-10-07T03:18:14Z
Honestly, I think that toSimpleString should just be gotten rid of. It was a mistake to include it. It's only there because Boost had it.
Regardless, I think that what's really needed here is either that a string like "2014-09-26 10:20:30 +0200" should be mutated to match the ISO extended format by replacing the first space with a T and removing the second space, or it should be solved with custom date-time formatting functionality, which std.datetime really should have but which I haven't gotten to yet. I do not think that it makes sense to make any of the from*String functions lax in what they accept. I think that that sort of thing is almost always a bad idea. I think that the from*String functions should only accept what their corresponding to*String functions emit, which is what is standard. The only exception is that the number of decimal places in the fractional seconds isn't fixed, because the standard doesn't specify that. Everything else is exactly the same on both sides.
Comment #3 by code — 2014-10-21T17:37:14Z
(In reply to Jonathan M Davis from comment #2)
> it should be solved with custom date-time formatting functionality, which
> std.datetime really should have but which I haven't gotten to yet.
Yeah, custom parsing seems the way to go here.
Comment #4 by code — 2014-10-22T13:57:57Z
Renamed the enhancement request.
For all the common types DateTime, TimeOfDay, Date, SysTime there should be parse and format functions that accept custom format strings.
It would make sense to use a syntax similar to strftime and strptime and also have a look at other programming languages.
If it can be used for optimization then format strings as template argument might make sense. If well done those could even replace the hand-written from*String/to*String methods.
Is there a specific reason that SimpleTimeZone.fromISOString isn't public?
Comment #5 by issues.dlang — 2014-10-22T16:57:29Z
(In reply to Martin Nowak from comment #4)
> Is there a specific reason that SimpleTimeZone.fromISOString isn't public?
It was never designed to be public. It's just a helper function for the from*String functions on SysTime. There's nothing on any of the TimeZone classes for converting to or from strings.
Though that reminds me... I need to create a bug report and fix how to/fromISOString deal with time zones, because they're dealt with exactly the same way that the to/fromISOExtString deals with them (including the : between the hours and minutes), and I'm pretty sure that that's not legit for non-extended ISO (though I need to verify that).
Comment #6 by dlang-bugzilla — 2017-06-26T12:40:21Z
*** Issue 17558 has been marked as a duplicate of this issue. ***
Comment #7 by robert.schadek — 2024-12-01T16:22:28Z