/* _Last-change.p
* 10/06/2006 Dmitri
*/
DEFINE VARIABLE dtDate AS DATE NO-UNDO.
DEFINE VARIABLE iTime AS INTEGER NO-UNDO.
DEFINE VARIABLE iMillis AS INTEGER NO-UNDO.
for each _file where not _hidden no-lock
by _File._Last-change desc:
RUN convertUnixTimestamp
(INPUT _File._Last-change,
OUTPUT dtDate,
OUTPUT iTime).
display _file-name dtDate STRING(iTime, "HH:MM:SS") "UTC":U.
end.
PROCEDURE convertUnixTimestamp:
DEFINE INPUT PARAMETER pdTimestamp AS DECIMAL NO-UNDO.
DEFINE OUTPUT PARAMETER pdtDate AS DATE NO-UNDO.
DEFINE OUTPUT PARAMETER piTime AS INTEGER NO-UNDO.
/* Seconds per day */
DEFINE VARIABLE iSPD AS INTEGER NO-UNDO.
/* Seconds per year */
DEFINE VARIABLE iSPY AS INTEGER NO-UNDO.
/* Variables to hold our calculation so far */
DEFINE VARIABLE iYear AS INTEGER NO-UNDO.
DEFINE VARIABLE iDay AS INTEGER NO-UNDO.
DEFINE VARIABLE iSecsLeft AS INTEGER NO-UNDO.
ASSIGN
iSPD = 60 * 60 * 24
iSPY = iSPD * 365
/* Since it is impossible to have 365 or more leap years since
** 1970 this following calculation will always work and always
** come up with a correct year.
*/
iYear = INTEGER(TRUNCATE (pdTimestamp / iSPY, 0))
/* Calculate the number of seconds that have elapsed in the
** current year so far.
*/
iSecsLeft = INTEGER(pdTimeStamp - (iYear * iSPY))
.
/* Now we have to adjust the seconds left in the current year for the number of~
Feb 29th days that have elapsed since 1970, excluding the one in the current y~
ear, which will be handled further below.
*/
/* How many leapyears since 1970? 1972 is the first one. */
IF iYear > 2 THEN DO:
DEFINE VARIABLE iLeapDays AS INTEGER NO-UNDO.
ASSIGN /* subtract 3 from year to get relative to 1973 */
/* 1973 = 1, 1977 = 2, etc. */
/* We don't include the current year in this */
iLeapDays = INTEGER(TRUNCATE((iYear - 3) / 4, 0)) + 1
iSecsLeft = iSecsLeft - (iLeapDays * iSPD).
END.
/* Now the year and seconds since the beginning of the year are accurate
*/
ASSIGN iDay = INTEGER(TRUNCATE(iSecsLeft / iSPD, 0))
/* Now the year and day are in julian format (almost). */
/* Julian would have year 2000 as "00", but we have "30". */
/* If the current year is a leap year this is handled here. */
/* DATE math allows us to add days to a date - add to Jan 1. */
pdtDate = DATE('01/01/':U + STRING(iYear + 1970)) + iDay
/* The number os seconds since midnight of the date above */
piTime = iSecsLeft - (iDay * iSPD)
.
END PROCEDURE. /* convertUnixTimestamp */