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

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).