On Tue, 03 Jun 2014 19:39:14 +0200
Robert Schadek via Digitalmars-d-learn
<digitalmars-d-learn@puremagic.com> wrote:

> On 06/03/2014 07:12 PM, Jonathan M Davis via Digitalmars-d-learn
> wrote:
> > On Tue, 03 Jun 2014 17:07:02 +0200
> > Robert Schadek via Digitalmars-d-learn
> > <digitalmars-d-learn@puremagic.com> wrote:
> >
> >> Is there a function in phobos that lets me do something like
> >> DateTime.format("MM:DD:YYYY ....") with a DateTime instance?
> > Not currently. It's on my todo list. I intend to get back to it
> > after I've finished with splitting std.datetime (which I should get
> > to fairly soon but have been doing some cleanup in std.datetime
> > first), but I don't know when it will actually be ready. So, for
> > now, you'd have to use std.string.format and the getters on
> > DateTime.
> >
> > - Jonathan M Davis
> Ok, I had people asking me for this because of my std.logger default
> output format.
>
> Do you accept PRs for that?

Well, I would prefer to do it myself, but I obviously can't say that I
wouldn't accept it if someone else did it and did a good job of it. The main
problem however is that we need to come up with a good formatting scheme -
that is the format of the custom time strings. What C has doesn't cut it, and
what I proposed a while back turned out to be too complicated.  There's this
3rd party library which had some interesting ideas:

http://pr.stewartsplace.org.uk/d/sutil/doc/datetimeformat.html

but I'm convinced that what's there is too simplistic. I'll need to dig up my
old proposal and look at how I can simplify it (possibly making it more like
what's at that link) without removing too much power from it.

Once I have the custom time format strings sorted out, I intend to create both
functions which take the format string as a runtime argument and those which
take them as compile-time arguments and their corresponding "from" functions
as well (e.g. toCustomString and fromCustomString). We'll end up with
functions for SysTime, DateTime, Date, and TimeOfDay (possibly by templatizing
functions or creating specifically named functions for each of them). My
intention is to put them in std.datetime.format once std.datetime has been
split (and they've been implemented) rather than sticking them on the types
directly.

I'll probably also look at adding a way to get at the exact pieces of
information you want efficiently without having to have flags for everything
in the custom time format strings, making it easier to create strings that are
more exotic but still do so without having to call all of the individual
getters (which isn't necessarily efficient). But by doing something like that
I should be able to simplify the custom time format strings somewhat and avoid
some of the more complicated constructs that I had in my previous proposal.

- Jonathan M Davis

Reply via email to