From aaabde524b6f31d8c803986ae16c107a4ff93555 Mon Sep 17 00:00:00 2001 From: "Dmitry.Shahtanov" Date: Mon, 17 Jun 2013 13:32:05 +0000 Subject: [PATCH] =?UTF-8?q?=D0=B0=D0=B1=D1=81=D0=BE=D0=BB=D1=8E=D1=82?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47300 954022d7-b5bf-4e40-9824-e11837661b57 --- Excel/model/parserFormula.js | 71 +++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/Excel/model/parserFormula.js b/Excel/model/parserFormula.js index 57c6f0416a..49c5227e80 100644 --- a/Excel/model/parserFormula.js +++ b/Excel/model/parserFormula.js @@ -41,6 +41,23 @@ function extend(Child, Parent) { Child.superclass = Parent.prototype } +Date.prototype.isLeapYear = function() +{ + var y = this.getFullYear(); + return y % 4 == 0 && y % 100 != 0 || y % 400 == 0; +}; + +Date.prototype.getDaysInMonth = function() +{ + return arguments.callee[this.isLeapYear() ? 'L' : 'R'][this.getMonth()]; +}; + +// durations of months for the regular year +Date.prototype.getDaysInMonth.R = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; +// durations of months for the leap year +Date.prototype.getDaysInMonth.L = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + + var _func = new Array();//для велосипеда а-ля перегрузка функций. _func[cElementType.number] = new Array(); _func[cElementType.string] = new Array(); @@ -1655,6 +1672,58 @@ var cFormulaFunction = { 'EDATE' : function(){ var r = new cBaseFunction(); r.setName("EDATE"); + r.setArgumentsMin(2); + r.setArgumentsMax(2); + r.Calculate = function(arg){ + var arg0 = arg[0], arg1 = arg[1]; + + if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){ + arg0 = arg0.cross(arguments[1].first); + } + else if( arg0 instanceof cArray ){ + arg0 = arg0.getElementRowCol(0,0); + } + + if ( arg1 instanceof cArea || arg1 instanceof cArea3D ){ + arg1 = arg1.cross(arguments[1].first); + } + else if( arg1 instanceof cArray ){ + arg1 = arg1.getElementRowCol(0,0); + } + + arg0 = arg0.tocNumber(); + arg1 = arg1.tocNumber(); + + if( arg0 instanceof cError) return this.value = arg0; + if( arg1 instanceof cError) return this.value = arg1; + + var val = arg0.getValue(); + + if(val < 0) + return this.setCA(new cError( cErrorType.not_numeric ),true); + else if(!g_bDate1904){ + if( val < 60 ) + val = new Date((val-c_DateCorrectConst)*86400*1000); + else if( val == 60 ) + val = new Date((val-c_DateCorrectConst-1)*86400*1000); + else + val = new Date((val-c_DateCorrectConst-1)*86400*1000); + } + else + val = new Date((val-c_DateCorrectConst)*86400*1000); + + val = new Date(val.setMonth(val.getMonth()+arg1.getValue())) + + return this.value = new cNumber( Math.floor( ( val.getTime()/1000 - val.getTimezoneOffset()*60 )/86400+(c_DateCorrectConst+1) ) ) + + } + /* r.getInfo = function(){ + return { + name:this.name, + args:"( start-date , month-offset )" + }; + } */ + r.setFormat(r.formatType.noneFormat); return r; }, 'EOMONTH' : function(){ @@ -8547,7 +8616,7 @@ function cRef(val,_ws){/*Ref means A1 for example*/ this.isAbsolute = false; this.type = cElementType.cell; this.range = _ws.getRange2(val); - this._valid = new CellAddress(val.replace("$","")).isValid(); + this._valid = new CellAddress(val.replace(/\$/g,"")).isValid(); } extend(cRef,cBaseType); cRef.prototype.getWsId = function(){ return this.ws.Id; }