Re: Formatting dates in std.datetime?

2012-04-21 Thread Stewart Gordon

On 20/04/2012 21:29, H. S. Teoh wrote:

Is there a way to format std.datetime.Date objects with a custom format
string?


My utility library has a datetime module with a custom formatting facility.

http://pr.stewartsplace.org.uk/d/sutil/

The format string scheme is one of my own design, using repeated-letter format specifiers 
similar to those found in some other schemes, and designed to be logical, natural-looking, 
extensible and easy to remember.


It doesn't currently have functions to convert between its types and those in 
std.datetime, but it's straightforward to construct a DateTimeComponents from a 
std.datetime.Date structure and then call its format method, if you still want to use the 
std.datetime API and just use my library for formatting.



In particular, I'd like to reuse month short names defined in
std.datetime, but it appears that the names are private. I'd really
rather not duplicate them by hand, if there's a way to get them.

snip

My library has these arrays public.  But I agree that it was somewhat gratuitous to make 
them private in std.datetime.


Stewart.


Formatting dates in std.datetime?

2012-04-20 Thread H. S. Teoh
Is there a way to format std.datetime.Date objects with a custom format
string? In particular, I'd like to reuse month short names defined in
std.datetime, but it appears that the names are private. I'd really
rather not duplicate them by hand, if there's a way to get them.

Alternatively, if there's a date formatting function that lets you use
strftime-like format strings, that would work too.


T

-- 
Век живи - век учись. А дураком помрёшь.


Re: Formatting dates in std.datetime?

2012-04-20 Thread Jonathan M Davis
On Friday, April 20, 2012 13:29:34 H. S. Teoh wrote:
 Is there a way to format std.datetime.Date objects with a custom format
 string? In particular, I'd like to reuse month short names defined in
 std.datetime, but it appears that the names are private. I'd really
 rather not duplicate them by hand, if there's a way to get them.
 
 Alternatively, if there's a date formatting function that lets you use
 strftime-like format strings, that would work too.

Such functionality does not currently exist. It was too much to design it on 
top of everything else when std.datetime was initially put up for review. 
There was a lot to it already. There has been some discussion on how to design 
the format strings ( 
http://forum.dlang.org/thread/mailman.1806.1324525352.24802.digitalmars-
d...@puremagic.com ), but nothing has been actually added to std.datetime yet. 
My 
proposed format is very good, I think, but the examples that I chose were 
nasty enough that a number of people weren't all that happy with it. Stewart's 
proposal is more user-friendly for the basic stuff, but I don't think that it 
does as well with the more complicated stuff. I haven't decided what I'm going 
to do about it yet. It's on my TODO list.

As for the month names, they're private and will stay that way. Really, 
they're an internationalization issue, and having them in the first place was 
already debatable (they're there primarily because of toSimpleString, which 
came from Boost and they almost didn't end up in there at all).

Once the custom format string stuff has been sorted out, it will end up with a 
way to indicate that you want either the English abbreviations (which 
std.datetime currently uses) or the locale-specific ones, but that's the 
closest that you're ever going to get to have access to them without copying 
them yourself.

- Jonathan M Davis