On Wed, Dec 21, 2011 at 8:41 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com">jmdavisProg@gmx.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Okay. At the moment, the time point types in std.datetime have functions for<br>
converting to and from strings of standard formats but not custom formats, so<br>
functions for that need to be added. I've come up with a proposal for how<br>
they're going to work and would like some feedback on it.<br>
<br>
Originally, I was going to make them work like strftime and strptime, since it<br>
was my understanding that those functions were fairly standard among various<br>
programming languags. And it _does_ look like a variety of programming<br>
languages have something similar (Java, Ruby, Python, etc.), but the exact set<br>
of flags that they use is not standard, so there _isn't_ really a standard to<br>
follow, just similar functions across a variety of programming languages. And<br>
honestly, strftime and strptime aren't very good. They're fairly limited IMHO,<br>
and the choice of flags is fairly arbitrary, so it seems like a good idea to<br>
design our own, assuming that we can make something better.<br>
<br>
Stewart Gordon has a library that takes a different approach (<br>
<a href="http://pr.stewartsplace.org.uk/d/sutil/datetime_format.html" target="_blank">http://pr.stewartsplace.org.uk/d/sutil/datetime_format.html</a> ). It does away<br>
with % flags and uses maximul munch with each of the flags being name such that<br>
they don't overlap in a way that would make certain combinations of flags<br>
impossible. It then requires that characters which are not part of the flags be<br>
surrounded by single quotes. It's an interesting approach, but it isn't as<br>
flexible as it could be because of its use of maximul munch instead of % flags.<br>
<br>
So, I've come up with something new which tries to take the best of both. On<br>
the whole, I think that it's fairly straightforward, and the flags are<br>
generally recognizable and memorable (though there are a lot). It's also<br>
definitely extremely flexible (e.g. you can pass it functions to generate<br>
portions of the string if the existing flags don't get you quite what you<br>
need). But I'd like some feedback on it before I spend a lot of time on the<br>
implementation.<br>
<br>
This page has the docs for std.datetime with everything else but the proposed<br>
custom formatting functions for SysTime stripped out of it:<br>
<br>
<a href="http://jmdavis.github.com/d-programming-language.org/std_datetime.html" target="_blank">http://jmdavis.github.com/d-programming-language.org/std_datetime.html</a><br>
<br>
So, what do you think?<br>
<span class="HOEnZb"><font color="#888888"><br>
- Jonathan M Davis<br>
</font></span></blockquote></div><br><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>In any case, I like how much thought you've put into this.</div><div><br></div><div>Regards,</div><div>Brad</div>