Commit bc2fa027 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@56330 954022d7-b5bf-4e40-9824-e11837661b57
parent dd2300e6
......@@ -274,7 +274,6 @@ function daysInYear( date, basis ){
}
}
cFormulaFunction.DateAndTime = {
'groupName':"DateAndTime",
'DATE':cDATE,
......@@ -361,7 +360,13 @@ cDATE.prototype.Calculate = function ( arg ) {
if ( month == 0 ) {
return this.setCA( new cError( cErrorType.not_numeric ), true );
}
this.value = new cNumber( Math.round( new Date( Date.UTC( year, month - 1, day ) ).getExcelDate() ) )
if ( year == 1900 && month == 2 && day == 29){
this.value = new cNumber( 60 );
}
else{
this.value = new cNumber( Math.round( new Date( Date.UTC( year, month - 1, day ) ).getExcelDate() ) );
}
this.value.numFormat = 14;
this.value.ca = true;
return this.value;
......@@ -1229,7 +1234,7 @@ function cNOW() {
cNOW.prototype = Object.create( cBaseFunction.prototype )
cNOW.prototype.Calculate = function () {
var d = new Date();
this.value = new cNumber( d.getExcelDate() + ( (d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds()) / c_sPerDay ) );
this.value = new cNumber( d.getExcelDate() + (d.getUTCHours() * 60 * 60 + d.getUTCMinutes() * 60 + d.getUTCSeconds()) / c_sPerDay );
this.value.numFormat = 22;
return this.setCA( this.value, true );
}
......@@ -1959,5 +1964,4 @@ cYEARFRAC.prototype.getInfo = function () {
name:this.name,
args:"( start-date , end-date [ , basis ] )"
};
}
}
\ No newline at end of file
......@@ -2547,8 +2547,9 @@ cPOWER.prototype.Calculate = function ( arg ) {
return this.value = arg1;
}
if ( !(arg0 instanceof cNumber) || ( arg1 && !(arg0 instanceof cNumber) ) )
if ( !(arg0 instanceof cNumber) || ( arg1 && !(arg0 instanceof cNumber) ) ){
return this.value = new cError( cErrorType.wrong_value_type );
}
return this.value = powerHelper( arg0.getValue(), arg1.getValue() );
......
......@@ -36,6 +36,13 @@ var cExcelSignificantDigits = 15, //количество цифр в числе
c_sPerDay = 86400,
c_msPerDay = c_sPerDay * 1000;
Date.prototype.excelNullDate1900 = Date.UTC(1899, 11, 30, 0, 0, 0);
Date.prototype.excelNullDate1904 = Date.UTC(1904, 0, 1, 0, 0, 0);
Date.prototype.getExcelNullDate = function(){
return g_bDate1904 ? Date.prototype.excelNullDate1904 : Date.prototype.excelNullDate1900;
}
Date.prototype.isLeapYear = function () {
var y = this.getUTCFullYear();
return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;
......@@ -59,24 +66,35 @@ Date.prototype.truncate = function () {
};
Date.prototype.getExcelDate = function () {
return Math.floor( ( this.getTime() / 1000 - this.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
// return Math.floor( ( this.getTime() / 1000 - this.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
var year = this.getUTCFullYear(), month = this.getUTCMonth(), date = this.getUTCDate(), res;
if(1900 < year || (1900 == year && 1 < month))
res = (Date.UTC(year, month, date, this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()) - this.getExcelNullDate() ) / c_msPerDay;
else if(1900 == year && 1 == month && 29 == date )
res = 60;
else
res = (Date.UTC(year, month, date, this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()) - this.getExcelNullDate() ) / c_msPerDay - 1;
return Math.floor(res);
};
Date.prototype.getDateFromExcel = function ( val ) {
if ( !g_bDate1904 ) {
if ( g_bDate1904 ) {
return new Date( val * c_msPerDay + this.getExcelNullDate() );
}
else {
if ( val < 60 ) {
return new Date( (val - c_DateCorrectConst) * c_msPerDay );
return new Date( val * c_msPerDay + this.getExcelNullDate() );
}
else if ( val === 60 ) {
return new Date( (val - c_DateCorrectConst - 1) * c_msPerDay );
return new Date( Date.UTC( 1900, 1, 29 ) );
}
else {
return new Date( (val - c_DateCorrectConst - 1) * c_msPerDay );
return new Date( val * c_msPerDay + this.getExcelNullDate() );
}
}
else {
return new Date( (val - c_DateCorrectConst) * c_msPerDay );
}
};
Date.prototype.addYears = function ( counts ) {
......@@ -868,7 +886,7 @@ cArea3D.prototype.toString = function () {
var wsFrom = this._wb.getWorksheetById( this.wsFrom ).getName(),
wsTo = this._wb.getWorksheetById( this.wsTo ).getName(),
name = Asc.g_oRangeCache.getActiveRange(this._cells);
name = name ? name : this._cells;
name = name && name.getName ? name.getName() : this._cells;
if ( rx_test_ws_name.test( wsFrom ) && rx_test_ws_name.test( wsTo ) ) {
return (wsFrom !== wsTo ? wsFrom + ":" + wsTo : wsFrom) + "!" + name;
}
......
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