@@ -51,7 +51,7 @@ public override Operand Calculate(AlgorithmEngine work)
5151 return Operand . Create ( dt ) ;
5252 }
5353 } else if ( type == 2 ) {
54- return args [ 0 ] . ToNumber ( "Function '{0}' parameter is error!" , "DateValue" ) . ToMyDate ( ) ;
54+ return args [ 0 ] . ToNumber ( "Function '{0}' parameter is error!" , "DateValue" ) . ToMyDate ( ) ;
5555 } else if ( type == 3 ) {
5656 var args1 = args [ 0 ] . ToNumber ( "Function '{0}' parameter {1} is error!" , "DateValue" , 1 ) ;
5757 var time = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) . AddMilliseconds ( args1 . LongValue ) ;
@@ -63,35 +63,34 @@ public override Operand Calculate(AlgorithmEngine work)
6363 if ( work . UseLocalTime ) { return Operand . Create ( time . ToLocalTime ( ) ) ; }
6464 return Operand . Create ( time ) ;
6565 }
66- return Operand . Error ( "Function '{0}' parameter is error!" , "DateValue" ) ;
66+ return Operand . Error ( "Function '{0}' parameter is error!" , "DateValue" ) ;
6767 }
6868 public override void ToString ( StringBuilder stringBuilder , bool addBrackets )
6969 {
7070 AddFunction ( stringBuilder , "DateValue" ) ;
7171 }
7272 }
7373
74- internal class Function_TIMESTAMP : Function_N
74+ internal class Function_TIMESTAMP : Function_2
7575 {
76- public Function_TIMESTAMP ( FunctionBase [ ] funcs ) : base ( funcs )
76+ public Function_TIMESTAMP ( FunctionBase func1 , FunctionBase func2 ) : base ( func1 , func2 )
7777 {
7878 }
7979
8080 public override Operand Calculate ( AlgorithmEngine work )
8181 {
82- var args = new List < Operand > ( ) ;
83- foreach ( var item in funcs ) { var aa = item . Calculate ( work ) ; if ( aa . IsError ) { return aa ; } args . Add ( aa ) ; }
82+ var args0 = func1 . Calculate ( work ) ; if ( args0 . IsError ) { return args0 ; }
83+
8484 int type = 0 ; // 毫秒
85- if ( args . Count == 2 ) {
86- var args2 = args [ 1 ] . ToNumber ( "Function '{0}' parameter {1} is error!" , "TimeStamp" , 2 ) ;
87- if ( args2 . IsError ) { return args2 ; }
85+ if ( func2 != null ) {
86+ var args2 = func2 . Calculate ( work ) ; if ( args2 . Type != OperandType . NUMBER ) { args2 = args2 . ToNumber ( "Function '{0}' parameter {1} is error!" , "TimeStamp" , 2 ) ; if ( args2 . IsError ) { return args2 ; } }
8887 type = args2 . IntValue ;
8988 }
9089 DateTime args1 ;
9190 if ( work . UseLocalTime ) {
92- args1 = args [ 0 ] . ToMyDate ( "Function '{0}' parameter {1} is error!" , "TimeStamp" , 1 ) . DateValue . ToDateTime ( DateTimeKind . Local ) . ToUniversalTime ( ) ;
91+ args1 = args0 . ToMyDate ( "Function '{0}' parameter {1} is error!" , "TimeStamp" , 1 ) . DateValue . ToDateTime ( DateTimeKind . Local ) . ToUniversalTime ( ) ;
9392 } else {
94- args1 = args [ 0 ] . ToMyDate ( "Function '{0}' parameter {1} is error!" , "TimeStamp" , 1 ) . DateValue . ToDateTime ( DateTimeKind . Utc ) ;
93+ args1 = args0 . ToMyDate ( "Function '{0}' parameter {1} is error!" , "TimeStamp" , 1 ) . DateValue . ToDateTime ( DateTimeKind . Utc ) ;
9594 }
9695 if ( type == 0 ) {
9796 var ms = ( args1 - new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ) . TotalMilliseconds ;
@@ -100,7 +99,7 @@ public override Operand Calculate(AlgorithmEngine work)
10099 var s = ( args1 - new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ) . TotalSeconds ;
101100 return Operand . Create ( s ) ;
102101 }
103- return Operand . Error ( "Function '{0}' parameter is error!" , "TimeStamp" ) ;
102+ return Operand . Error ( "Function '{0}' parameter is error!" , "TimeStamp" ) ;
104103 }
105104 public override void ToString ( StringBuilder stringBuilder , bool addBrackets )
106105 {
@@ -116,12 +115,12 @@ public Function_TIMEVALUE(FunctionBase func1) : base(func1)
116115
117116 public override Operand Calculate ( AlgorithmEngine work )
118117 {
119- var args1 = func1 . Calculate ( work ) ; if ( args1 . Type != OperandType . TEXT ) { args1 = args1 . ToText ( "Function '{0}' parameter is error!" , "TimeValue" ) ; if ( args1 . IsError ) { return args1 ; } }
118+ var args1 = func1 . Calculate ( work ) ; if ( args1 . Type != OperandType . TEXT ) { args1 = args1 . ToText ( "Function '{0}' parameter is error!" , "TimeValue" ) ; if ( args1 . IsError ) { return args1 ; } }
120119
121120 if ( TimeSpan . TryParse ( args1 . TextValue , CultureInfo . InvariantCulture , out TimeSpan dt ) ) {
122121 return Operand . Create ( dt ) ;
123122 }
124- return Operand . Error ( "Function '{0}' parameter is error!" , "TimeValue" ) ;
123+ return Operand . Error ( "Function '{0}' parameter is error!" , "TimeValue" ) ;
125124 }
126125 public override void ToString ( StringBuilder stringBuilder , bool addBrackets )
127126 {
@@ -331,7 +330,7 @@ public Function_SECOND(FunctionBase func1) : base(func1)
331330 public override Operand Calculate ( AlgorithmEngine work )
332331 {
333332 var args1 = func1 . Calculate ( work ) ;
334- if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Second" ) ; if ( args1 . IsError ) { return args1 ; } }
333+ if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Second" ) ; if ( args1 . IsError ) { return args1 ; } }
335334 return Operand . Create ( args1 . DateValue . Second ) ;
336335 }
337336 public override void ToString ( StringBuilder stringBuilder , bool addBrackets )
@@ -349,7 +348,7 @@ public Function_MINUTE(FunctionBase func1) : base(func1)
349348 public override Operand Calculate ( AlgorithmEngine work )
350349 {
351350 var args1 = func1 . Calculate ( work ) ;
352- if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Minute" ) ; if ( args1 . IsError ) { return args1 ; } }
351+ if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Minute" ) ; if ( args1 . IsError ) { return args1 ; } }
353352 return Operand . Create ( args1 . DateValue . Minute ) ;
354353 }
355354 public override void ToString ( StringBuilder stringBuilder , bool addBrackets )
@@ -367,7 +366,7 @@ public Function_HOUR(FunctionBase func1) : base(func1)
367366 public override Operand Calculate ( AlgorithmEngine work )
368367 {
369368 var args1 = func1 . Calculate ( work ) ;
370- if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Hour" ) ; if ( args1 . IsError ) { return args1 ; } }
369+ if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Hour" ) ; if ( args1 . IsError ) { return args1 ; } }
371370 return Operand . Create ( args1 . DateValue . Hour ) ;
372371 }
373372 public override void ToString ( StringBuilder stringBuilder , bool addBrackets )
@@ -385,7 +384,7 @@ public Function_MONTH(FunctionBase func1) : base(func1)
385384 public override Operand Calculate ( AlgorithmEngine work )
386385 {
387386 var args1 = func1 . Calculate ( work ) ;
388- if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Month" ) ; if ( args1 . IsError ) { return args1 ; } }
387+ if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Month" ) ; if ( args1 . IsError ) { return args1 ; } }
389388 if ( args1 . DateValue . Month == null ) {
390389 return Operand . Error ( "Function 'Month' is error!" ) ;
391390 }
@@ -406,7 +405,7 @@ public Function_YEAR(FunctionBase func1) : base(func1)
406405 public override Operand Calculate ( AlgorithmEngine work )
407406 {
408407 var args1 = func1 . Calculate ( work ) ;
409- if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Year" ) ; if ( args1 . IsError ) { return args1 ; } }
408+ if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Year" ) ; if ( args1 . IsError ) { return args1 ; } }
410409 if ( args1 . DateValue . Year == null ) {
411410 return Operand . Error ( "Function 'Year' is error!" ) ;
412411 }
@@ -427,7 +426,7 @@ public Function_DAY(FunctionBase func1) : base(func1)
427426 public override Operand Calculate ( AlgorithmEngine work )
428427 {
429428 var args1 = func1 . Calculate ( work ) ;
430- if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Day" ) ; if ( args1 . IsError ) { return args1 ; } }
429+ if ( args1 . Type != OperandType . DATE ) { args1 = args1 . ToMyDate ( "Function '{0}' parameter is error!" , "Day" ) ; if ( args1 . IsError ) { return args1 ; } }
431430 if ( args1 . DateValue . Day == null ) {
432431 return Operand . Error ( "Function 'Day' is error!" ) ;
433432 }
0 commit comments