www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Request: std.date should support non-US date formats

reply Don Clugston <dac nospam.com.au> writes:
Right now, all of the formats in std.date are useless to me.
Where I come from, 9/11 is the 9th of November.
But now, I'm in a non-English speaking country, and the names of
the months are different.
The format which makes the most sense internationally is YYYY-MM-DD 
hh:mm:ss, and I would recommend there be a function which returns 
"1996-05-02 02:04:57 GMT-0800".
I think this is actually what toString() should return.
This is particularly important in view of the proposal for embedded
documentation, with an option for specifying "Date:"
I'm not sure that this can be done in general without knowing the 
locale; the allowable formats would need to be restricted (and please
don't restrict them to US date formats!).

-Don.
Sep 05 2005
next sibling parent reply MicroWizard <MicroWizard_member pathlink.com> writes:
Agree.

When more choices are available, use the ANSI standard (YYYY.MM.DD)
All hungarians will be happy ... like me ;-)))

Tamas Nagy

In article <dfhro0$221q$1 digitaldaemon.com>, Don Clugston says...
Right now, all of the formats in std.date are useless to me.
Where I come from, 9/11 is the 9th of November.
But now, I'm in a non-English speaking country, and the names of
the months are different.
The format which makes the most sense internationally is YYYY-MM-DD 
hh:mm:ss, and I would recommend there be a function which returns 
"1996-05-02 02:04:57 GMT-0800".
I think this is actually what toString() should return.
This is particularly important in view of the proposal for embedded
documentation, with an option for specifying "Date:"
I'm not sure that this can be done in general without knowing the 
locale; the allowable formats would need to be restricted (and please
don't restrict them to US date formats!).

-Don.

Sep 05 2005
parent Victor Nakoryakov <nail-mail mail.ru> writes:
MicroWizard wrote:
 Agree.
 
 When more choices are available, use the ANSI standard (YYYY.MM.DD)
 All hungarians will be happy ... like me ;-)))
 
 Tamas Nagy

And russians :) -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Sep 06 2005
prev sibling next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Don Clugston wrote:
 Right now, all of the formats in std.date are useless to me.
 Where I come from, 9/11 is the 9th of November.

Yes, std.date has enough holes and warts to be getting on with. D/27490 digitalmars.D.bugs/2365 But see also my utility library http://pr.stewartsplace.org.uk/d/ which has date/time stuff. The DateValue and TimeValue types have toFormatString (currently implemented only for Windows), which generates a date/time string in the OS-defined format. (Must set Doxygen up properly so that it's documented next time!) In a future version I plan to add a format string system to it. digitalmars.D/6193 Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Sep 06 2005
prev sibling parent reply Carlos Santander <csantander619 gmail.com> writes:
Don Clugston escribió:
 Right now, all of the formats in std.date are useless to me.
 Where I come from, 9/11 is the 9th of November.
 But now, I'm in a non-English speaking country, and the names of
 the months are different.
 The format which makes the most sense internationally is YYYY-MM-DD 
 hh:mm:ss, and I would recommend there be a function which returns 
 "1996-05-02 02:04:57 GMT-0800".
 I think this is actually what toString() should return.
 This is particularly important in view of the proposal for embedded
 documentation, with an option for specifying "Date:"
 I'm not sure that this can be done in general without knowing the 
 locale; the allowable formats would need to be restricted (and please
 don't restrict them to US date formats!).
 
 -Don.
 
 
 
 
 

Regardless of what toString() returns, I still think there should be a formatDate() function that takes a date and a format string (or viceversa) so you can have the date in any format you want. -- Carlos Santander Bernal
Sep 07 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Wed, 07 Sep 2005 18:10:08 -0500, Carlos Santander  
<csantander619 gmail.com> wrote:
 Don Clugston escribió:
 Right now, all of the formats in std.date are useless to me.
 Where I come from, 9/11 is the 9th of November.
 But now, I'm in a non-English speaking country, and the names of
 the months are different.
 The format which makes the most sense internationally is YYYY-MM-DD  
 hh:mm:ss, and I would recommend there be a function which returns  
 "1996-05-02 02:04:57 GMT-0800".
 I think this is actually what toString() should return.
 This is particularly important in view of the proposal for embedded
 documentation, with an option for specifying "Date:"
 I'm not sure that this can be done in general without knowing the  
 locale; the allowable formats would need to be restricted (and please
 don't restrict them to US date formats!).
  -Don.

Regardless of what toString() returns, I still think there should be a formatDate() function that takes a date and a format string (or viceversa) so you can have the date in any format you want.

Yes. Like (probably using) strftime, eg. import std.c.time; import std.stdio; void main() { char[] res = new char[100]; time_t now = time(null); res.length = strftime(res.ptr,res.length,"%a %d %b %Y",localtime(&now)); writefln("%s",res); } Regan p.s. FYI... %a Abbreviated weekday name %A Full weekday name %b Abbreviated month name %B Full month name %c Date and time representation appropriate for locale %d Day of month as decimal number (01 - 31) %H Hour in 24-hour format (00 - 23) %I Hour in 12-hour format (01 - 12) %j Day of year as decimal number (001 - 366) %m Month as decimal number (01 - 12) %M Minute as decimal number (00 - 59) %p Current locale's A.M./P.M. indicator for 12-hour clock %S Second as decimal number (00 - 59) %U Week of year as decimal number, with Sunday as first day of week (00 - 53) %w Weekday as decimal number (0 - 6; Sunday is 0) %W Week of year as decimal number, with Monday as first day of week (00 - 53) %x Date representation for current locale %X Time representation for current locale %y Year without century, as decimal number (00 - 99) %Y Year with century, as decimal number %z Time-zone name or abbreviation; no characters if time zone is unknown %Z (as above) %% Percent sign
Sep 07 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Regan Heath wrote:
 On Wed, 07 Sep 2005 18:10:08 -0500, Carlos Santander 
 <csantander619 gmail.com> wrote:

 Regardless of what toString() returns, I still think there should be a 
 formatDate() function that takes a date and a format string (or 
 viceversa) so you can have the date in any format you want.

Yes. Like (probably using) strftime, eg.

UIMS this falls somewhat short of letting you have the date in _any_ format. For example, I don't see any ways of controlling capitalisation or leading zeros. Since I proposed a format for format strings digitalmars.D/6193 I've been working a bit on a spec, which hopefully I'll share in the near future. But to give an example of how it works, the letter 'm' is defined like this: m month number without leading 0 mm month number with leading 0 mmm abbreviated month name, lowercase Mmm abbreviated month name, initial cap MMM abbreviated month name, uppercase mmmm full month name, lowercase Mmmm full month name, initial cap MMMM full month name, uppercase Things I like about my system: - it seems more natural-looking - it's a little more logical - the letter denotes what is displayed and the length and capitalisation denote how it is displayed - it should be reasonably extensible without breaking the logic Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Sep 08 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Thu, 08 Sep 2005 10:56:24 +0100, Stewart Gordon <smjg_1998 yahoo.com>  
wrote:
 Regan Heath wrote:
 On Wed, 07 Sep 2005 18:10:08 -0500, Carlos Santander  
 <csantander619 gmail.com> wrote:

 Regardless of what toString() returns, I still think there should be a  
 formatDate() function that takes a date and a format string (or  
 viceversa) so you can have the date in any format you want.


UIMS

YAMS because I didn't post it. Here is the rest of the doc: <quote> As in the printf function, the # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows. (%#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#% ) # flag is ignored. (%#c) Long date and time representation, appropriate for current locale. For example: “Tuesday, March 14, 1995, 12:41:29”. (%#x) Long date representation, appropriate to current locale. For example: “Tuesday, March 14, 1995”. (%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y) Remove leading zeros (if any). </quote>
 this falls somewhat short of letting you have the date in _any_ format.   
 For example, I don't see any ways of controlling capitalisation or  
 leading zeros.

See above. %#d for example.
 Since I proposed a format for format strings

 digitalmars.D/6193

 I've been working a bit on a spec, which hopefully I'll share in the  
 near future.  But to give an example of how it works, the letter 'm' is  
 defined like this:

      m       month number without leading 0
      mm      month number with leading 0
      mmm     abbreviated month name, lowercase
      Mmm     abbreviated month name, initial cap
      MMM     abbreviated month name, uppercase
      mmmm    full month name, lowercase
      Mmmm    full month name, initial cap
      MMMM    full month name, uppercase

 Things I like about my system:
 - it seems more natural-looking
 - it's a little more logical - the letter denotes what is displayed and  
 the length and capitalisation denote how it is displayed
 - it should be reasonably extensible without breaking the logic

Cool. Regan
Sep 08 2005