Commit 5553c680 authored by GoshaZotov's avatar GoshaZotov

add ISOWEEKNUM formula

parent 1d36f679
...@@ -48,8 +48,6 @@ ...@@ -48,8 +48,6 @@
var cFormulaFunctionGroup = AscCommonExcel.cFormulaFunctionGroup; var cFormulaFunctionGroup = AscCommonExcel.cFormulaFunctionGroup;
/*new funcions with _xlnf-prefix*/ /*new funcions with _xlnf-prefix*/
cFormulaFunctionGroup['DateAndTime'] = cFormulaFunctionGroup['DateAndTime'] || [];
cFormulaFunctionGroup['DateAndTime'].push(cISOWEEKNUM);
cFormulaFunctionGroup['TextAndData'] = cFormulaFunctionGroup['TextAndData'] || []; cFormulaFunctionGroup['TextAndData'] = cFormulaFunctionGroup['TextAndData'] || [];
cFormulaFunctionGroup['TextAndData'].push(cDBCS, cUNICHAR, cUNICODE); cFormulaFunctionGroup['TextAndData'].push(cDBCS, cUNICHAR, cUNICODE);
cFormulaFunctionGroup['Statistical'] = cFormulaFunctionGroup['Statistical'] || []; cFormulaFunctionGroup['Statistical'] = cFormulaFunctionGroup['Statistical'] || [];
...@@ -65,10 +63,9 @@ ...@@ -65,10 +63,9 @@
cFormulaFunctionGroup['Information'].push(cSHEET, cSHEETS); cFormulaFunctionGroup['Information'].push(cSHEET, cSHEETS);
cFormulaFunctionGroup['NotRealised'] = cFormulaFunctionGroup['NotRealised'] || []; cFormulaFunctionGroup['NotRealised'] = cFormulaFunctionGroup['NotRealised'] || [];
cFormulaFunctionGroup['NotRealised'].push(cISOWEEKNUM, cFormulaFunctionGroup['NotRealised'].push(cDBCS, cUNICHAR, cUNICODE, cBINOM_DIST_RANGE, cF_TEST, cFORECAST_ETS,
cDBCS, cUNICHAR, cUNICODE, cBINOM_DIST_RANGE, cF_TEST, cFORECAST_ETS, cFORECAST_ETS_CONFINT, cFORECAST_ETS_CONFINT, cFORECAST_ETS_SEASONALITY, cFORECAST_ETS_STAT, cHYPGEOM_DIST, cPDURATION, cAGGREGATE,
cFORECAST_ETS_SEASONALITY, cFORECAST_ETS_STAT, cHYPGEOM_DIST, cPDURATION, cMUNIT, cFORMULATEXT, cSHEET, cSHEETS);
cAGGREGATE, cMUNIT, cFORMULATEXT, cSHEET, cSHEETS);
/** /**
* @constructor * @constructor
...@@ -202,18 +199,6 @@ ...@@ -202,18 +199,6 @@
cHYPGEOM_DIST.prototype = Object.create(cBaseFunction.prototype); cHYPGEOM_DIST.prototype = Object.create(cBaseFunction.prototype);
cHYPGEOM_DIST.prototype.constructor = cHYPGEOM_DIST; cHYPGEOM_DIST.prototype.constructor = cHYPGEOM_DIST;
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cISOWEEKNUM() {
cBaseFunction.call(this, "ISOWEEKNUM");
this.isXLFN = true;
}
cISOWEEKNUM.prototype = Object.create(cBaseFunction.prototype);
cISOWEEKNUM.prototype.constructor = cISOWEEKNUM;
/** /**
* @constructor * @constructor
* @extends {AscCommonExcel.cBaseFunction} * @extends {AscCommonExcel.cBaseFunction}
......
...@@ -412,9 +412,9 @@ ...@@ -412,9 +412,9 @@
cFormulaFunctionGroup['DateAndTime'] = cFormulaFunctionGroup['DateAndTime'] || []; cFormulaFunctionGroup['DateAndTime'] = cFormulaFunctionGroup['DateAndTime'] || [];
cFormulaFunctionGroup['DateAndTime'].push(cDATE, cDATEDIF, cDATEVALUE, cDAY, cDAYS, cDAYS360, cEDATE, cEOMONTH, cHOUR, cFormulaFunctionGroup['DateAndTime'].push(cDATE, cDATEDIF, cDATEVALUE, cDAY, cDAYS, cDAYS360, cEDATE, cEOMONTH,
cMINUTE, cMONTH, cNETWORKDAYS, cNETWORKDAYS_INTL, cNOW, cSECOND, cTIME, cTIMEVALUE, cTODAY, cWEEKDAY, cWEEKNUM, cHOUR, cISOWEEKNUM, cMINUTE, cMONTH, cNETWORKDAYS, cNETWORKDAYS_INTL, cNOW, cSECOND, cTIME, cTIMEVALUE, cTODAY,
cWORKDAY, cWORKDAY_INTL, cYEAR, cYEARFRAC); cWEEKDAY, cWEEKNUM, cWORKDAY, cWORKDAY_INTL, cYEAR, cYEARFRAC);
/** /**
* @constructor * @constructor
...@@ -1011,6 +1011,73 @@ ...@@ -1011,6 +1011,73 @@
} }
}; };
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cISOWEEKNUM() {
this.name = "ISOWEEKNUM";
this.value = null;
this.argumentsCurrent = 0;
}
cISOWEEKNUM.prototype = Object.create(cBaseFunction.prototype);
cISOWEEKNUM.prototype.constructor = cISOWEEKNUM;
cISOWEEKNUM.prototype.argumentsMin = 1;
cISOWEEKNUM.prototype.argumentsMax = 1;
cISOWEEKNUM.prototype.numFormat = AscCommonExcel.cNumFormatNone;
cISOWEEKNUM.prototype.isXLFN = true;
cISOWEEKNUM.prototype.Calculate = function (arg) {
var oArguments = this._prepareArguments(arg, arguments[1], true);
var argClone = oArguments.args;
argClone[0] = argClone[0].tocNumber();
var argError;
if (argError = this._checkErrorArg(argClone)) {
return this.value = argError;
}
var arg0 = argClone[0];
if (arg0.getValue() < 0) {
return this.value = new cError(cErrorType.not_numeric);
}
function WeekNumber(dt, iso, type) {
dt.setUTCHours(0, 0, 0);
var startOfYear = new Date(Date.UTC(dt.getUTCFullYear(), 0, 1));
var endOfYear = new Date(dt);
endOfYear.setUTCMonth(11);
endOfYear.setUTCDate(31);
var wk = parseInt(((dt - startOfYear) / c_msPerDay + iso[startOfYear.getUTCDay()]) / 7);
if (type) {
switch (wk) {
case 0:
// Возвращаем номер недели от 31 декабря предыдущего года
startOfYear.setUTCDate(0);
return WeekNumber(startOfYear, iso, type);
case 53:
// Если 31 декабря выпадает до четверга 1 недели следующего года
if (endOfYear.getUTCDay() < 4) {
return new cNumber(1);
} else {
return new cNumber(wk);
}
default:
return new cNumber(wk);
}
} else {
wk = parseInt(((dt - startOfYear) / c_msPerDay + iso[startOfYear.getUTCDay()] + 7) / 7);
return new cNumber(wk);
}
}
var weekdayStartDay = [0, 1, 2, 3, 4, 5, 6];
var type = 0;
return this.value =
new cNumber(WeekNumber(Date.prototype.getDateFromExcel(arg0.getValue()), weekdayStartDay, type));
};
/** /**
* @constructor * @constructor
* @extends {AscCommonExcel.cBaseFunction} * @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