Code: Select all
FUNCTION Start( ) AS VOID
? SYS ( 1 )
? SYS ( 2 )
?
? SYS ( 3 )
? SYS ( 3 )
? SYS ( 3 )
?
? SYS ( 10 , Val(SYS(1)))
? SYS ( 11 , Date() )
RETURN
Code: Select all
FUNCTION SYS ( number AS INT , value := NIL AS USUAL ) AS USUAL
LOCAL STATIC oRandom AS System.Random
SWITCH number
CASE 1 // "C" - current system date as a Julian day number
RETURN ( (DWORD) Today() ):ToString()
CASE 2 // "N" - seconds since midnight
RETURN (INT) XSharp.Core.Functions.Seconds()
CASE 3 // "C" - Returns a legal file name that can be used to create temporary files.
IF oRandom == NULL
oRandom := System.Random{}
ENDIF
RETURN oRandom:NEXT( 10000000 , 99999999 ):ToString()
CASE 10 // "C" - String date from Julian day number
IF ! IsNumeric ( value )
THROW ArgumentException{"wrong parameter type", nameof ( value ) }
ENDIF
RETURN DToC ( (DATE) (DWORD) value )
CASE 11 // "C" - Converts a date expression or character string in date format
// to a Julian day number
IF IsNil ( value )
THROW ArgumentException{"parameter missing", nameof ( value ) }
ENDIF
IF IsDate ( value ) .OR. IsDateTime ( value )
RETURN ( (DWORD) (DATE) value ):ToString()
ELSEIF IsString ( value )
VAR d := CToD ( value )
IF CToD ( value ) == NULL_DATE
RETURN "0"
ENDIF
RETURN ((DWORD ) d ):ToString()
ELSE
THROW ArgumentException{"wrong parameter type", nameof ( value ) }
ENDIF
OTHERWISE
RETURN NIL
END SWITCH
Karl-Heinz