I have been looking for how to best calculate the date and time in Clarion.
Under normal circumstances, I would convert a date time to milliseconds, but that does not work as a LONG cannot contain the date and time of the day.
The alternative is to put it in a REAL or DECIMAL. But is it really the best way?
If I recall correctly, in clarionmag was artickle about something simillar, keeping date and time in REAL, called star time or something … you can keep date in REAL var left from the decimal point, and time in milliseconds on the right from the decimal point, ex: 70128.18000001 …
Thanks Marino
Good point with the decimal point as split.
I’ll search in the old mag’s.
Regards Niels
IIRC in ClarionMag you are looking for “StarDate” or “StarDates” by Dr Parker for the Date.Time format.
Unix Dates are “Number for Seconds since 1/1/1970”. It can and fit into a LONG for something like 20 more years, but a ULONG for something like 90 so past 2100. You could use any base date.
I guess one only has to figure out when they’re going to retire, then make their choice.
Seems like an almost daily question lately.
Hi All
Thanks for your input.
Below is what I ended up doing.
I saw how Bruce (thanks) did it in MyTable, I even stole some of his equates and variables, and made my own class to calculate back and forth.
the bottom line is that I convert the date and time to a REAL and do all the calculations there. Very simple. But it works.
Comments are very welcome.
Member()
include('dateTimeClass.inc'),ONCE
Map
End
mt:SYSTEMTIME group, type
wYear ushort
wMonth ushort
wDayOfWeek ushort
wDay ushort
wHour ushort
wMinute ushort
wSecond ushort
wMilliseconds ushort
end
msPerDay real(24 * 60 * 60 * 100)
msPerHour equate (60 * 60 * 100)
msPerMinute equate (60 * 100)
msPerSecond equate (100)
DateTimeClass.fromSysTime procedure(STRING pSystime, *Date pDate,*TIME pTime)
lSysTime GROUP(mt:SYSTEMTIME),OVER(pSystime)
END
lTime GROUP,OVER(pTime)
HS BYTE
Sec BYTE
Min BYTE
Hour BYTE
END
CODE
pDate = Date(lSysTime.wMonth,lSysTime.wDay,lSysTime.wYear)
pTime=(lSysTime.wHour*msPerHour) + (lSysTime.wMinute * msPerMinute) + (lSysTime.wSecond * msPerSecond) + lSysTime.wMilliseconds
DateTimeClass.ToSysTime procedure(*STRING pSystime, Date pDate,Time pTime)
lSysTime GROUP(mt:SYSTEMTIME),OVER(pSystime)
END
TempTime ushort
lTime GROUP,OVER(pTime)
HS BYTE
Sec BYTE
Min BYTE
Hour BYTE
END
CODE
lSysTime.wYear = YEAR(pDate)
lSysTime.wMonth = MONTH(pDate)
lSysTime.wDayOfWeek = pDate%7
lSysTime.wDay = DAY(pDate)
lSysTime.wHour = lTime.Hour
lSysTime.wMinute = lTime.Min
lSysTime.wSecond = lTime.Sec
lSysTime.wMilliseconds = lTime.HS
DateTimeClass.ToHS PROCEDURE(STRING pSystime)
lSysTime GROUP(mt:SYSTEMTIME),OVER(pSystime)
END
CODE
RETURN (DATE(lSysTime.wMonth,lSysTime.wDay,lSysTime.wYear)*msPerDay) + (lSysTime.wHour * msPerHour) + (lSysTime.wMinute * msPerMinute) + (lSysTime.wSecond * msPerSecond) + lSysTime.wMilliseconds
DateTimeClass.FromHS PROCEDURE(REAL pHS)
lSysTime GROUP(mt:SYSTEMTIME)
END
Days LONG
CODE
IF pHS
Days = INT(pHS/msPerDay)
lSysTime.wYear = YEAR(Days)
lSysTime.wMonth = MONTH(Days)
lSysTime.wDay = DAY(Days)
lSysTime.wDayOfWeek = lSysTime.wDay%7
pHS = pHS - Days * msPerDay
IF pHS
lSysTime.wHour = INT(pHS/msPerHour)
pHS = pHS - lSysTime.wHour * msPerHour
IF pHS
lSysTime.wMinute = INT(pHS / msPerMinute)
pHS = pHS - lSysTime.wMinute * msPerMinute
IF pHS
lSysTime.wSecond = INT(pHS / msPerSecond)
lSysTime.wMilliseconds = pHS - lSysTime.wSecond * msPerSecond
END
END
END
END
RETURN lSysTime
DateTimeClass.dateAdd procedure(STRING pType, LONG pQuantity, STRING pSystime)
lSysTime GROUP(mt:SYSTEMTIME),OVER(pSystime)
END
tempDateTime REAL
TempDays LONG
CODE
tempDateTime = self.ToHS(pSystime)
CASE lower(pType)
OF 'y' !Year
IF tempDateTime
TempDays = INT(tempDateTime / msPerDay)
tempDateTime = tempDateTime - (TempDays * msPerDay) + (DATE(MONTH(TempDays),DAY(TempDays),YEAR(TempDays)+pQuantity) * msPerDay)
END
OF 'm' ! Month
IF tempDateTime
TempDays = INT(tempDateTime / msPerDay)
tempDateTime = tempDateTime - (TempDays * msPerDay) + (DATE(MONTH(TempDays)+100*12+pQuantity,DAY(TempDays),YEAR(TempDays)-100) * msPerDay)
END
OF 'w' !Week (7 days)
tempDateTime = tempDateTime + (msPerDay * pQuantity * 7)
OF 'd' ! Day
tempDateTime = tempDateTime + (msPerDay * pQuantity)
OF 'h' ! Hour
tempDateTime = tempDateTime + (msPerHour * pQuantity)
OF 'm' !Minute
tempDateTime = tempDateTime + (msPerMinute * pQuantity)
OF 's' ! Second
tempDateTime = tempDateTime + (msPerSecond * pQuantity)
END
RETURN self.FromHS(tempDateTime)