Skip to content

Commit 59bb247

Browse files
author
linzhijun
committed
fix
1 parent 7ee7ab1 commit 59bb247

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

csharp/ToolGood.Algorithm/Internals/Functions/FunctionBase.time.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,20 @@ public override void ToString(StringBuilder stringBuilder, bool addBrackets)
261261

262262
}
263263

264-
internal class Function_TIME : Function_N
264+
internal class Function_TIME : Function_3
265265
{
266-
public Function_TIME(FunctionBase[] funcs) : base(funcs)
266+
public Function_TIME(FunctionBase func1, FunctionBase func2, FunctionBase func3) : base(func1, func2, func3)
267267
{
268268
}
269269

270270
public override Operand Calculate(AlgorithmEngine work)
271271
{
272-
var args1 = funcs[0].Calculate(work); if (args1.Type != OperandType.NUMBER) { args1 = args1.ToNumber("Function '{0}' parameter {1} is error!", "Time", 1); if (args1.IsError) { return args1; } }
273-
var args2 = funcs[1].Calculate(work); if (args2.Type != OperandType.NUMBER) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "Time", 2); if (args2.IsError) { return args2; } }
272+
var args1 = func1.Calculate(work); if (args1.Type != OperandType.NUMBER) { args1 = args1.ToNumber("Function '{0}' parameter {1} is error!", "Time", 1); if (args1.IsError) { return args1; } }
273+
var args2 = func2.Calculate(work); if (args2.Type != OperandType.NUMBER) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "Time", 2); if (args2.IsError) { return args2; } }
274274

275275
MyDate d;
276-
if (funcs.Length == 3) {
277-
var args3 = funcs[2].Calculate(work); if (args3.Type != OperandType.NUMBER) { args3 = args3.ToNumber("Function '{0}' parameter {1} is error!", "Time", 3); if (args3.IsError) { return args3; } }
276+
if (func3 != null) {
277+
var args3 = func3.Calculate(work); if (args3.Type != OperandType.NUMBER) { args3 = args3.ToNumber("Function '{0}' parameter {1} is error!", "Time", 3); if (args3.IsError) { return args3; } }
278278
d = new MyDate(0, 0, 0, args1.IntValue, args2.IntValue, args3.IntValue);
279279
} else {
280280
d = new MyDate(0, 0, 0, args1.IntValue, args2.IntValue, 0);
@@ -438,20 +438,19 @@ public override void ToString(StringBuilder stringBuilder, bool addBrackets)
438438
}
439439
}
440440

441-
internal class Function_WEEKDAY : Function_N
441+
internal class Function_WEEKDAY : Function_2
442442
{
443-
public Function_WEEKDAY(FunctionBase[] funcs) : base(funcs)
443+
public Function_WEEKDAY(FunctionBase func1, FunctionBase func2) : base(func1, func2)
444444
{
445445
}
446446

447447
public override Operand Calculate(AlgorithmEngine work)
448448
{
449-
var exprs = funcs;
450-
var args1 = exprs[0].Calculate(work); if (args1.Type != OperandType.DATE) { args1 = args1.ToMyDate("Function '{0}' parameter {1} is error!", "WeekDay", 1); if (args1.IsError) { return args1; } }
449+
var args1 = func1.Calculate(work); if (args1.Type != OperandType.DATE) { args1 = args1.ToMyDate("Function '{0}' parameter {1} is error!", "WeekDay", 1); if (args1.IsError) { return args1; } }
451450

452451
var type = 1;
453-
if (exprs.Length == 2) {
454-
var args2 = exprs[1].Calculate(work); if (args2.Type != OperandType.NUMBER) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "WeekDay", 2); if (args2.IsError) { return args2; } }
452+
if (func2 != null) {
453+
var args2 = func2.Calculate(work); if (args2.Type != OperandType.NUMBER) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "WeekDay", 2); if (args2.IsError) { return args2; } }
455454
type = args2.IntValue;
456455
}
457456

csharp/ToolGood.Algorithm/Internals/MathFunctionVisitor.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -969,11 +969,11 @@ public FunctionBase VisitDATE_fun(mathParser.DATE_funContext context)
969969
public FunctionBase VisitTIME_fun(mathParser.TIME_funContext context)
970970
{
971971
var exprs = context.expr();
972-
FunctionBase[] args = new FunctionBase[exprs.Length];
973-
for (int i = 0; i < exprs.Length; i++) {
974-
args[i] = exprs[i].Accept(this);
975-
}
976-
return new Function_TIME(args);
972+
var args1 = exprs[0].Accept(this);
973+
var args2 = exprs[1].Accept(this);
974+
if (exprs.Length == 2) return new Function_TIME(args1, args2, null);
975+
var args3 = exprs[2].Accept(this);
976+
return new Function_TIME(args1, args2, args3);
977977
}
978978

979979
public FunctionBase VisitNOW_fun(mathParser.NOW_funContext context)
@@ -1025,11 +1025,10 @@ public FunctionBase VisitSECOND_fun(mathParser.SECOND_funContext context)
10251025
public FunctionBase VisitWEEKDAY_fun(mathParser.WEEKDAY_funContext context)
10261026
{
10271027
var exprs = context.expr();
1028-
FunctionBase[] args = new FunctionBase[exprs.Length];
1029-
for (int i = 0; i < exprs.Length; i++) {
1030-
args[i] = exprs[i].Accept(this);
1031-
}
1032-
return new Function_WEEKDAY(args);
1028+
var args1 = exprs[0].Accept(this);
1029+
if (exprs.Length == 1) return new Function_WEEKDAY(args1, null);
1030+
var args2 = exprs[1].Accept(this);
1031+
return new Function_WEEKDAY(args1, args2);
10331032
}
10341033

10351034
public FunctionBase VisitDATEDIF_fun(mathParser.DATEDIF_funContext context)

0 commit comments

Comments
 (0)