Skip to content

Commit 56ced75

Browse files
author
linzhijun
committed
fix
1 parent 59bb247 commit 56ced75

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,20 +672,20 @@ public override void ToString(StringBuilder stringBuilder, bool addBrackets)
672672
}
673673
}
674674

675-
internal class Function_WEEKNUM : Function_N
675+
internal class Function_WEEKNUM : Function_2
676676
{
677-
public Function_WEEKNUM(FunctionBase[] funcs) : base(funcs)
677+
public Function_WEEKNUM(FunctionBase func1, FunctionBase func2) : base(func1, func2)
678678
{
679679
}
680680

681681
public override Operand Calculate(AlgorithmEngine work)
682682
{
683-
var args1 = funcs[0].Calculate(work); if (args1.Type != OperandType.DATE) { args1 = args1.ToMyDate("Function '{0}' parameter {1} is error!", "WeekNum", 1); if (args1.IsError) { return args1; } }
683+
var args1 = func1.Calculate(work); if (args1.Type != OperandType.DATE) { args1 = args1.ToMyDate("Function '{0}' parameter {1} is error!", "WeekNum", 1); if (args1.IsError) { return args1; } }
684684
var startMyDate = (DateTime)args1.DateValue;
685685

686686
var days = startMyDate.DayOfYear + (int)(new DateTime(startMyDate.Year, 1, 1).DayOfWeek);
687-
if (funcs.Length == 2) {
688-
var args2 = funcs[1].Calculate(work); if (args2.Type != OperandType.NUMBER) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "WeekNum", 2); if (args2.IsError) { return args2; } }
687+
if (func2 != null) {
688+
var args2 = func2.Calculate(work); if (args2.Type != OperandType.NUMBER) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "WeekNum", 2); if (args2.IsError) { return args2; } }
689689
if (args2.IntValue == 2) {
690690
days--;
691691
}

csharp/ToolGood.Algorithm/Internals/MathFunctionVisitor.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,11 +1091,10 @@ public FunctionBase VisitWORKDAY_fun(mathParser.WORKDAY_funContext context)
10911091
public FunctionBase VisitWEEKNUM_fun(mathParser.WEEKNUM_funContext context)
10921092
{
10931093
var exprs = context.expr();
1094-
FunctionBase[] args = new FunctionBase[exprs.Length];
1095-
for (int i = 0; i < exprs.Length; i++) {
1096-
args[i] = exprs[i].Accept(this);
1097-
}
1098-
return new Function_WEEKNUM(args);
1094+
var args1 = exprs[0].Accept(this);
1095+
if (exprs.Length == 1) return new Function_WEEKNUM(args1, null);
1096+
var args2 = exprs[1].Accept(this);
1097+
return new Function_WEEKNUM(args1, args2);
10991098
}
11001099

11011100
public FunctionBase VisitADDMONTHS_fun(mathParser.ADDMONTHS_funContext context)

0 commit comments

Comments
 (0)