ClockData <-> TimeStamp

AmigaOS users can make feature requests in this forum.
Post Reply
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

ClockData <-> TimeStamp

Post by mritter0 »

I would like to see some new utility.library functions be added to help out in date conversions:

Code: Select all

DateStamp=ClockData2DateStamp(struct ClockData clockdata)
ClockData=DateStamp2ClockData(struct DateStamp *datestamp)
Why? Because FormatDate() uses a DateStamp only. Or add a FormatDateCD() that can convert ClockData to the same template.

Code: Select all

FormatDate(Locale,"%d-%b-%y %T",dateStamp,&putCharHook);
FormatDateCD(Locale,"%d-%b-%y %T",clockData,&putCharHook);
Workbench Explorer - A better way to browse drawers
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: ClockData <-> TimeStamp

Post by colinw »

Use the "AmigaTime" as the standard interchange data type, which is; (uint32) Seconds {since the 1st,Jan,1978}
and then convert it to and from the different structures with the appropriate library functions. ie;

The timer.device normally operates on "AmigaTime" via a struct TimeVal {uint32 Seconds; uint32 Microseconds;}
The DOS library also has; IDOS->DateStamp( struct DateStamp *ds ); Which also can return "AmigaTime". (seconds) in IoErr().

The utility library has the AmigaTime to ClockData convertor functions;
uint32 seconds = IUtility->Date2Amiga(struct ClockData *cd);
void IUtility->Amiga2Date(uint32 seconds,struct ClockData *cd);

Then you have the other DOS functions to convert between AmigaTime and DOS DateStamps;
struct DateStamp *ds = IDOS->SecondsToDateStamp( uint32 seconds, struct DateStamp *ds );
uint32 seconds = IDOS->DateStampToSeconds( struct DateStamp *ds );

You also have the date formatting function that are in DOS;
int32 success = IDOS->DateToStr( struct DateTime *datetime );
int32 success = IDOS->StrToDate( struct DateTime * datetime );

Enjoy...
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

Re: ClockData <-> TimeStamp

Post by mritter0 »

SecondsToDateStamp() was what I was missing. Thank you.
Workbench Explorer - A better way to browse drawers
Post Reply