@@ -30,7 +30,7 @@ public CritVisitor(string version)
3030
3131 //OS Functions
3232 Variables [ "ReadText" ] = new Func < object ? [ ] , object ? > ( ReadText ) ;
33- // Variables["Time"] = new Func<object?[], object?>(Time);
33+ Variables [ "Time" ] = new Func < object ? [ ] , object ? > ( Time ) ;
3434
3535 //Gerenal Functions
3636 Variables [ "Convert" ] = new Func < object ? [ ] , object ? > ( ConvertTo ) ;
@@ -65,18 +65,16 @@ public CritVisitor(string version)
6565
6666 }
6767
68- //TODO FIX THIS; UPDATE SHOULD NOW BE POSSIBLE WITH THE NEW BIG NUMBERS
69- //public static object? Time(object?[] args)
70- //{
71- // if (args.Length != 0) throw new Exception("Time takes no arguments");
68+
69+ public static object ? Time ( object ? [ ] args )
70+ {
71+ if ( args . Length != 0 ) throw new Exception ( "Time takes no arguments" ) ;
72+
73+ TimeSpan t = ( DateTime . UtcNow - new DateTime ( 1970 , 1 , 1 ) ) ;
74+ double timestamp = t . TotalMilliseconds ;
75+ return Math . Round ( timestamp / 1000 , 2 ) ;
76+ }
7277
73- // //TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
74- // //double timestamp = t.TotalMilliseconds;
75- // //return Math.Round(timestamp / 1000, 2);
76- // //int m = DateTime.Now.Millisecond;
77- // return DateTime.Now;
78- //}
79-
8078 public static object ? ReadText ( object ? [ ] args )
8179 {
8280 if ( args . Length != 1 ) throw new Exception ( "ReadText expects 1 argument" ) ;
@@ -98,19 +96,19 @@ public CritVisitor(string version)
9896 throw new Exception ( "ConvertTo expects 2 arguments, first one the variable to convert to and the second one being the type." ) ;
9997
10098
101- string TypeToConvertTo = args [ 1 ] ! . ToString ( ) ! ;
99+ string typeToConvertTo = args [ 1 ] ! . ToString ( ) ! ;
102100
103101 string [ ] typeOptions = { "int" , "float" , "string" , "bool" } ;
104- if ( ! typeOptions . Contains ( TypeToConvertTo ) )
102+ if ( ! typeOptions . Contains ( typeToConvertTo ) )
105103 throw new Exception ( $ "Invalid type...\n Must be one of the following types: { string . Join ( ", " , typeOptions ) } ") ;
106104
107- object ? ValueToConvert = args [ 0 ] ! ;
105+ object ? valueToConvert = args [ 0 ] ! ;
108106
109- return ValueToConvert switch
107+ return valueToConvert switch
110108 {
111- string => Convert . ToString ( ValueToConvert ) ,
112- bool => Convert . ToBoolean ( ValueToConvert ) ,
113- _ => TypeDispatcher ( ValueToConvert )
109+ string => Convert . ToString ( valueToConvert ) ,
110+ bool => Convert . ToBoolean ( valueToConvert ) ,
111+ _ => TypeDispatcher ( valueToConvert )
114112 } ;
115113 }
116114
0 commit comments