timer device problem with GetSysTime()

7 posts / 0 new
Last post
walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
timer device problem with GetSysTime()

I don't know if you had the same issue before, but I am using GetSysTime() to get the system date, and more specifically, the seconds number. This returns a 10 digit timestamp of the current date, or at least it should return that.

What I get is the right day, month and hour of the moment I run it, but minus 8 years. Of' course, the time on my system is synced and shows the right date, bit the GetSysTime() keeps giving a wrong year.

I use it at the following method:

  1. STRPTR now(void)
  2. {
  3. uint8 timestampLen = 12;
  4. STRPTR buf = IExec->AllocVecTags(sizeof(char) * timestampLen,
  5. AVT_Type, MEMF_SHARED,
  6. AVT_ClearWithValue, "\0",
  7. TAG_DONE);
  8. struct TimeVal tv;
  9.  
  10. ITimer->GetSysTime(&tv);
  11. IUtility->SNPrintf(buf, sizeof(char) * timestampLen, "%lu", tv.Seconds);
  12.  
  13. return buf;
  14. }

And below you can see how I initiate and open the timer device

  1. TimerMP = IExec->AllocSysObject(ASOT_PORT, NULL);
  2. if (TimerMP != NULL)
  3. {
  4. TimeReq = IExec->AllocSysObjectTags(ASOT_IOREQUEST,
  5. ASOIOR_Size, sizeof(struct TimeRequest),
  6. ASOIOR_ReplyPort, TimerMP,
  7. TAG_END);
  8.  
  9. if (TimeReq != NULL)
  10. {
  11. if (!IExec->OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)TimeReq, 0))
  12. {
  13. if ((TTimerBase = (struct Library *)TimeReq->Request.io_Device))
  14. {
  15. ITimer = (struct TimerIFace *)IExec->GetInterface(TTimerBase, "main", 1, NULL);
  16. if(!ITimer) return CleanExit("Can't open timer device Interface");
  17. }
  18. else return CleanExit("Can't open timer device");
  19. }
  20. }
  21. else return CleanExit("Can't open timer device. Timer request failed.");
  22. }
  23. else return CleanExit("Can't open timer device. Timer msgport failed.");

The system I am running it is an X5000/40 with latest AmigaOS 4.1 FEupd2.

Any idea why this is happening and how I can overcome that? Should I use some other function to get the right time?

TSK
TSK's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-06-28 02:06
Re: timer device problem with GetSysTime()

I use DOS librarys DateStamp() function to get the date. I'm using GetSysTime only when I'm counting short time periods between two events.

walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Re: timer device problem with GetSysTime()

@TSK
Thank you for your reply. To be honest I thought that DateStamp(), because it is part of DOS, would have to do with the date of a file/folder. I will check this out again.

Thank you for your help.

walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Re: timer device problem with GetSysTime()

@TSK
Tried the DateStamp(), and when I used DateStampToSecond() I got the same timestamp as with the GetSysTime().
The problem, as Andy (@broadblues) explained it to me, is that Unix epoch starts at 1/1/1970 but Amiga epoch starts at 1/1/1978, and that's the difference. So I had to add that difference to the system timestamp, which is calculated by (365 * 8 + 2(leapyears)) * 24 * 60 * 60.

And that's how I fixed the issue I had.

cwenzel
cwenzel's picture
Offline
Last seen: 5 months 4 days ago
Joined: 2021-01-12 07:05
Re: timer device problem with GetSysTime()

If you are using any DOS version past 53.31 (8/2009) then the seconds value is available
as a secondary result from IoErr() and you don't need to supply a datestamp parameter or
convert it back to "AmigaTime".

IDOS->DateStamp(0);
seconds = IDOS->IoErr();

walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Re: timer device problem with GetSysTime()

@cwenzel
Oh, I didn't have a clue you can get it that way. What happens on newer versions of DOS?
I will have a look on that as well.

Thank you

cwenzel
cwenzel's picture
Offline
Last seen: 5 months 4 days ago
Joined: 2021-01-12 07:05
Re: timer device problem with GetSysTime()

Newer versions continue to have the same functionality.
Result2 (ie; IoErr()) was frequently used to return a second result, not just for error codes.

Secondary returncodes for some functions have existed way back to the 68K days.
I had to make sure these were also correct when I rewrote DOS library.
Quite often, a secondary returncode wasn't even documented, I only found out about it when stuff started crashing and re-discovered it after revisiting the original ASM code to see what was different from my new C-version.

Sometimes I only had to update the documentation to mention argument and returncode quirks, sometimes I needed some additional functionality internally or elsewhere, but it didn't warrant adding a new function to the API just for that, this one is in that catagory.

Log in or register to post comments