'===========================================================================
' Subject: LINEAR DATE                        Date: 07-12-96 (01:22)       
'  Author: Kevin J. Krumwiede                 Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: DATETIME.ABC
'===========================================================================
' Hello everybody!  This program reports the current linear date, 
' expressed as the number of seconds since 00:00 on 01-01-1970. 
' This could be used the same way you might use TIMER to create 
' delays, but without the complications of midnight rollover. 
' This seems to be pretty fast, though I'm sure there's room for 
' optimization.  I think I corected properly for all the special  
' cases (leap years, etc.), but if you spot any errors, please 
' let me know!  Here it is: 
 
' ********************************************************************* 
' lin_date.bas 
' Written and released to the PUBLIC DOMAIN by Kevin J Krumwiede 
' Calculates the linear date from 01-01-1970 as per the Unix convention 
' ********************************************************************* 
 
DECLARE FUNCTION linearDate& () 
DECLARE FUNCTION leapDays% (year%) 
 
CLS 
PRINT "Current Linear Date:"; 
PRINT linearDate& 
 
END 
 
FUNCTION leapDays% (year%) 
 
IF (year% MOD 100 = 0) AND (year% MOD 4 <> 0) THEN 
        leapDays% = 0 
ELSEIF (year% MOD 4 = 0) THEN 
        leapDays% = 1 
ELSE 
        leapDays% = 0 
END IF 
 
END FUNCTION 
 
FUNCTION linearDate& 
 
dt$ = DATE$ 
m% = VAL(LEFT$(dt$, 2)) 
d% = VAL(MID$(dt$, 4, 2)) 
y% = VAL(RIGHT$(dt$, 4)) 
 
DIM days(1 TO 12) AS INTEGER 
days(1) = 31: days(2) = 28: days(3) = 31: days(4) = 30 
days(5) = 31: days(6) = 30: days(7) = 31: days(8) = 31 
days(9) = 30: days(10) = 31: days(11) = 30: days(12) = 31 
 
lin& = 0 
FOR i% = 1970 TO y% - 1 
        lin& = lin& + 86400 * (365 + leapDays(y%)) 
NEXT i% 
 
FOR i% = 1 TO m% - 1 
        lin& = lin& + 86400 * days(m%) 
NEXT 
IF m% > 2 THEN lin& = lin& + 86400 * leapDays(y%) 
 
lin& = lin& + 86400 * (d% - 1) 
lin& = lin& + TIMER 
 
linearDate& = lin& 
 
END FUNCTION 
