ooo-build r11453 - in trunk: . patches/vba



Author: pflin
Date: Wed Jan 30 05:39:54 2008
New Revision: 11453
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11453&view=rev

Log:
	* patches/vba/n353254-dateserial.diff: Make Date class 
	support signed day, month.



Modified:
   trunk/ChangeLog
   trunk/patches/vba/n353254-dateserial.diff

Modified: trunk/patches/vba/n353254-dateserial.diff
==============================================================================
--- trunk/patches/vba/n353254-dateserial.diff	(original)
+++ trunk/patches/vba/n353254-dateserial.diff	Wed Jan 30 05:39:54 2008
@@ -1,101 +1,108 @@
---- basic/source/runtime/methods.cxx.orig	2008-01-23 17:25:09.000000000 +0800
-+++ basic/source/runtime/methods.cxx	2008-01-23 17:50:48.000000000 +0800
-@@ -1826,19 +1826,94 @@ INT16 implGetDateYear( double aDate )
-     return nRet;
+--- tools/inc/tools/date.hxx.orig	2008-01-30 13:17:26.000000000 +0800
++++ tools/inc/tools/date.hxx	2008-01-30 11:20:30.000000000 +0800
+@@ -67,10 +67,7 @@ public:
+ 					Date( sal_uInt32 _nDate ) { Date::nDate = _nDate; }
+ 					Date( const Date& rDate )
+ 						{ nDate = rDate.nDate; }
+-					Date( USHORT nDay, USHORT nMonth, USHORT nYear )
+-						{ nDate = (   sal_uInt32( nDay   % 100 ) ) +
+-								  ( ( sal_uInt32( nMonth % 100 ) ) * 100 ) +
+-								  ( ( sal_uInt32( nYear  % 10000 ) ) * 10000); }
++					Date( sal_Int32 nDay, sal_Int32 nMonth, USHORT nYear );
+ 
+ 	void			SetDate( sal_uInt32 nNewDate ) { nDate = nNewDate; }
+ 	sal_uInt32		GetDate() const { return nDate; }
+--- tools/source/datetime/tdate.cxx.orig	2008-01-30 13:17:53.000000000 +0800
++++ tools/source/datetime/tdate.cxx	2008-01-30 11:45:50.000000000 +0800
+@@ -186,6 +186,78 @@ Date::Date()
+ #endif
  }
  
-+static USHORT aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,
-+								   31, 31, 30, 31, 30, 31 };
-+
-+
-+BOOL ImpIsLeapYear( USHORT nYear )
++Date::Date( sal_Int32 nDay, sal_Int32 nMonth, USHORT nYear )
 +{
-+	return (((nYear % 4) == 0) && ((nYear % 100) != 0) || ((nYear % 400) == 0));
-+}
-+
-+USHORT ImpDaysInMonth( USHORT nMonth, USHORT nYear )
-+{
-+	if ( nMonth != 2 )
-+		return aDaysInMonth[nMonth-1];
++	if( ( nDay >= 0 && nDay < 100 )
++		&& ( nMonth > 0 && nMonth < 100 ))
++	{
++		nDate = ( sal_uInt32( nDay   % 100 ) ) +
++				( ( sal_uInt32( nMonth % 100 ) ) * 100 ) +
++				( ( sal_uInt32( nYear  % 10000 ) ) * 10000); 
++	}
 +	else
 +	{
-+		if ( ((nYear % 4) == 0) && ((nYear % 100) != 0) ||
-+			 ((nYear % 400) == 0) )
-+			return aDaysInMonth[nMonth-1] + 1;
++		long nDays = DateToDays( 0, 1, nYear );
++		nDays += nDay;
++	
++		// If Month is 0, the result is December of the previous year.
++		// If Month is -1, the result is November of the previous year.
++		// If Month is 13, the result is January of the following year.
++		if( nMonth > 0 )
++		{
++			USHORT nYears = (nMonth-1)/12;
++			for( USHORT i=0; i < nYears; i++ )
++			{
++				nDays += 365;
++				if( ImpIsLeapYear(nYear+i))
++					nDays++;
++			}
++
++			nMonth -= nYears*12;
++			nYear += nYears;
++			for( USHORT j=1; j< nMonth; j++ )
++			{
++				nDays += DaysInMonth(j,nYear);
++			}
++		}
++
++		if( nMonth <= 0 )
++		{
++			nYear--;
++			nMonth *= -1;
++			nMonth++;
++			USHORT nYears = nMonth/12;
++
++			for( USHORT i=0; i < nYears; i++ )
++			{
++				nDays -= 365;
++				if( ImpIsLeapYear(nYear-i))
++					nDays--;
++			}
++
++			nMonth -= nYears * 12;
++			nYear -= nYears;
++			for( USHORT j=12; j > 12-nMonth; j--)
++			{
++				nDays -= DaysInMonth(j, nYear);
++			}
++		}
++
++		if ( nDays > MAX_DAYS )
++			nDate = 31 + (12*100) + (((ULONG)9999)*10000);
++		else if ( nDays <= 0 )
++			nDate = 1 + 100;
 +		else
-+			return aDaysInMonth[nMonth-1];
++		{
++			USHORT nTempDay;
++			USHORT nTempMonth;
++			USHORT nTempYear;
++			DaysToDate( nDays, nTempDay, nTempMonth, nTempYear );
++			nDate = ((ULONG)nTempDay) + (((ULONG)nTempMonth)*100) + (((ULONG)nTempYear)*10000);
++		}
 +	}
 +}
 +
- BOOL implDateSerial( INT16 nYear, INT16 nMonth, INT16 nDay, double& rdRet )
+ // -----------------------------------------------------------------------
+ 
+ void Date::SetDay( USHORT nNewDay )
+--- basic/source/runtime/methods.cxx.orig	2008-01-23 17:25:09.000000000 +0800
++++ basic/source/runtime/methods.cxx	2008-01-30 11:23:48.000000000 +0800
+@@ -1830,9 +1830,7 @@ BOOL implDateSerial( INT16 nYear, INT16 
  {
  	if ( nYear < 100 )
  		nYear += 1900;
 -	if ((nYear < 100 || nYear > 9999)   ||
 -		(nMonth < 1 || nMonth > 12 )	||
 -		(nDay < 1 || nDay > 31 ))
-+	if (nYear < 100 || nYear > 9999)
++	if ((nYear < 100 || nYear > 9999))
  	{
  		StarBASIC::Error( SbERR_BAD_ARGUMENT );
  		return FALSE;
- 	}
- 
--	Date aCurDate( nDay, nMonth, nYear );
-+	// The value of nDay outside the range (1-31) are accepted in Visual Basic;
-+	// Also the value of nMonth outside the range(1-12) are accepted.
-+
-+	// If Day is 0, the result is the last day of the previous month.
-+	// If Day is -1, the result is the penultimate day of the previous month.
-+
-+	Date aCurDate( 0, 1, nYear );
-+
-+	long nDays = nDay;
-+
-+	// If Month is 0, the result is December of the previous year.
-+	// If Month is -1, the result is November of the previous year.
-+	// If Month is 13, the result is January of the following year.
-+	if( nMonth > 0 )
-+	{
-+		USHORT nTemp = (nMonth-1)/12;
-+		for( USHORT i=0; i < nTemp; i++ )
-+		{
-+			nDays += 365;
-+			if( ImpIsLeapYear(nYear+i))
-+				nDays++;
-+		}
-+
-+		nMonth -= nTemp*12;
-+		nYear += nTemp;
-+		for( USHORT j=1; j< nMonth; j++ )
-+		{
-+			nDays += ImpDaysInMonth(j,nYear);
-+		}
-+	}
-+
-+	if( nMonth <= 0 )
-+	{
-+		nYear--;
-+		nMonth *= -1;
-+		nMonth++;
-+		USHORT nTemp = nMonth/12;
-+
-+		for( USHORT i=0; i < nTemp; i++ )
-+		{
-+			nDays -= 365;
-+			if( ImpIsLeapYear(nYear-i))
-+				nDays--;
-+		}
-+
-+		nMonth -= nTemp * 12;
-+		nYear -= nTemp;
-+		for( USHORT j=12; j > 12-nMonth; j--)
-+		{
-+			nDays -= ImpDaysInMonth(j, nYear);
-+		}
-+	}
-+	
-+	aCurDate += nDays;
-+
- 	long nDiffDays = GetDayDiff( aCurDate );
-     rdRet = (double)nDiffDays;
-     return TRUE;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]