DateStamp ISO format

AmigaOS users can make feature requests in this forum.
Post Reply
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

DateStamp ISO format

Post by JosDuchIt »

According to SDK:Include/include_h/dos/datetime.h dos recognizes the following formats
#define FORMAT_DOS 0 / * dd-mmm-yy * /
#define FORMAT_INT 1 / * yy-mmm-dd * /
#define FORMAT_USA 2 / * mm-dd-yy * /
#define FORMAT_CDN 3 / * dd-mm-yy * /
#define FORMAT_DEF 4 / * use default format, as defined
#define FORMAT_ISO 5 / * yyyy-mm-dd (ISO 8601)
Requires locale V48 or dos V50.36
if locale not available * /


I added the recognition of those formats in Gui4cli OS4 version

The result is not conform with this specification for the ISo format
eg

2006-12-9 guis:Docs/Tutorials/LVStyles.gc
2014-11-27 guic:Template.gc
2010-6-4 dir:Keyscreen.gc
2014-11-12 guic:/Tools/Config.gc
2014-8-6 guic:Rexxgui.gc
2014-11-27 guic:/Gui4Cli.prefs

is a selection of files to which their date was added in front using a simple Gui4Cli script

sorting them puts
2014-11-27 guic:/Gui4Cli.prefs
2014-8-6 guic:Rexxgui.gc

Can this be improves so as to allow easy & correct sorting on date?
2014-08-06 guic:Rexxgui.gc
2014-11-27 guic:/Gui4Cli.prefs
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: DateStamp ISO format

Post by tonyw »

Not sure what you are asking for here. As I understand it, you wrote the dates using gui4cli, but the result is not being sorted as you would like?

The sort does not do what you want because it is an alphabetical sort, not a numerical or date-based sort. You could get around that by formatting the data with leading zeroes in the month and day.
cheers
tony
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: DateStamp ISO format

Post by colinw »

It's difficult to decipher what exactly the problem he is describing, but I think he is using the IDOS->DateToStr() function,
even though it was not specified, it's the only string formatting function that uses a "datestamp" and has an "ISO formatting" flag.

So, with that assumption, it seems that when specifying; dat_Format = FORMAT_ISO; he is not getting the leading zero
padding for the month and day numbers as specified in the template, ie; FORMAT_ISO: (yyyy-mm-dd).

Fortunately, the DOS code is doing the right thing in the DateToStr() function using ISO format, (I just checked it),
so, this could still mean that the locale.library code that takes over the default DOS function when locale library is opened,
is not doing the padding as described, but I just happen to still have a test program I wrote.

I set the date to the 1st of february, 2014 and this is what I get from the test program;

FORMAT_DOS : Saturday 01-Feb-14 13:19:22
FORMAT_INT : Saturday 14-Feb-01 13:19:22
FORMAT_USA : Saturday 02-01-14 13:19:22
FORMAT_CDN : Saturday 01-02-14 13:19:22
FORMAT_DEF : Saturday 1/02/2014 01:19PM
FORMAT_ISO : Saturday 2014-02-01 13:19:22

Looks pretty right to me, the FORMAT_ISO is padded properly, so we will definately need more info about his problem.
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: DateStamp ISO format

Post by JosDuchIt »

@all thanks for your attention & sorry to be less clear than i should
@colinw

It is indeed the DateToStr() function that is used and does not provide the ISO strings expected

DateToStr is used by the get_time function
get-time is called to provide the resulting strings as "internal variables of Gui4Cli" as shown, either for the system time or for a file's datestamp
All works ok except for the ISO strings
The original is showed below . I am presently rewriting it , to correct the strings provided by DateToStr.
- I am adding a DateTime structure "struct gcmain *gd" , that will be used instead of "dtime" in the get_time function.
struct gcmain *gd has all the reusable stuctures that are not "gui" specific ( a gui is an indeopendent Gui4Cli script with its own window.)
The split-date function shown will give me direct access to year , month & day information & permit modification of the ISO datestring
I am not sure yet how to handle the datestrings containing char * strings .
I hope however that this can be fixed in the DateToStr function

Code: Select all

// ==========================================================
// get_time() - return success
// get the system time, date, day & store into buffers supplied 
// (which must be large enough)


// ==========================================================
/*  calls

case fDATE :              get_time(&(gd->infodat->Date), NULL, buff, NULL); 
case fTIME :              get_time(&(gd->infodat->Date), buff, NULL, NULL); 
case fDAY  :		get_time(&(gd->infodat->Date), NULL, NULL, buff);
*/

BOOL get_time( struct DateStamp *dstamp, // datestamp struct or null -we get it
					 UBYTE *time,				 // buffers:
					 UBYTE *date,				 // - for time/date/weekday strings
					 UBYTE *day)				 //	or null if not wanted
{
	struct DateStamp mydt;
	struct DateTime dtime;
	if (date) *date='\0'; 
	if (time) *time='\0';
	if (day)	 *day='\0';
	// read time ourselves if datestamp=0
	if (dstamp)  ///  DateTime has DateStamp as first item 
	else			dtime.dat_Stamp = *DateStamp (&mydt); //Get_Time(NULL, 

	// format default to prefs
	dtime.dat_Format	= gd->dateformat;	 // 0=DOS,1=INT,2=USA,3=CDN-default USA 11-26-14
	dtime.dat_Flags	= 0; //OS4W was NULL uint8  assignment makes integer from pointer without a cast
	dtime.dat_StrDate = date;	  // any of these/// buffers///  can be null
	dtime.dat_StrTime = time;
	dtime.dat_StrDay	= day;
	return ((BOOL)DateToStr(&dtime));  // return success or failure 

}


UBYTE * getlong(UBYTE *t, LONG *num)
{
	LONG wt = 1;
	UBYTE *p, *s;

	*num = 0;  p = t;

	while (*p && (*p!=':') && (*p!='.') && (*p!='-') && (*p!='/')) ++p;
	if (p == t) return (NULL); // no number

	s = &p[-1]; // last digit
	while (s >= t)
	{	 *num += (*s - '0') * wt;
		 wt *= 10;
		 --s;
	}
	if (!(*p)) return (NULL);
	return (++p);
}


 ==========================================================
//		  split a date string /// depends on date format //// called by varint.h/
// ==========================================================
void split_date(UBYTE *datestr, LONG *yr, LONG *mont, LONG *day)
{
	UBYTE *p;
	*yr = 0; *min = 0; *sec = 0;
	switch (gd->DateFormat)
	{
		case  FORMAT_USA :      /* mm-dd-yy  */
			if ((p = getlong (datestr, mont)))
			{	if ((p = getlong (p, day)))
				getlong (p, yr);
			}
			break
		case  FORMAT_CDN :		/* dd-mm-yy  */
				if ((p = getlong (datestr, day)))
			{	if ((p = getlong (mont, yr)))
				getlong (p, yr);
			}
			break
		case  FORMAT_ISO :		/* yyyy-mm-dd */
			if ((p = getlong (datestr, yr)))
			{	if ((p = getlong (p, mont)))
				getlong (p, day);
			}
			break
		case  FORMAT_INT :		/* yy-mmm-dd  char */
			break
		case  FORMAT_DOS :		 /* dd-mmm-yy  char, also yesterday? */
			break
	}

	
}



User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: DateStamp ISO format

Post by colinw »

JosDuchIt wrote:@all thanks for your attention & sorry to be less clear than i should
@colinw
It is indeed the DateToStr() function that is used and does not provide the ISO strings expected

I hope however that this can be fixed in the DateToStr function
As I have indicated, there is no problem with the DateToStr() function, I did infact test it again, just for you.

However, I did immediately see that there were at least two problems with your function and no debugging
to make sure you are getting what you were expecting...

1) "dtime.dat_Stamp" doesn't always get initialised, it will be random data if the "dstamp" argument is not NULL.
This field MUST be initialised every time.

2) Other than a switch, the "dstamp" doesn't get used at all.

3) The value going into "dtime.dat_Format = gd->dateformat;" which is a global value from "somewhere" that is
not passed as a parameter, (avoid globals where possible, explicitly pass parameters for more robust code),
there is also no debug code to make sure it has a value of FORMAT_ISO (5), if it happens to be FORMAT_DEF (4)
then it will be your default format instead and may not be padded with leading zero's.
I would recommend you hard code the value and test it again. (After you fix problem 1)

That's as far as I looked.
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: DateStamp ISO format

Post by JosDuchIt »

@Tonyw
thanks for reply &suggestions

I was able to correct the code , ISO is working ok now
Post Reply