Commit 96bce91c authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

переделан алгоритм получения доли года.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56270 954022d7-b5bf-4e40-9824-e11837661b57
parent 5b3c6224
......@@ -209,6 +209,52 @@ function GetDiffDate( d1, d2, nMode ) {
return (bNeg ? -nRet : nRet) / c_msPerDay / pOptDaysIn1stYear;
}
function days360( date1, date2, flag ){
var sign;
var nY1 = date1.getUTCFullYear(), nM1 = date1.getUTCMonth()+1, nD1 = date1.getUTCDate(),
nY2 = date2.getUTCFullYear(), nM2 = date2.getUTCMonth()+1, nD2 = date2.getUTCDate();
if (flag && (date2 < date1))
{
sign = date1;
date1 = date2;
date2 = sign;
sign = -1.0;
}
else
sign = 1.0;
if (nD1 == 31)
nD1 -= 1;
else if (!flag)
{
if (nM1 == 2)
{
switch ( nD1 )
{
case 28 :
if ( !date1.isLeapYear() )
nD1 = 30;
break;
case 29 :
nD1 = 30;
break;
}
}
}
if (nD2 == 31)
{
if (!flag )
{
if (nD1 == 30)
nD2--;
}
else
nD2 = 30;
}
return sign * ( nD2 - nD1 + ( nM2 - nM1 )* 30.0 + ( nY2 - nY1 ) * 360.0 ) ;
}
cFormulaFunction.DateAndTime = {
'groupName':"DateAndTime",
'DATE':cDATE,
......@@ -611,8 +657,7 @@ cDAYS360.prototype.Calculate = function ( arg ) {
var date1 = Date.prototype.getDateFromExcel( arg0.getValue() ), date2 = Date.prototype.getDateFromExcel( arg1.getValue() );
return this.value = new cNumber( GetDiffDate360( date1.getUTCDate(), date1.getUTCMonth() + 1, date1.getUTCFullYear(), date1.isLeapYear(),
date2.getUTCDate(), date2.getUTCMonth() + 1, date2.getUTCFullYear(), !arg2.toBool() ) )
return this.value = new cNumber( days360( date1, date2, arg2.toBool() ) );
}
cDAYS360.prototype.getInfo = function () {
......
......@@ -134,6 +134,23 @@ Math.fact = function ( n ) {
return res;
};
Math.doubleFact = function ( n ) {
var res = 1;
n = this.floor( n );
if ( n < 0 ) {
return NaN;
}
else if ( n > 170 ) {
return Infinity;
}
// n = Math.floor((n+1)/2);
while ( n > 0 ) {
res *= n;
n-=2;
}
return res;
};
Math.factor = function ( n ) {
var res = 1;
n = this.floor( n );
......@@ -3837,26 +3854,44 @@ function matching( x, y, oper ) {
}
function GetDiffDate360( nDay1, nMonth1, nYear1, bLeapYear1, nDay2, nMonth2, nYear2, bUSAMethod ) {
if ( nDay1 == 31 )
nDay1--;
else if ( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 && !bLeapYear1 ) ) ) )
nDay1 = 30;
var nDayDiff;
var startTime = new Date( nYear1, nMonth1-1, nDay1 ),
endTime = new Date( nYear2, nMonth2-1, nDay2 ),
nY, nM, nD;
if ( nDay2 == 31 ) {
if ( bUSAMethod && nDay1 != 30 ) {
nDay2 = 1;
if ( nMonth2 == 12 ) {
nYear2++;
nMonth2 = 1;
if( startTime > endTime ){
nY = nYear1;nYear1 = nYear2; nYear2 = nY;
nM = nMonth1;nMonth1 = nMonth2; nMonth2 = nM;
nD = nDay1;nDay1 = nDay2; nDay2 = nD;
}
else
nMonth2++;
if ( bUSAMethod ) {
if ( nDay1 == 31 ) {
nDay1--;
}
else
if ( nDay1 == 30 && nDay2 == 31 ) {
nDay2--;
}
else {
if ( nMonth1 == 2 && nDay1 == ( new Date(nYear1, 0, 1).isLeapYear() ? 29 : 28 ) ) {
nDay1 = 30;
if ( nMonth2 == 2 && nDay2 == ( new Date(nYear2, 0, 1).isLeapYear() ? 29 : 28 ) ) {
nDay2 = 30;
}
return ( nDay2 - nDay1 ) + ( nMonth2 - nMonth1 ) * 30 + ( nYear2 - nYear1 ) * 360;
}
}
nDayDiff = ( nYear2 - nYear1 ) * 360 + ( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );
}
else {
if ( nDay1 == 31 ) {
nDay1--;
}
if ( nDay2 == 31 ) {
nDay2--;
}
nDayDiff = ( nYear2 - nYear1 ) * 360 + ( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );
}
return nDayDiff;
}
function searchRegExp( str, flags ) {
......
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