algol-things/src/mktime2.a68
2025-04-09 19:57:45 +01:00

36 lines
1.1 KiB
Plaintext

BEGIN
LONG INT days per year = 365,
days per leap year = 366,
secs per day = 24 * 3600,
secs per hour = 3600,
secs per min = 60;
[1:12] LONG INT days in month := (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
PROC to epoch secs = ([] INT t) LONG REAL:
BEGIN
LONG INT year = t[1], month = t[2], day = t[3],
hour = t[4], min = t[5], sek = t[6];
LONG INT years = year - 1970;
LONG INT leap years = years OVER 4 - years OVER 100 + years OVER 400;
LONG INT days = years * days per year + leap years;
IF year MOD 4 = 0 AND (year MOD 100 /= 0 OR year MOD 400 = 0)
THEN days in month[2] := 29
FI;
FOR m FROM 1 TO month - 1 DO
days +:= days in month[m]
OD;
days +:= day - 1;
LONG REAL total = days * secs per day + hour * secs per hour + min * secs per min + sek;
total
END;
[] INT lt = local time;
print(("array: ", lt, newline));
LONG REAL secs = to epoch secs(lt);
print(("seconds: ", secs, newline))
END