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



Author: pflin
Date: Thu Jan 31 05:22:02 2008
New Revision: 11476
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11476&view=rev

Log:
	* patches/vba/n353254-dateserial.diff: modified by Noel's trick 



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	Thu Jan 31 05:22:02 2008
@@ -1,101 +1,6 @@
---- 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
- }
- 
-+Date::Date( sal_Int32 nDay, sal_Int32 nMonth, USHORT nYear )
-+{
-+	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
-+	{
-+		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
-+		{
-+			USHORT nTempDay;
-+			USHORT nTempMonth;
-+			USHORT nTempYear;
-+			DaysToDate( nDays, nTempDay, nTempMonth, nTempYear );
-+			nDate = ((ULONG)nTempDay) + (((ULONG)nTempMonth)*100) + (((ULONG)nTempYear)*10000);
-+		}
-+	}
-+}
-+
- // -----------------------------------------------------------------------
- 
- 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 
++++ basic/source/runtime/methods.cxx	2008-01-31 10:29:31.000000000 +0800
+@@ -1830,15 +1830,36 @@ BOOL implDateSerial( INT16 nYear, INT16 
  {
  	if ( nYear < 100 )
  		nYear += 1900;
@@ -106,3 +11,33 @@
  	{
  		StarBASIC::Error( SbERR_BAD_ARGUMENT );
  		return FALSE;
+ 	}
+ 
+-	Date aCurDate( nDay, nMonth, nYear );
++	// grab the year & month
++	Date aCurDate( 1, (( nMonth % 12 ) > 0 ) ? ( nMonth % 12 ) : 12 + ( nMonth % 12 ), nYear );
++	
++	// adjust year based on month value
++	// e.g. 2000, 0, xx = 1999, 12, xx ( or December of the previous year )
++	//		2000, 13, xx = 2001, 1, xx ( or January of the following year )
++	if( ( nMonth < 1 ) || ( nMonth > 12 ) )
++	{
++		// inacurrate around leap year, don't use days to calculate,
++		// just modify the months directory
++		INT16 nYearAdj = ( nMonth /12 ); // default to positive months inputed
++		if ( nMonth <=0 )
++			nYearAdj = ( ( nMonth -12 ) / 12 );
++		aCurDate.SetYear( aCurDate.GetYear() + nYearAdj );
++	}
++
++	// adjust day value,
++	// e.g. 2000, 2, 0 = 2000, 1, 31 or the last day of the previous month
++	//		2000, 1, 32 = 2000, 2, 1 or the first day of the following month
++	if( ( nDay < 1 ) || ( nDay > aCurDate.GetDaysInMonth() ) )
++		aCurDate += nDay - 1;
++	else
++		aCurDate.SetDay( nDay );
++	
+ 	long nDiffDays = GetDayDiff( aCurDate );
+     rdRet = (double)nDiffDays;
+     return TRUE;



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