Commit 2f6f1131 authored by GoshaZotov's avatar GoshaZotov

add DAYS formula

parent fd462fe2
......@@ -289,7 +289,7 @@
}
cFormulaFunctionGroup['DateAndTime'] = cFormulaFunctionGroup['DateAndTime'] || [];
cFormulaFunctionGroup['DateAndTime'].push(cDATE, cDATEDIF, cDATEVALUE, cDAY, cDAYS360, cEDATE, cEOMONTH, cHOUR,
cFormulaFunctionGroup['DateAndTime'].push(cDATE, cDATEDIF, cDATEVALUE, cDAY, cDAYS, cDAYS360, cEDATE, cEOMONTH, cHOUR,
cMINUTE, cMONTH, cNETWORKDAYS, cNETWORKDAYS_INTL, cNOW, cSECOND, cTIME, cTIMEVALUE, cTODAY, cWEEKDAY, cWEEKNUM,
cWORKDAY, cWORKDAY_INTL, cYEAR, cYEARFRAC);
......@@ -586,6 +586,94 @@
}
};
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cDAYS() {
this.name = "DAYS";
this.value = null;
this.argumentsCurrent = 0;
}
cDAYS.prototype = Object.create(cBaseFunction.prototype);
cDAYS.prototype.constructor = cDAYS;
cDAYS.prototype.argumentsMin = 2;
cDAYS.prototype.argumentsMax = 2;
cDAYS.prototype.numFormat = AscCommonExcel.cNumFormatNone;
cDAYS.prototype.Calculate = function (arg) {
var arg0 = arg[0], val, arg1 = arg[1], val1;
if (arg0 instanceof cArray) {
arg0 = arg0.getElement(0);
} else if (arg0 instanceof cArea || arg0 instanceof cArea3D) {
arg0 = arg0.cross(arguments[1]).tocNumber();
val = arg0.tocNumber().getValue();
}
if (arg0 instanceof cError) {
return this.value = arg0;
} else if (arg0 instanceof cNumber || arg0 instanceof cBool) {
val = arg0.tocNumber().getValue();
} else if (arg0 instanceof cRef || arg0 instanceof cRef3D) {
val = arg0.getValue().tocNumber();
if (val instanceof cNumber || val instanceof cBool) {
val = arg0.tocNumber().getValue();
} else {
return this.value = new cError(cErrorType.wrong_value_type);
}
} else if (arg0 instanceof cString) {
val = arg0.tocNumber();
if (val instanceof cError || val instanceof cEmpty) {
var d = new Date(arg0.getValue());
if (isNaN(d)) {
return this.value = new cError(cErrorType.wrong_value_type);
} else {
val = Math.floor(( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay +
( AscCommonExcel.c_DateCorrectConst + (AscCommon.bDate1904 ? 0 : 1) ));
}
} else {
val = arg0.tocNumber().getValue();
}
}
if (arg1 instanceof cArray) {
arg1 = arg1.getElement(0);
} else if (arg1 instanceof cArea || arg1 instanceof cArea3D) {
arg1 = arg1.cross(arguments[1]).tocNumber();
val1 = arg1.tocNumber().getValue();
}
if (arg1 instanceof cError) {
return this.value = arg1;
} else if (arg1 instanceof cNumber || arg1 instanceof cBool) {
val1 = arg1.tocNumber().getValue();
} else if (arg1 instanceof cRef || arg1 instanceof cRef3D) {
val1 = arg1.getValue().tocNumber();
if (val1 instanceof cNumber || val1 instanceof cBool) {
val1 = arg1.tocNumber().getValue();
} else {
return this.value = new cError(cErrorType.wrong_value_type);
}
} else if (arg1 instanceof cString) {
val1 = arg1.tocNumber();
if (val1 instanceof cError || val1 instanceof cEmpty) {
var d = new Date(arg1.getValue());
if (isNaN(d)) {
return this.value = new cError(cErrorType.wrong_value_type);
} else {
val1 = Math.floor(( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay +
( AscCommonExcel.c_DateCorrectConst + (AscCommon.bDate1904 ? 0 : 1) ));
}
} else {
val1 = arg1.tocNumber().getValue();
}
}
if (val < 0 || val1 < 0) {
return this.value = new cError(cErrorType.not_numeric);
}else{
return this.value = new cNumber(val1 - val);
}
};
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
......
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