Commit 797c16cc authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

работа с временем переведена на UTC, пространство имен для функций.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55785 954022d7-b5bf-4e40-9824-e11837661b57
parent 60a874e7
......@@ -2621,7 +2621,7 @@
var nSize = A.length;
if ( A.length < 1 || nSize == 0 )
return new CError( cErrorType.not_available ).toString();
return new cError( cErrorType.not_available ).toString();
else {
if ( nSize == 1 )
return toFixed( A[0] );
......@@ -4142,7 +4142,7 @@
oParser = new parserFormula( "PRICE(DATE(2008,2,15),DATE(2017,11,15),0.0575,0.065,100,2,0)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), _getprice( new Date( 2008, 1, 15 ), new Date( 2017, 10, 15 ), 0.0575, 0.065, 100, 2, 0 ) );
strictEqual( oParser.calculate().getValue(), _getprice( new Date( Date.UTC(2008, 1, 15 )), new Date( Date.UTC(2017, 10, 15 )), 0.0575, 0.065, 100, 2, 0 ) );
} )
......@@ -4184,7 +4184,7 @@
oParser = new parserFormula( "YIELD(DATE(2008,2,15),DATE(2016,11,15),0.0575,95.04287,100,2,0)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), _getYield( new Date(2008,1,15), new Date(2016,10,15),0.0575,95.04287,100,2,0 ) );
strictEqual( oParser.calculate().getValue(), _getYield( new Date(Date.UTC(2008,1,15)), new Date(Date.UTC(2016,10,15)),0.0575,95.04287,100,2,0 ) );
} )
......@@ -4229,7 +4229,7 @@
oParser = new parserFormula( "ODDLPRICE(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),0.0785,0.0625,100,2,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), oddlprice( new Date(2008,10,11), new Date(2021,2,1), new Date(2008,9,15), 0.0785, 0.0625, 100, 2, 1 ) );
strictEqual( oParser.calculate().getValue(), oddlprice( new Date(Date.UTC(2008,10,11)), new Date(Date.UTC(2021,2,1)), new Date(Date.UTC(2008,9,15)), 0.0785, 0.0625, 100, 2, 1 ) );
} )
......@@ -4259,7 +4259,7 @@
oParser = new parserFormula( "DURATION(DATE(2008,1,1),DATE(2016,1,1),0.08,0.09,2,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), _duration( new Date(2008,0,1), new Date(2016,0,1), 0.08, 0.09, 2, 1 ) );
strictEqual( oParser.calculate().getValue(), _duration( new Date(Date.UTC(2008,0,1)), new Date(Date.UTC(2016,0,1)), 0.08, 0.09, 2, 1 ) );
} )
......@@ -4273,7 +4273,7 @@
oParser = new parserFormula( "MDURATION(DATE(2008,1,1),DATE(2016,1,1),0.08,0.09,2,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), mduration( new Date(2008,0,1), new Date(2016,0,1), 0.08, 0.09, 2, 1 ) );
strictEqual( oParser.calculate().getValue(), mduration( new Date(Date.UTC(2008,0,1)), new Date(Date.UTC(2016,0,1)), 0.08, 0.09, 2, 1 ) );
} )
......
......@@ -7,7 +7,7 @@
* Time: 15:15
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Cube = {
FormulaObjects.cFormulaFunction.Cube = {
'groupName':"Cube",
'CUBEKPIMEMBER':cCUBEKPIMEMBER,
'CUBEMEMBER':cCUBEMEMBER,
......
......@@ -7,7 +7,7 @@
* Time: 15:16
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Database = {
FormulaObjects.cFormulaFunction.Database = {
'groupName':"Database",
'DAVERAGE':cDAVERAGE,
'DCOUNT':cDCOUNT,
......
......@@ -351,7 +351,7 @@ function BesselY( fNum, nOrder ) {
* Time: 12:25
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Engineering = {
FormulaObjects.cFormulaFunction.Engineering = {
'groupName':"Engineering",
'BESSELI':cBESSELI,
'BESSELJ':cBESSELJ,
......
......@@ -165,7 +165,7 @@ function RateIteration( nper, payment, pv, fv, payType, guess ) {
function lcl_GetCouppcd( settl, matur, freq ) {
var n = new Date( matur );
n.setFullYear( settl.getFullYear() );
n.setUTCFullYear( settl.getUTCFullYear() );
if ( n < settl ) {
n.addYears( 1 );
}
......@@ -176,7 +176,7 @@ function lcl_GetCouppcd( settl, matur, freq ) {
}
function lcl_GetCoupncd( settl, matur, freq ) {
matur.setFullYear( settl.getFullYear() );
matur.setUTCFullYear( settl.getUTCFullYear() );
if ( matur > settl ) {
matur.addYears( -1 );
}
......@@ -199,7 +199,7 @@ function getcoupdays( settl, matur, frequency, basis ) {
function getcoupnum( settl, matur, frequency ) {
var n = lcl_GetCouppcd( settl, matur, frequency ),
months = (matur.getFullYear() - n.getFullYear()) * 12 + matur.getMonth() - n.getMonth();
months = (matur.getUTCFullYear() - n.getUTCFullYear()) * 12 + matur.getUTCMonth() - n.getUTCMonth();
return Math.ceil( months * frequency / 12 );
}
......@@ -289,9 +289,9 @@ function getyieldmat( settle, mat, issue, rate, price, base ) {
function getduration( settlement, maturity, coupon, yld, frequency, basis ) {
var dbc = getcoupdaybs( new Date( settlement ).truncate(), new Date( maturity ).truncate(), frequency, basis ),
coupD = getcoupdays( new Date( settlement ).truncate(), new Date( maturity ).truncate(), frequency, basis ),
numCoup = getcoupnum( new Date( settlement ).truncate(), new Date( maturity ).truncate(), frequency );
var dbc = getcoupdaybs( new Date( settlement ), new Date( maturity ), frequency, basis ),
coupD = getcoupdays( new Date( settlement ), new Date( maturity ), frequency, basis ),
numCoup = getcoupnum( new Date( settlement ), new Date( maturity ), frequency );
var duration = 0, p = 0;
......@@ -326,7 +326,7 @@ function getduration( settlement, maturity, coupon, yld, frequency, basis ) {
* Time: 15:19
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Financial = {
FormulaObjects.cFormulaFunction.Financial = {
'groupName':"Financial",
'ACCRINT':cACCRINT,
'ACCRINTM':cACCRINTM,
......@@ -3278,7 +3278,7 @@ cODDFPRICE.prototype.Calculate = function ( arg ) {
var newDate = new Date( orgDate );
newDate.addMonths( numMonths );
if ( returnLastDay )
return new Date( newDate.getFullYear(), newDate.getMonth(), newDate.getDaysInMonth() );
return new Date( newDate.getUTCFullYear(), newDate.getUTCMonth(), newDate.getDaysInMonth() );
else
return newDate;
}
......@@ -3302,8 +3302,8 @@ cODDFPRICE.prototype.Calculate = function ( arg ) {
}
function coupNumber( mat, settl, numMonths, isWholeNumber ) {
var my = mat.getFullYear(), mm = mat.getMonth() + 1, md = mat.getDate(),
sy = settl.getFullYear(), sm = settl.getMonth() + 1, sd = settl.getDate(),
var my = mat.getUTCFullYear(), mm = mat.getUTCMonth() + 1, md = mat.getDate(),
sy = settl.getUTCFullYear(), sm = settl.getUTCMonth() + 1, sd = settl.getDate(),
endOfMonthTemp = lastDayOfMonth( my, mm, md ),
endOfMonth = (!endOfMonthTemp && mm != 2 && md > 28 && md < new Date( my, mm ).getDaysInMonth()) ? lastDayOfMonth( sy, sm, sd ) : endOfMonthTemp,
startDate = changeMonth( settl, 0, endOfMonth ),
......@@ -4684,8 +4684,8 @@ cTBILLEQ.prototype.Calculate = function ( arg ) {
var d1 = Date.prototype.getDateFromExcel( settlement.getValue() );
var d2 = Date.prototype.getDateFromExcel( nMat );
var date1 = d1.getDate(), month1 = d1.getMonth(), year1 = d1.getFullYear(),
date2 = d2.getDate(), month2 = d2.getMonth(), year2 = d2.getFullYear();
var date1 = d1.getUTCDate(), month1 = d1.getUTCMonth(), year1 = d1.getUTCFullYear(),
date2 = d2.getUTCDate(), month2 = d2.getUTCMonth(), year2 = d2.getUTCFullYear();
var nDiff = GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true );
......@@ -4838,8 +4838,8 @@ cTBILLYIELD.prototype.Calculate = function ( arg ) {
var d1 = Date.prototype.getDateFromExcel( settlement.getValue() );
var d2 = Date.prototype.getDateFromExcel( maturity.getValue() );
var date1 = d1.getDate(), month1 = d1.getMonth(), year1 = d1.getFullYear(),
date2 = d2.getDate(), month2 = d2.getMonth(), year2 = d2.getFullYear();
var date1 = d1.getUTCDate(), month1 = d1.getUTCMonth(), year1 = d1.getUTCFullYear(),
date2 = d2.getUTCDate(), month2 = d2.getUTCMonth(), year2 = d2.getUTCFullYear();
var nDiff = GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true );
nDiff++;
......
......@@ -7,7 +7,7 @@
* Time: 15:21
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Information = {
FormulaObjects.cFormulaFunction.Information = {
'groupName':"Information",
'ERROR.TYPE':cERROR_TYPE,
'ISBLANK':cISBLANK,
......
......@@ -7,7 +7,7 @@
* Time: 15:22
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Logical = {
FormulaObjects.cFormulaFunction.Logical = {
'groupName':"Logical",
'AND':cAND,
'FALSE':cFALSE,
......
......@@ -7,7 +7,7 @@
* Time: 15:21
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.LookupAndReference = {
FormulaObjects.cFormulaFunction.LookupAndReference = {
'groupName':"LookupAndReference",
'ADDRESS':cADDRESS,
'AREAS':cAREAS,
......
......@@ -7,7 +7,7 @@
* Time: 15:20
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Mathematic = {
FormulaObjects.cFormulaFunction.Mathematic = {
'groupName':"Mathematic",
'ABS':cABS,
'ACOS':cACOS,
......@@ -2857,42 +2857,39 @@ function cROMAN() {
}
cROMAN.prototype = Object.create( cBaseFunction.prototype )
cROMAN.prototype.Calculate = function ( arg ) {
function roman( fVal, fMode ) {
if ( (fMode >= 0.0) && (fMode < 5.0) && (fVal >= 0.0) && (fVal < 4000.0) ) {
var pChars = [ 'M', 'D', 'C', 'L', 'X', 'V', 'I' ];
var pValues = [ 1000, 500, 100, 50, 10, 5, 1 ];
var nMaxIndex = pValues.length - 1;
var aRoman = "";
var nVal = fVal;
var nMode = fMode;
for ( var i = 0; i <= nMaxIndex / 2; i++ ) {
var nIndex = 2 * i;
var nDigit = parseInt( nVal / pValues[ nIndex ] );
if ( (nDigit % 5) == 4 ) {
var nIndex2 = (nDigit == 4) ? nIndex - 1 : nIndex - 2;
var nSteps = 0;
while ( (nSteps < nMode) && (nIndex < nMaxIndex) ) {
nSteps++;
if ( pValues[ nIndex2 ] - pValues[ nIndex + 1 ] <= nVal )
nIndex++;
function roman( num, mode ) {
if ( (mode >= 0) && (mode < 5) && (num >= 0) && (num < 4000) ) {
var chars = [ 'M', 'D', 'C', 'L', 'X', 'V', 'I' ],
values = [ 1000, 500, 100, 50, 10, 5, 1 ],
maxIndex = values.length - 1,
aRoman = "",
index, digit, index2, steps;
for ( var i = 0; i <= maxIndex / 2; i++ ) {
index = 2 * i;
digit = parseInt( num / values[ index ] );
if ( (digit % 5) == 4 ) {
index2 = (digit == 4) ? index - 1 : index - 2;
steps = 0;
while ( (steps < mode) && (index < maxIndex) ) {
steps++;
if ( values[ index2 ] - values[ index + 1 ] <= num )
index++;
else
nSteps = nMode;
steps = mode;
}
aRoman += pChars[ nIndex ];
aRoman += pChars[ nIndex2 ];
nVal = ( nVal + pValues[ nIndex ] );
nVal = ( nVal - pValues[ nIndex2 ] );
aRoman += chars[ index ];
aRoman += chars[ index2 ];
num = ( num + values[ index ] );
num = ( num - values[ index2 ] );
}
else {
if ( nDigit > 4 )
aRoman += pChars[ nIndex - 1 ];
for ( var j = nDigit % 5; j > 0; j-- ) {
aRoman += pChars[ nIndex ];
if ( digit > 4 )
aRoman += chars[ index - 1 ];
for ( var j = digit % 5; j > 0; j-- ) {
aRoman += chars[ index ];
}
nVal %= pValues[ nIndex ];
num %= values[ index ];
}
}
return new cString( aRoman );
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
* Time: 15:18
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Statistical = {
FormulaObjects.cFormulaFunction.Statistical = {
'groupName':"Statistical",
'AVEDEV':cAVEDEV,
'AVERAGE':cAVERAGE,
......
......@@ -7,7 +7,7 @@
* Time: 15:17
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.TextAndData = {
FormulaObjects.cFormulaFunction.TextAndData = {
'groupName':"TextAndData",
'ASC':cASC,
'BAHTTEXT':cBAHTTEXT,
......@@ -609,7 +609,7 @@ cFIND.prototype.getInfo = function () {
}
function cFINDB() {
var r = new cFormulaFunction.TextAndData["FIND"]()
var r = new FormulaObjects.cFormulaFunction.TextAndData["FIND"]()
r.setName( "FINDB" );
return r;
}
......@@ -869,7 +869,7 @@ cLEFT.prototype.getInfo = function () {
}
function cLEFTB() {
var r = new cFormulaFunction.TextAndData["LEFT"]()
var r = new FormulaObjects.cFormulaFunction.TextAndData["LEFT"]()
r.setName( "LEFTB" );
return r;
}
......@@ -918,7 +918,7 @@ cLEN.prototype.getInfo = function () {
}
function cLENB() {
var r = new cFormulaFunction.TextAndData["LEN"]();
var r = new FormulaObjects.cFormulaFunction.TextAndData["LEN"]();
r.setName( "LENB" );
return r;
}
......@@ -1033,7 +1033,7 @@ cMID.prototype.getInfo = function () {
}
function cMIDB() {
var r = new cFormulaFunction.TextAndData["MID"]();
var r = new FormulaObjects.cFormulaFunction.TextAndData["MID"]();
r.setName( "MIDB" );
return r;
}
......@@ -1210,7 +1210,7 @@ cREPLACE.prototype.getInfo = function () {
}
function cREPLACEB() {
var r = new cFormulaFunction.TextAndData["REPLACE"]();
var r = new FormulaObjects.cFormulaFunction.TextAndData["REPLACE"]();
r.setName( "REPLACEB" );
return r;
}
......@@ -1344,7 +1344,7 @@ cRIGHT.prototype.getInfo = function () {
}
function cRIGHTB() {
var r = new cFormulaFunction.TextAndData["RIGHT"]()
var r = new FormulaObjects.cFormulaFunction.TextAndData["RIGHT"]()
r.setName( "RIGHTB" );
return r;
}
......@@ -1450,7 +1450,7 @@ cSEARCH.prototype.getInfo = function () {
}
function cSEARCHB() {
var r = new cFormulaFunction.TextAndData["SEARCH"]();
var r = new FormulaObjects.cFormulaFunction.TextAndData["SEARCH"]();
r.setName( "SEARCHB" );
return r;
}
......
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