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:
STRPTR now(void) { uint8 timestampLen = 12; STRPTR buf = IExec->AllocVecTags(sizeof(char) * timestampLen, AVT_Type, MEMF_SHARED, AVT_ClearWithValue, "\0", TAG_DONE); struct TimeVal tv; ITimer->GetSysTime(&tv); IUtility->SNPrintf(buf, sizeof(char) * timestampLen, "%lu", tv.Seconds); return buf; }
And below you can see how I initiate and open the timer device
TimerMP = IExec->AllocSysObject(ASOT_PORT, NULL); if (TimerMP != NULL) { TimeReq = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size, sizeof(struct TimeRequest), ASOIOR_ReplyPort, TimerMP, TAG_END); if (TimeReq != NULL) { if (!IExec->OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)TimeReq, 0)) { if ((TTimerBase = (struct Library *)TimeReq->Request.io_Device)) { ITimer = (struct TimerIFace *)IExec->GetInterface(TTimerBase, "main", 1, NULL); if(!ITimer) return CleanExit("Can't open timer device Interface"); } else return CleanExit("Can't open timer device"); } } else return CleanExit("Can't open timer device. Timer request failed."); } 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?
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.
@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.
@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.
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();
@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
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.