public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/30867]  New: Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD
@ 2007-02-20  2:14 alf dot lacis at aiscientific dot com
  2007-02-20  5:54 ` [Bug preprocessor/30867] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: alf dot lacis at aiscientific dot com @ 2007-02-20  2:14 UTC (permalink / raw)
  To: gcc-bugs

Several times now in different jobs, I have come across the need for a better
__DATE__ and __TIME__, and always had to use a function such as that listed
below.

This is probably a question for the steering committee, but can I suggest the
following.

In particular, some formats which are sortable in a directory listing or table,
and some of which can be used as part of a valid file name (eg, for Windows and
Linux file systems).  I suggest the following 4 macros:

Macro:         Expands to:
__YYYY_MM_DD__  2007-02-20 also know as 'Swedish format'
__YYYYMMDD__    20070220   as above, but no delimiters, for a file name part
__HH_MM_SS__    15:51:52  24-hour format
__HHMMSS__      155152    as above, but no delimiters, for a file name part

Typical function to get a combined Swedish format date and time from the build
__DATE__ and __TIME__:


/*!
\file   swedish_build.c
\author (c) 2004-2007 Alf Lacis.

\brief  Converts the 'standard' __DATE__ and __TIME__ macros into a useful
Swedish-formatted string of the form "YYYYMMDD.HHMMSS".

\date 20040615 AGL Created from yyyymmdd.c.

***************************************************************************************************/

#include <string.h>
#include <ctype.h>
#include "alflb.h"          //  for prototypes, etc

const char *mmm[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec" };
const char *mm[]  = { "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" ,
"09" , "10" , "11" , "12"  };

//                            012345678901234....
// Converts __DATE__ string: "Feb  5 2007"
// And __TIME__ string:      "09:42:12"

// to Swedish format:        "20070205.094212"

char *swedish_build( char swedish[], size_t sizeof_swedish, char yankee_date[],
char yankee_time[] )
{
    int ii;

    if ( sizeof_swedish < SWEDISH_BUILD_SIZE )
    {
        return NULL;
    }

    strcpy( swedish, "        .      " );  // 8 spaces, dot, 6 spaces, 1
trailing '\0'
    memcpy( swedish, &yankee_date[7], 4 );
    for ( ii = 0; ii < 12; ii++ )
    {
        if ( strncmp( yankee_date, mmm[ii], 3 ) == 0 )
        {
            memcpy( &swedish[4], mm[ii], 2 );
            break;
        }
    }
    memcpy( &swedish[6], &yankee_date[4], 2 );
    memcpy( &swedish[9] , yankee_time, 2 );
    memcpy( &swedish[11], &yankee_time[3], 2 );
    memcpy( &swedish[13], &yankee_time[6], 2 );

    replace( swedish, ' ', '0' );

    return swedish;
}

// end of file: swedish_build.c


-- 
           Summary: Can we have a new __DATE__ which is sortable, eg YYYY-
                    MM-DD
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alf dot lacis at aiscientific dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30867


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug preprocessor/30867] Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD
  2007-02-20  2:14 [Bug preprocessor/30867] New: Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD alf dot lacis at aiscientific dot com
@ 2007-02-20  5:54 ` pinskia at gcc dot gnu dot org
  2007-04-25  0:22 ` tromey at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-20  5:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-02-20 05:54 -------
You should note that __DATE__ and __TIME__ are actually part of the C89 (ANSI)
and C90 (ISO) standards.

> This is probably a question for the steering committee

Really if you up to implementing it, I would say go ahead instead of saying it
up to the SC,  though note extensions are going be looked down apon so you
might want to go instead the standards route but also still implement it with
GCC since the standards committee recently likes adding stuff which has already
been implemented.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30867


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug preprocessor/30867] Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD
  2007-02-20  2:14 [Bug preprocessor/30867] New: Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD alf dot lacis at aiscientific dot com
  2007-02-20  5:54 ` [Bug preprocessor/30867] " pinskia at gcc dot gnu dot org
@ 2007-04-25  0:22 ` tromey at gcc dot gnu dot org
  2007-04-25 17:04 ` eweddington at cso dot atmel dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at gcc dot gnu dot org @ 2007-04-25  0:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tromey at gcc dot gnu dot org  2007-04-25 01:22 -------
I agree that the "swedish" (never heard it called that before) format
is superior.  But what is the use case for having this available
as a preprocessor macro?


-- 

tromey at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30867


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug preprocessor/30867] Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD
  2007-02-20  2:14 [Bug preprocessor/30867] New: Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD alf dot lacis at aiscientific dot com
  2007-02-20  5:54 ` [Bug preprocessor/30867] " pinskia at gcc dot gnu dot org
  2007-04-25  0:22 ` tromey at gcc dot gnu dot org
@ 2007-04-25 17:04 ` eweddington at cso dot atmel dot com
  2007-06-12 23:33 ` alf dot lacis at aiscientific dot com
  2008-05-23 22:54 ` andrew_dowden at softdesign dot net dot nz
  4 siblings, 0 replies; 6+ messages in thread
From: eweddington at cso dot atmel dot com @ 2007-04-25 17:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from eweddington at cso dot atmel dot com  2007-04-25 18:04 -------
Note that the YYYY-MM-DD date format is ISO standard 8601, which also includes
formats for time as well.

<http://en.wikipedia.org/wiki/ISO_8601>

Any new formats for __DATE__ and __TIME__ should probably conform to this
standard.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30867


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug preprocessor/30867] Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD
  2007-02-20  2:14 [Bug preprocessor/30867] New: Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD alf dot lacis at aiscientific dot com
                   ` (2 preceding siblings ...)
  2007-04-25 17:04 ` eweddington at cso dot atmel dot com
@ 2007-06-12 23:33 ` alf dot lacis at aiscientific dot com
  2008-05-23 22:54 ` andrew_dowden at softdesign dot net dot nz
  4 siblings, 0 replies; 6+ messages in thread
From: alf dot lacis at aiscientific dot com @ 2007-06-12 23:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from alf dot lacis at aiscientific dot com  2007-06-12 23:33 -------
I did *not* say I wanted a new format for __DATE__ & __TIME__ (reread my
request).

I wanted *new* macros.  For example:
Macro:         Expands to:
__YYYY_MM_DD__  2007-02-20 also know as 'Swedish format' (new)
__YYYYMMDD__    20070220   as above, but no delimiters (new)
__HH_MM_SS__    15:51:52  24-hour format (new, but actually same as __TIME__)
__HHMMSS__      155152    as above, but no delimiters (new)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30867


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug preprocessor/30867] Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD
  2007-02-20  2:14 [Bug preprocessor/30867] New: Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD alf dot lacis at aiscientific dot com
                   ` (3 preceding siblings ...)
  2007-06-12 23:33 ` alf dot lacis at aiscientific dot com
@ 2008-05-23 22:54 ` andrew_dowden at softdesign dot net dot nz
  4 siblings, 0 replies; 6+ messages in thread
From: andrew_dowden at softdesign dot net dot nz @ 2008-05-23 22:54 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]



------- Comment #5 from andrew_dowden at softdesign dot net dot nz  2008-05-23 22:53 -------
Strongly agree, can not change existing use/std. as relates to C89/C90 etc.

Would also suggest (as minor alternative):

  __DATEI__  date index-order, numeric, sort friendly; also US-military, etc..
    output:  yyyymmdd   eg. 20080524

  __DATEI-EN__  date index-order, non-ambiguous, English(US/GB)
    output:  yyyy-Mmm-dd   eg. 2008-May-24

  __DATEI-FR__  date index-order, non-ambiguous, Français(FR)
    output:  yyyy-Mmm-dd   eg. 2008-Mai-24

  __DATEI-DE__  date index-order, non-ambiguous, Deutsch(D)   ETC..


  __TIMEI__  time index-order, 24HR, sort friendly
    output:  hh:mm:ss   eg. 10:53:14

  __TIMEN__  time index-order, 24HR, numeric, sort friendly
    output:  hhmmss   eg. 105314


-- 

andrew_dowden at softdesign dot net dot nz changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrew_dowden at softdesign
                   |                            |dot net dot nz


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30867


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-05-23 22:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-20  2:14 [Bug preprocessor/30867] New: Can we have a new __DATE__ which is sortable, eg YYYY-MM-DD alf dot lacis at aiscientific dot com
2007-02-20  5:54 ` [Bug preprocessor/30867] " pinskia at gcc dot gnu dot org
2007-04-25  0:22 ` tromey at gcc dot gnu dot org
2007-04-25 17:04 ` eweddington at cso dot atmel dot com
2007-06-12 23:33 ` alf dot lacis at aiscientific dot com
2008-05-23 22:54 ` andrew_dowden at softdesign dot net dot nz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).