Commit df10a213 authored by GoshaZotov's avatar GoshaZotov

modify cNETWORKDAYS function

parent dd0b7e89
......@@ -1159,121 +1159,61 @@
cNETWORKDAYS.prototype.argumentsMax = 3;
cNETWORKDAYS.prototype.numFormat = AscCommonExcel.cNumFormatNone;
cNETWORKDAYS.prototype.Calculate = function (arg) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if (arg0 instanceof cArea || arg0 instanceof cArea3D) {
arg0 = arg0.cross(arguments[1]);
} else if (arg0 instanceof cArray) {
arg0 = arg0.getElementRowCol(0, 0);
}
if (arg1 instanceof cArea || arg1 instanceof cArea3D) {
arg1 = arg1.cross(arguments[1]);
} else if (arg1 instanceof cArray) {
arg1 = arg1.getElementRowCol(0, 0);
}
var oArguments = this._prepareArguments([arg[0], arg[1]], arguments[1]);
var argClone = oArguments.args;
arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber();
argClone[0] = argClone[0].tocNumber();
argClone[1] = argClone[1].tocNumber();
if (arg0 instanceof cError) {
return this.value = arg0;
}
if (arg1 instanceof cError) {
return this.value = arg1;
var argError;
if (argError = this._checkErrorArg(argClone)) {
return this.value = argError;
}
var val0 = arg0.getValue(), val1 = arg1.getValue(), dif, count = 0;
var arg0 = argClone[0], arg1 = argClone[1], arg2 = arg[2];
var val0 = arg0.getValue(), val1 = arg1.getValue();
if (val0 < 0) {
return this.value = new cError(cErrorType.not_numeric);
} else if (!AscCommon.bDate1904) {
if (val0 < 60) {
val0 = new Date((val0 - AscCommonExcel.c_DateCorrectConst) * c_msPerDay);
} else if (val0 == 60) {
val0 = new Date((val0 - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay);
} else {
val0 = new Date((val0 - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay);
}
} else {
val0 = new Date((val0 - AscCommonExcel.c_DateCorrectConst) * c_msPerDay);
}
if (val1 < 0) {
return this.value = new cError(cErrorType.not_numeric);
} else if (!AscCommon.bDate1904) {
if (val1 < 60) {
val1 = new Date((val1 - AscCommonExcel.c_DateCorrectConst) * c_msPerDay);
} else if (val1 == 60) {
val1 = new Date((val1 - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay);
} else {
val1 = new Date((val1 - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay);
}
} else {
val1 = new Date((val1 - AscCommonExcel.c_DateCorrectConst) * c_msPerDay);
}
var holidays = [], i;
val0 = getCorrectDate(val0);
val1 = getCorrectDate(val1);
if (arg2) {
if (arg2 instanceof cRef) {
var a = arg2.getValue();
if (a instanceof cNumber && a.getValue() >= 0) {
holidays.push(a);
}
} else if (arg2 instanceof cArea || arg2 instanceof cArea3D) {
var arr = arg2.getValue();
for (i = 0; i < arr.length; i++) {
if (arr[i] instanceof cNumber && arr[i].getValue() >= 0) {
holidays.push(arr[i]);
}
}
} else if (arg2 instanceof cArray) {
arg2.foreach(function (elem, r, c) {
if (elem instanceof cNumber) {
holidays.push(elem);
} else if (elem instanceof cString) {
var res = g_oFormatParser.parse(elem.getValue());
if (res && res.bDateTime && res.value >= 0) {
holidays.push(new cNumber(parseInt(res.value)));
}
}
})
}
//Holidays
var holidays = getHolidays(arg2);
if (holidays instanceof cError) {
return this.value = holidays;
}
for (i = 0; i < holidays.length; i++) {
holidays[i] = Date.prototype.getDateFromExcel(holidays[i].getValue());
}
var calcDate = function() {
var count = 0;
var start = val0;
var end = val1;
var dif = val1 - val0;
if(dif < 0){
start = val1;
end = val0;
}
function includeInHolidays(date) {
for (var i = 0; i < holidays.length; i++) {
if (date.getTime() == holidays[i].getTime()) {
return false;
var difAbs = ( end - start );
difAbs = ( difAbs + (c_msPerDay) ) / c_msPerDay;
for (var i = 0; i < difAbs; i++) {
var date = new Date(start);
date.setUTCDate(start.getUTCDate() + i);
if (date.getUTCDay() !== 6 && date.getUTCDay() !== 0 && _includeInHolidays(date, holidays)) {
count++;
}
}
return true;
}
var start = val0;
var end = val1;
dif = val1 - val0;
if(dif < 0){
start = val1;
end = val0;
}
var difAbs = ( end - start );
difAbs = ( difAbs + (c_msPerDay) ) / c_msPerDay;
return new cNumber((dif < 0 ? -1 : 1) * count);
};
for (i = 0; i < difAbs; i++) {
var date = new Date(start);
date.setUTCDate(start.getUTCDate() + i);
if (date.getUTCDay() != 6 && date.getUTCDay() != 0 && includeInHolidays(date)) {
count++;
}
}
return this.value = new cNumber((dif < 0 ? -1 : 1) * count);
return this.value = calcDate();
};
/**
......@@ -1292,7 +1232,6 @@
cNETWORKDAYS_INTL.prototype.argumentsMax = 4;
cNETWORKDAYS_INTL.prototype.numFormat = AscCommonExcel.cNumFormatNone;
cNETWORKDAYS_INTL.prototype.Calculate = function (arg) {
var t = this;
var tempArgs = arg[2] ? [arg[0], arg[1], arg[2]] : [arg[0], arg[1]];
var oArguments = this._prepareArguments(tempArgs, arguments[1]);
var argClone = oArguments.args;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment