Commit 6a95a35c authored by GoshaZotov's avatar GoshaZotov

modify cWORKDAY function

parent 16eabedf
...@@ -1707,121 +1707,65 @@ ...@@ -1707,121 +1707,65 @@
cWORKDAY.prototype.argumentsMax = 3; cWORKDAY.prototype.argumentsMax = 3;
cWORKDAY.prototype.numFormat = AscCommonExcel.cNumFormatNone; cWORKDAY.prototype.numFormat = AscCommonExcel.cNumFormatNone;
cWORKDAY.prototype.Calculate = function (arg) { cWORKDAY.prototype.Calculate = function (arg) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var t = this;
var oArguments = this._prepareArguments([arg[0], arg[1]], arguments[1]);
var argClone = oArguments.args;
if (arg0 instanceof cArea || arg0 instanceof cArea3D) { argClone[0] = argClone[0].tocNumber();
arg0 = arg0.cross(arguments[1]); argClone[1] = argClone[1].tocNumber();
} else if (arg0 instanceof cArray) {
arg0 = arg0.getElementRowCol(0, 0);
}
if (arg1 instanceof cArea || arg1 instanceof cArea3D) { var argError;
arg1 = arg1.cross(arguments[1]); if (argError = this._checkErrorArg(argClone)) {
} else if (arg1 instanceof cArray) { return this.value = argError;
arg1 = arg1.getElementRowCol(0, 0);
} }
arg0 = arg0.tocNumber(); var arg0 = argClone[0], arg1 = argClone[1], arg2 = arg[2];
arg1 = arg1.tocNumber();
if (arg0 instanceof cError) {
return this.value = arg0;
}
if (arg1 instanceof cError) {
return this.value = arg1;
}
var val0 = arg0.getValue(), holidays = [], i; var val0 = arg0.getValue(), holidays = [], i;
if (val0 < 0) { if (val0 < 0) {
return this.value = new cError(cErrorType.not_numeric); 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);
} }
val0 = getCorrectDate(val0);
if (arg2) { //Holidays
if (arg2 instanceof cArea || arg2 instanceof cArea3D) { var holidays = getHolidays(arg2);
var arr = arg2.getValue(); if (holidays instanceof cError) {
for (i = 0; i < arr.length; i++) { return this.value = holidays;
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)));
}
}
})
}
} }
for (i = 0; i < holidays.length; i++) { var calcDate = function(){
if (!AscCommon.bDate1904) { var dif = arg1.getValue(), count = 1, dif1 = 1, val, date = val0;
if (holidays[i].getValue() < 60) {
holidays[i] = new Date((holidays[i].getValue() - AscCommonExcel.c_DateCorrectConst) * c_msPerDay);
} else if (holidays[i] == 60) {
holidays[i] =
new Date((holidays[i].getValue() - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay);
} else {
holidays[i] =
new Date((holidays[i].getValue() - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay);
}
} else {
holidays[i] = new Date((holidays[i].getValue() - AscCommonExcel.c_DateCorrectConst) * c_msPerDay);
}
}
function notAHolidays(date) { while (Math.abs(dif) > count) {
for (var i = 0; i < holidays.length; i++) { date = new Date(val0.getTime() + dif1 * c_msPerDay);
if (date.getTime() == holidays[i].getTime()) { if (date.getUTCDay() !== 6 && date.getUTCDay() !== 0 && _includeInHolidays(date, holidays)) {
return false; count++;
}
dif >= 0 ? dif1++ : dif1--;
//если последняя итерация
if(!(Math.abs(dif) > count)){
//проверяем не оказалось ли следом выходных. если оказались - прибавляем
date = new Date(val0.getTime() + dif1 * c_msPerDay);
if(date.getUTCDay() === 6){
dif1 += 2;
}
} }
} }
return true;
}
var dif = arg1.getValue(), count = 1, dif1 = dif > 0 ? 1 : dif < 0 ? -1 : 0, val, date = val0;
while (Math.abs(dif) > count) {
date = new Date(val0.getTime() + dif1 * c_msPerDay); date = new Date(val0.getTime() + dif1 * c_msPerDay);
if (date.getUTCDay() != 6 && date.getUTCDay() != 0 && notAHolidays(date)) { val = date.getExcelDate();
count++;
}
dif >= 0 ? dif1++ : dif1--;
}
date = new Date(val0.getTime() + dif1 * c_msPerDay);
val = date.getExcelDate();
if (val < 0) { if (val < 0) {
return this.value = new cError(cErrorType.not_numeric); return new cError(cErrorType.not_numeric);
} }
return this.setCalcValue(new cNumber(val), 14); return t.setCalcValue(new cNumber(val));
}; };
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cWORKDAY_INTL() {
cBaseFunction.call(this, "WORKDAY.INTL");
}
cWORKDAY_INTL.prototype = Object.create(cBaseFunction.prototype); return this.value = calcDate();
cWORKDAY_INTL.prototype.constructor = cWORKDAY_INTL; };
/** /**
* @constructor * @constructor
......
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