Sys() function
Posted: Mon Apr 26, 2021 2:54 pm
There are many informations available. As a starting point i added the settings 1, 2, 3 , 10 and 11.
regards
Karl-Heinz
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