Commit 5a8f5f6f authored by Sergey Konovalov's avatar Sergey Konovalov

function property 'ca' moved to function prototype and calculate at parsing

parent 777a8b94
......@@ -581,22 +581,20 @@
return this.value = new cError(cErrorType.not_numeric);
} else if (!AscCommon.bDate1904) {
if (val < 60) {
return this.setCA(
new cNumber(( new Date((val - AscCommonExcel.c_DateCorrectConst) * c_msPerDay) ).getUTCDate()),
false, 0);
return this.setCalcValue(
new cNumber(( new Date((val - AscCommonExcel.c_DateCorrectConst) * c_msPerDay) ).getUTCDate()), 0);
} else if (val == 60) {
return this.setCA(
return this.setCalcValue(
new cNumber(( new Date((val - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay) ).getUTCDate() +
1), false, 0);
1), 0);
} else {
return this.setCA(
return this.setCalcValue(
new cNumber(( new Date((val - AscCommonExcel.c_DateCorrectConst - 1) * c_msPerDay) ).getUTCDate()),
false, 0);
0);
}
} else {
return this.setCA(
new cNumber(( new Date((val - AscCommonExcel.c_DateCorrectConst) * c_msPerDay) ).getUTCDate()), false,
0);
return this.setCalcValue(
new cNumber(( new Date((val - AscCommonExcel.c_DateCorrectConst) * c_msPerDay) ).getUTCDate()), 0);
}
};
cDAY.prototype.getInfo = function () {
......@@ -879,8 +877,8 @@
return this.value = new cError(cErrorType.not_numeric);
} else //1 2 3 4 4 3 2 1
{
return this.setCA(new cNumber(parseInt(( ( val - Math.floor(val) ) * 24 ).toFixed(cExcelDateTimeDigits))),
false, 0);
return this.setCalcValue(new cNumber(parseInt(( ( val - Math.floor(val) ) * 24 ).toFixed(cExcelDateTimeDigits))),
0);
}
};
cHOUR.prototype.getInfo = function () {
......@@ -947,7 +945,7 @@
return this.value = new cError(cErrorType.not_numeric);
} else {
val = parseInt(( ( val * 24 - Math.floor(val * 24) ) * 60 ).toFixed(cExcelDateTimeDigits)) % 60;
return this.setCA(new cNumber(val), false, 0);
return this.setCalcValue(new cNumber(val), 0);
}
};
cMINUTE.prototype.getInfo = function () {
......@@ -1011,15 +1009,15 @@
}
if (!AscCommon.bDate1904) {
if (val == 60) {
return this.setCA(new cNumber(2), false, 0);
return this.setCalcValue(new cNumber(2), 0);
} else {
return this.setCA(
return this.setCalcValue(
new cNumber(( new Date(( (val == 0 ? 1 : val) - AscCommonExcel.c_DateCorrectConst - 1 ) *
c_msPerDay) ).getUTCMonth() + 1), false, 0);
c_msPerDay) ).getUTCMonth() + 1), 0);
}
} else {
return this.setCA(new cNumber(( new Date(( (val == 0 ? 1 : val) - AscCommonExcel.c_DateCorrectConst ) *
c_msPerDay) ).getUTCMonth() + 1), false, 0);
return this.setCalcValue(new cNumber(( new Date(( (val == 0 ? 1 : val) - AscCommonExcel.c_DateCorrectConst ) *
c_msPerDay) ).getUTCMonth() + 1), 0);
}
};
cMONTH.prototype.getInfo = function () {
......@@ -1181,12 +1179,13 @@
cNOW.prototype = Object.create(cBaseFunction.prototype);
cNOW.prototype.constructor = cNOW;
cNOW.prototype.argumentsMax = 0;
cNOW.prototype.ca = true;
cNOW.prototype.Calculate = function () {
var d = new Date();
this.value = new cNumber(d.getExcelDate() +
(d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds()) / c_sPerDay);
this.value.numFormat = 22;
return this.setCA(this.value, true);
return this.value;
};
cNOW.prototype.getInfo = function () {
return {
......@@ -1252,7 +1251,7 @@
return this.value = new cError(cErrorType.not_numeric);
} else {
val = parseInt((( val * 24 * 60 - Math.floor(val * 24 * 60) ) * 60).toFixed(cExcelDateTimeDigits)) % 60;
return this.setCA(new cNumber(val), false, 0);
return this.setCalcValue(new cNumber(val), 0);
}
};
cSECOND.prototype.getInfo = function () {
......@@ -1313,7 +1312,7 @@
second = second.getValue();
var v = (hour * 60 * 60 + minute * 60 + second) / c_sPerDay;
this.setCA(new cNumber(v - Math.floor(v)), false);
this.value = new cNumber(v - Math.floor(v));
if (arguments[1].getNumFormatStr().toLowerCase() === "general") {
this.value.numFormat = 18;
}
......@@ -1382,8 +1381,9 @@
cTODAY.prototype = Object.create(cBaseFunction.prototype);
cTODAY.prototype.constructor = cTODAY;
cTODAY.prototype.argumentsMax = 0;
cTODAY.prototype.ca = true;
cTODAY.prototype.Calculate = function () {
this.setCA(new cNumber(new Date().getExcelDate()), true);
this.value = new cNumber(new Date().getExcelDate());
if (arguments[1].getNumFormatStr().toLowerCase() === "general") {
this.value.numFormat = 14;
}
......@@ -1719,9 +1719,9 @@
}
if (arguments[1].getNumFormatStr().toLowerCase() === "general") {
return this.setCA(new cNumber(val), false, 14);
return this.setCalcValue(new cNumber(val), 14);
} else {
return this.setCA(new cNumber(val), false);
return this.value = new cNumber(val);
}
};
cWORKDAY.prototype.getInfo = function () {
......@@ -1794,11 +1794,11 @@
}
}
if (val < 0) {
return this.setCA(new cError(cErrorType.not_numeric), false, 0);
return this.setCalcValue(new cError(cErrorType.not_numeric), 0);
} else {
return this.setCA(
return this.setCalcValue(
new cNumber((new Date((val - (AscCommonExcel.c_DateCorrectConst + 1)) * c_msPerDay)).getUTCFullYear()),
false, 0);
0);
}
};
cYEAR.prototype.getInfo = function () {
......
......@@ -567,6 +567,7 @@
cINDIRECT.prototype.constructor = cINDIRECT;
cINDIRECT.prototype.argumentsMin = 1;
cINDIRECT.prototype.argumentsMax = 2;
cINDIRECT.prototype.ca = true;
cINDIRECT.prototype.Calculate = function (arg) {
var t = this, arg0 = arg[0].tocString(), arg1 = arg[1] ? arg[1] :
new cBool(true), r1 = arguments[1], wb = r1.worksheet.workbook, o = {
......@@ -608,7 +609,7 @@
}
ret.addElement(found_operand)
});
return this.setCA(ret, true);
return this.value = ret;
} else {
o.Formula = arg0.toString();
parseReference();
......@@ -623,7 +624,7 @@
}
}
return this.setCA(ret, true);
return this.value = ret;
};
cINDIRECT.prototype.getInfo = function () {
......@@ -906,6 +907,7 @@
cOFFSET.prototype.constructor = cOFFSET;
cOFFSET.prototype.argumentsMin = 3;
cOFFSET.prototype.argumentsMax = 5;
cOFFSET.prototype.ca = true;
cOFFSET.prototype.Calculate = function (arg) {
function validBBOX(bbox) {
......@@ -987,7 +989,7 @@
this.value = new cError(cErrorType.wrong_value_type);
}
return this.setCA(this.value, true);
return this.value;
};
cOFFSET.prototype.getInfo = function () {
......
......@@ -2564,8 +2564,9 @@
cRAND.prototype = Object.create(cBaseFunction.prototype);
cRAND.prototype.constructor = cRAND;
cRAND.prototype.argumentsMax = 0;
cRAND.prototype.ca = true;
cRAND.prototype.Calculate = function () {
return this.setCA(new cNumber(Math.random()), true);
return this.value = new cNumber(Math.random());
};
cRAND.prototype.getInfo = function () {
return {
......@@ -2587,6 +2588,7 @@
cRANDBETWEEN.prototype.constructor = cRANDBETWEEN;
cRANDBETWEEN.prototype.argumentsMin = 2;
cRANDBETWEEN.prototype.argumentsMax = 2;
cRANDBETWEEN.prototype.ca = true;
cRANDBETWEEN.prototype.Calculate = function (arg) {
function randBetween(a, b) {
......@@ -2644,7 +2646,7 @@
}
return this.setCA(new cNumber(randBetween(arg0.getValue(), arg1.getValue())), true);
return this.value = new cNumber(randBetween(arg0.getValue(), arg1.getValue()));
};
cRANDBETWEEN.prototype.getInfo = function () {
return {
......
......@@ -634,7 +634,6 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
function cBaseType(val) {
this.needRecalc = false;
this.numFormat = null;
this.ca = false;
this.value = val;
}
......@@ -642,7 +641,6 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
oRes.needRecalc = this.needRecalc;
oRes.numFormat = this.numFormat;
oRes.value = this.value;
oRes.ca = this.ca;
};
cBaseType.prototype.getValue = function () {
return this.value;
......@@ -2282,6 +2280,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cBaseFunction.prototype.argumentsMin = 0;
cBaseFunction.prototype.argumentsMax = 255;
cBaseFunction.prototype.numFormat = c_numFormatFirstCell;
cBaseFunction.prototype.ca = false;
cBaseFunction.prototype.Calculate = function () {
this.value = new cError(cErrorType.wrong_name);
return this.value;
......@@ -2341,11 +2340,8 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cBaseFunction.prototype.toString = function () {
return this.name.replace(rx_sFuncPref, "_xlfn.");
};
cBaseFunction.prototype.setCA = function (arg, ca, numFormat) {
cBaseFunction.prototype.setCalcValue = function (arg, numFormat) {
this.value = arg;
if (ca) {
this.value.ca = true;
}
if (numFormat !== null && numFormat !== undefined) {
this.value.numFormat = numFormat;
}
......@@ -4258,6 +4254,9 @@ parserFormula.prototype.parse = function(local, digitDelim) {
elem = new cBaseFunction(val);
elem.isXLFN = (0 === val.indexOf("_xlfn."));
}
if (elem && elem.ca) {
this.ca = elem.ca;
}
stack.push(elem);
args[++indentCount] = 1;
} else {
......@@ -4783,15 +4782,18 @@ parserFormula.prototype.parse = function(local, digitDelim) {
found_operator.isXLFN = ( this.operand_str.indexOf("_xlfn.") === 0 );
}
if (found_operator != null) {
this.elemArr.push(found_operator);
this.f.push(found_operator);
} else {
this.error.push(c_oAscError.ID.FrmlWrongFunctionName);
this.outStack = [];
this.elemArr = [];
return false;
}
if (found_operator != null) {
if (found_operator.ca) {
this.ca = found_operator.ca;
}
this.elemArr.push(found_operator);
this.f.push(found_operator);
} else {
this.error.push(c_oAscError.ID.FrmlWrongFunctionName);
this.outStack = [];
this.elemArr = [];
return false;
}
this.operand_expected = false;
wasRigthParentheses = false;
continue;
......@@ -4919,14 +4921,6 @@ parserFormula.prototype.parse = function(local, digitDelim) {
}
this.isCalculate = false;
this.isDirty = false;
if(!!this.ca != this.value.ca){
if (this.value.ca) {
this.wb.dependencyFormulas.startListeningVolatile(this);
} else {
this.wb.dependencyFormulas.endListeningVolatile(this);
}
this.ca = this.value.ca;
}
};
/* Для обратной сборки функции иногда необходимо поменять ссылки на ячейки */
......
......@@ -5335,7 +5335,6 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
Cell.prototype._calculateRefType = function () {
var val = this.formulaParsed.value;
var nF = val.numFormat;
var ca = val.ca;
if (cElementType.cell === val.type || cElementType.cell3D === val.type) {
val = val.getValue();
if (cElementType.empty === val.type) {
......@@ -5349,7 +5348,6 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
val = val.cross(new Asc.Range(this.nCol, this.nRow, this.nCol, this.nRow), this.ws.getId());
}
val.numFormat = nF;
val.ca = ca;
this.formulaParsed.value = val;
};
Cell.prototype._updateCellValue = function() {
......
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