Commit 3dc8a52c authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

добавлены DATEDIF, DAYS360, YEARFRAC

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47677 954022d7-b5bf-4e40-9824-e11837661b57
parent 68117d77
......@@ -74,6 +74,9 @@
<script type="text/javascript" src="../apiDefines.js"></script>
<script type="text/javascript" src="../api.js"></script>
<!--for presentation-->
<script type="text/javascript" src="../Common/PresentationSerializeAdapter.js"></script>
<!--for theme-->
<script type="text/javascript" src="../../Common/Shapes/EditorSettings.js"></script>
<script type="text/javascript" src="../../Common/Shapes/Serialize.js"></script>
......
......@@ -950,6 +950,26 @@
ok( Math.abs(oParser.calculate().getValue() - 0.9180555555555560) < dif );
})
test("Test: \"DAYS360\"",function(){
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31))","A2",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), 1198);
oParser = new parserFormula("DAYS360(DATE(2005,5,31),DATE(2002,2,3))","A2",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), -1197);
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),FALSE)","A2",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), 1198);
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),TRUE)","A2",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), 1197);
})
test("Test: \"WEEKNUM\"",function(){
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1))","A2",ws);
ok(oParser.parse());
......@@ -1007,36 +1027,101 @@
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula("WEEKNUM(DATE(2008,1,4),11)","A2",ws);//вск
oParser = new parserFormula("WEEKNUM(DATE(2008,1,4),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula("WEEKNUM(DATE(2008,1,10),11)","A2",ws);//вск
oParser = new parserFormula("WEEKNUM(DATE(2008,1,10),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula("WEEKNUM(DATE(2008,1,11),11)","A2",ws);//вск
oParser = new parserFormula("WEEKNUM(DATE(2008,1,11),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula("WEEKNUM(DATE(2008,1,17),11)","A2",ws);//вск
oParser = new parserFormula("WEEKNUM(DATE(2008,1,17),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3);
oParser = new parserFormula("WEEKNUM(DATE(2008,1,18),11)","A2",ws);//вск
oParser = new parserFormula("WEEKNUM(DATE(2008,1,18),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3);
oParser = new parserFormula("WEEKNUM(DATE(2008,1,24),11)","A2",ws);//вск
oParser = new parserFormula("WEEKNUM(DATE(2008,1,24),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 4);
oParser = new parserFormula("WEEKNUM(DATE(2013,1,1),21)","A2",ws);//вск
oParser = new parserFormula("WEEKNUM(DATE(2013,1,1),21)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula("WEEKNUM(DATE(2013,1,7))","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
})
test("Test: \"YEARFRAC\"",function(){
function okWrapper(a,b){
ok( Math.abs(a - b) < dif );
}
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,3,26))","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.236111111);
oParser = new parserFormula("YEARFRAC(DATE(2006,3,26),DATE(2006,1,1))","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.236111111);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1))","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.5);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2007,9,1))","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 1.666666667);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),0)","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.5);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),1)","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.495890411);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),2)","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.502777778);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),3)","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.495890411);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),4)","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 0.5);
oParser = new parserFormula("YEARFRAC(DATE(2004,3,1),DATE(2006,3,1),1)","A2",ws);
ok(oParser.parse());
okWrapper( oParser.calculate().getValue(), 1.998175182481752);
})
test("Test: \"DATEDIF\"",function(){
oParser = new parserFormula("DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"Y\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"D\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 440);
oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"YD\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 75);
oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"MD\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 14);
})
});
This diff is collapsed.
......@@ -57,6 +57,34 @@ Date.prototype.getDaysInMonth.R = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3
// durations of months for the leap year
Date.prototype.getDaysInMonth.L = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
Date.prototype.getExcelDate = function(){
return Math.floor( ( this.getTime()/1000 - this.getTimezoneOffset()*60 )/c_sPerDay+( c_DateCorrectConst + (g_bDate1904?0:1) ) )
}
Date.prototype.getDateFromExcel = function(val){
if(!g_bDate1904){
if( val < 60 )
return new Date((val-c_DateCorrectConst)*c_msPerDay);
else if( val == 60 )
return new Date((val-c_DateCorrectConst-1)*c_msPerDay);
else
return new Date((val-c_DateCorrectConst-1)*c_msPerDay);
}
else
return new Date((val-c_DateCorrectConst)*c_msPerDay);
}
Date.prototype.addYears = function(counts){
this.setYear(this.getFullYear()+counts);
}
Date.prototype.addMonths = function(counts){
this.setMonth(this.getMonth()+counts);
}
Date.prototype.addDays = function(counts){
this.setDate(this.getDate()+counts);
}
var _func = [];//для велосипеда а-ля перегрузка функций.
_func[cElementType.number] = [];
......
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