On Wed, Dec 21, 2011 at 8:41 PM, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
Okay. At the moment, the time point types in std.datetime have functions for
converting to and from strings of standard formats but not custom formats, so
functions for that need to be added. I've come up with a proposal for how
they're going to work and would like some feedback on it.

Originally, I was going to make them work like strftime and strptime, since it
was my understanding that those functions were fairly standard among various
programming languags. And it _does_ look like a variety of programming
languages have something similar (Java, Ruby, Python, etc.), but the exact set
of flags that they use is not standard, so there _isn't_ really a standard to
follow, just similar functions across a variety of programming languages. And
honestly, strftime and strptime aren't very good. They're fairly limited IMHO,
and the choice of flags is fairly arbitrary, so it seems like a good idea to
design our own, assuming that we can make something better.

Stewart Gordon has a library that takes a different approach (
http://pr.stewartsplace.org.uk/d/sutil/datetime_format.html ). It does away
with % flags and uses maximul munch with each of the flags being name such that
they don't overlap in a way that would make certain combinations of flags
impossible. It then requires that characters which are not part of the flags be
surrounded by single quotes. It's an interesting approach, but it isn't as
flexible as it could be because of its use of maximul munch instead of % flags.

So, I've come up with something new which tries to take the best of both. On
the whole, I think that it's fairly straightforward, and the flags are
generally recognizable and memorable (though there are a lot). It's also
definitely extremely flexible (e.g. you can pass it functions to generate
portions of the string if the existing flags don't get you quite what you
need). But I'd like some feedback on it before I spend a lot of time on the
implementation.

This page has the docs for std.datetime with everything else but the proposed
custom formatting functions for SysTime stripped out of it:

http://jmdavis.github.com/d-programming-language.org/std_datetime.html

So, what do you think?

- Jonathan M Davis


I must admit, I was scared by the first couple of examples on that page.  It looks like the the general use case is more approachable though.  I've never been much of a fan of strftime as I have to look up the syntax every time I use it (despite writing date scheduling software for a living) and it's difficult to look up because most languages use that name but often have variants to the flags (as you've said) and they all show up in a google search.  That said, it works and I wouldn't be upset if D ended up using it.

Personally, I don't know that phobos needs a highly advanced data formatting syntax built in. I kind of lean toward as simple of syntax as we can get that covers 99% of what people need and maybe have something like this offered as an third-party library for people who need its advanced features. I do think Stewart Gordon's approach is a good fit for this requirement.

In any case, I like how much thought you've put into this.

Regards,
Brad