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