diff options
Diffstat (limited to 'tools/source/datetime/tdate.cxx')
-rw-r--r-- | tools/source/datetime/tdate.cxx | 158 |
1 files changed, 79 insertions, 79 deletions
diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx index eca1ab40b49e..fcd739bfda68 100644 --- a/tools/source/datetime/tdate.cxx +++ b/tools/source/datetime/tdate.cxx @@ -54,14 +54,14 @@ struct tm *localtime_r(const time_t *timep, struct tm *buffer); // ======================================================================= -static USHORT aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30, +static sal_uInt16 aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; #define MAX_DAYS 3636532 // ======================================================================= -inline BOOL ImpIsLeapYear( USHORT nYear ) +inline sal_Bool ImpIsLeapYear( sal_uInt16 nYear ) { return ( ( ((nYear % 4) == 0) && ((nYear % 100) != 0) ) || @@ -71,7 +71,7 @@ inline BOOL ImpIsLeapYear( USHORT nYear ) // ----------------------------------------------------------------------- -inline USHORT DaysInMonth( USHORT nMonth, USHORT nYear ) +inline sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear ) { if ( nMonth != 2 ) return aDaysInMonth[nMonth-1]; @@ -86,13 +86,13 @@ inline USHORT DaysInMonth( USHORT nMonth, USHORT nYear ) // ----------------------------------------------------------------------- -long Date::DateToDays( USHORT nDay, USHORT nMonth, USHORT nYear ) +long Date::DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ) { long nDays; - nDays = ((ULONG)nYear-1) * 365; + nDays = ((sal_uIntPtr)nYear-1) * 365; nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400); - for( USHORT i = 1; i < nMonth; i++ ) + for( sal_uInt16 i = 1; i < nMonth; i++ ) nDays += DaysInMonth(i,nYear); nDays += nDay; return nDays; @@ -101,23 +101,23 @@ long Date::DateToDays( USHORT nDay, USHORT nMonth, USHORT nYear ) // ----------------------------------------------------------------------- static void DaysToDate( long nDays, - USHORT& rDay, USHORT& rMonth, USHORT& rYear ) + sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear ) { long nTempDays; long i = 0; - BOOL bCalc; + sal_Bool bCalc; do { nTempDays = (long)nDays; - rYear = (USHORT)((nTempDays / 365) - i); - nTempDays -= ((ULONG)rYear-1) * 365; + rYear = (sal_uInt16)((nTempDays / 365) - i); + nTempDays -= ((sal_uIntPtr)rYear-1) * 365; nTempDays -= ((rYear-1) / 4) - ((rYear-1) / 100) + ((rYear-1) / 400); - bCalc = FALSE; + bCalc = sal_False; if ( nTempDays < 1 ) { i++; - bCalc = TRUE; + bCalc = sal_True; } else { @@ -126,7 +126,7 @@ static void DaysToDate( long nDays, if ( (nTempDays != 366) || !ImpIsLeapYear( rYear ) ) { i--; - bCalc = TRUE; + bCalc = sal_True; } } } @@ -134,12 +134,12 @@ static void DaysToDate( long nDays, while ( bCalc ); rMonth = 1; - while ( (ULONG)nTempDays > DaysInMonth( rMonth, rYear ) ) + while ( (sal_uIntPtr)nTempDays > DaysInMonth( rMonth, rYear ) ) { nTempDays -= DaysInMonth( rMonth, rYear ); rMonth++; } - rDay = (USHORT)nTempDays; + rDay = (sal_uInt16)nTempDays; } // ======================================================================= @@ -151,17 +151,17 @@ Date::Date() DosGetDateTime( &aDateTime ); // Datum zusammenbauen - nDate = ((ULONG)aDateTime.day) + - (((ULONG)aDateTime.month)*100) + - (((ULONG)aDateTime.year)*10000); + nDate = ((sal_uIntPtr)aDateTime.day) + + (((sal_uIntPtr)aDateTime.month)*100) + + (((sal_uIntPtr)aDateTime.year)*10000); #elif defined WNT SYSTEMTIME aDateTime; GetLocalTime( &aDateTime ); // Datum zusammenbauen - nDate = ((ULONG)aDateTime.wDay) + - (((ULONG)aDateTime.wMonth)*100) + - (((ULONG)aDateTime.wYear)*10000); + nDate = ((sal_uIntPtr)aDateTime.wDay) + + (((sal_uIntPtr)aDateTime.wMonth)*100) + + (((sal_uIntPtr)aDateTime.wYear)*10000); #else time_t nTmpTime; struct tm aTime; @@ -172,65 +172,65 @@ Date::Date() // Datum zusammenbauen if ( localtime_r( &nTmpTime, &aTime ) ) { - nDate = ((ULONG)aTime.tm_mday) + - (((ULONG)(aTime.tm_mon+1))*100) + - (((ULONG)(aTime.tm_year+1900))*10000); + nDate = ((sal_uIntPtr)aTime.tm_mday) + + (((sal_uIntPtr)(aTime.tm_mon+1))*100) + + (((sal_uIntPtr)(aTime.tm_year+1900))*10000); } else - nDate = 1 + 100 + (((ULONG)1900)*10000); + nDate = 1 + 100 + (((sal_uIntPtr)1900)*10000); #endif } // ----------------------------------------------------------------------- -void Date::SetDay( USHORT nNewDay ) +void Date::SetDay( sal_uInt16 nNewDay ) { - ULONG nMonth = GetMonth(); - ULONG nYear = GetYear(); + sal_uIntPtr nMonth = GetMonth(); + sal_uIntPtr nYear = GetYear(); - nDate = ((ULONG)(nNewDay%100)) + (nMonth*100) + (nYear*10000); + nDate = ((sal_uIntPtr)(nNewDay%100)) + (nMonth*100) + (nYear*10000); } // ----------------------------------------------------------------------- -void Date::SetMonth( USHORT nNewMonth ) +void Date::SetMonth( sal_uInt16 nNewMonth ) { - ULONG nDay = GetDay(); - ULONG nYear = GetYear(); + sal_uIntPtr nDay = GetDay(); + sal_uIntPtr nYear = GetYear(); - nDate = nDay + (((ULONG)(nNewMonth%100))*100) + (nYear*10000); + nDate = nDay + (((sal_uIntPtr)(nNewMonth%100))*100) + (nYear*10000); } // ----------------------------------------------------------------------- -void Date::SetYear( USHORT nNewYear ) +void Date::SetYear( sal_uInt16 nNewYear ) { - ULONG nDay = GetDay(); - ULONG nMonth = GetMonth(); + sal_uIntPtr nDay = GetDay(); + sal_uIntPtr nMonth = GetMonth(); - nDate = nDay + (nMonth*100) + (((ULONG)(nNewYear%10000))*10000); + nDate = nDay + (nMonth*100) + (((sal_uIntPtr)(nNewYear%10000))*10000); } // ----------------------------------------------------------------------- DayOfWeek Date::GetDayOfWeek() const { - return (DayOfWeek)((ULONG)(DateToDays( GetDay(), GetMonth(), GetYear() )-1) % 7); + return (DayOfWeek)((sal_uIntPtr)(DateToDays( GetDay(), GetMonth(), GetYear() )-1) % 7); } // ----------------------------------------------------------------------- -USHORT Date::GetDayOfYear() const +sal_uInt16 Date::GetDayOfYear() const { - USHORT nDay = GetDay(); - for( USHORT i = 1; i < GetMonth(); i++ ) + sal_uInt16 nDay = GetDay(); + for( sal_uInt16 i = 1; i < GetMonth(); i++ ) nDay = nDay + ::DaysInMonth( i, GetYear() ); // += yields a warning on MSVC, so don't use it return nDay; } // ----------------------------------------------------------------------- -USHORT Date::GetWeekOfYear( DayOfWeek eStartDay, +sal_uInt16 Date::GetWeekOfYear( DayOfWeek eStartDay, sal_Int16 nMinimumNumberOfDaysInWeek ) const { short nWeek; @@ -308,76 +308,76 @@ USHORT Date::GetWeekOfYear( DayOfWeek eStartDay, // == noch gleiche Woche long nTempDays = DateToDays( GetDay(), GetMonth(), GetYear() ); nTempDays += 6 - (GetDayOfWeek()+(7-(short)eStartDay)) % 7; - USHORT nDay; - USHORT nMonth; - USHORT nYear; + sal_uInt16 nDay; + sal_uInt16 nMonth; + sal_uInt16 nYear; DaysToDate( nTempDays, nDay, nMonth, nYear ); nWeek = Date( nDay, nMonth, nYear ).GetWeekOfYear( eStartDay, nMinimumNumberOfDaysInWeek ); } } } - return (USHORT)nWeek; + return (sal_uInt16)nWeek; } // ----------------------------------------------------------------------- -USHORT Date::GetDaysInMonth() const +sal_uInt16 Date::GetDaysInMonth() const { return DaysInMonth( GetMonth(), GetYear() ); } // ----------------------------------------------------------------------- -BOOL Date::IsLeapYear() const +sal_Bool Date::IsLeapYear() const { - USHORT nYear = GetYear(); + sal_uInt16 nYear = GetYear(); return ImpIsLeapYear( nYear ); } // ----------------------------------------------------------------------- -BOOL Date::IsValid() const +sal_Bool Date::IsValid() const { - USHORT nDay = GetDay(); - USHORT nMonth = GetMonth(); - USHORT nYear = GetYear(); + sal_uInt16 nDay = GetDay(); + sal_uInt16 nMonth = GetMonth(); + sal_uInt16 nYear = GetYear(); if ( !nMonth || (nMonth > 12) ) - return FALSE; + return sal_False; if ( !nDay || (nDay > DaysInMonth( nMonth, nYear )) ) - return FALSE; + return sal_False; else if ( nYear <= 1582 ) { if ( nYear < 1582 ) - return FALSE; + return sal_False; else if ( nMonth < 10 ) - return FALSE; + return sal_False; else if ( (nMonth == 10) && (nDay < 15) ) - return FALSE; + return sal_False; } - return TRUE; + return sal_True; } // ----------------------------------------------------------------------- Date& Date::operator +=( long nDays ) { - USHORT nDay; - USHORT nMonth; - USHORT nYear; + sal_uInt16 nDay; + sal_uInt16 nMonth; + sal_uInt16 nYear; long nTempDays = DateToDays( GetDay(), GetMonth(), GetYear() ); nTempDays += nDays; if ( nTempDays > MAX_DAYS ) - nDate = 31 + (12*100) + (((ULONG)9999)*10000); + nDate = 31 + (12*100) + (((sal_uIntPtr)9999)*10000); else if ( nTempDays <= 0 ) nDate = 1 + 100; else { DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((ULONG)nDay) + (((ULONG)nMonth)*100) + (((ULONG)nYear)*10000); + nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); } return *this; @@ -387,20 +387,20 @@ Date& Date::operator +=( long nDays ) Date& Date::operator -=( long nDays ) { - USHORT nDay; - USHORT nMonth; - USHORT nYear; + sal_uInt16 nDay; + sal_uInt16 nMonth; + sal_uInt16 nYear; long nTempDays = DateToDays( GetDay(), GetMonth(), GetYear() ); nTempDays -= nDays; if ( nTempDays > MAX_DAYS ) - nDate = 31 + (12*100) + (((ULONG)9999)*10000); + nDate = 31 + (12*100) + (((sal_uIntPtr)9999)*10000); else if ( nTempDays <= 0 ) nDate = 1 + 100; else { DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((ULONG)nDay) + (((ULONG)nMonth)*100) + (((ULONG)nYear)*10000); + nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); } return *this; @@ -410,16 +410,16 @@ Date& Date::operator -=( long nDays ) Date& Date::operator ++() { - USHORT nDay; - USHORT nMonth; - USHORT nYear; + sal_uInt16 nDay; + sal_uInt16 nMonth; + sal_uInt16 nYear; long nTempDays = DateToDays( GetDay(), GetMonth(), GetYear() ); if ( nTempDays < MAX_DAYS ) { nTempDays++; DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((ULONG)nDay) + (((ULONG)nMonth)*100) + (((ULONG)nYear)*10000); + nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); } return *this; @@ -429,16 +429,16 @@ Date& Date::operator ++() Date& Date::operator --() { - USHORT nDay; - USHORT nMonth; - USHORT nYear; + sal_uInt16 nDay; + sal_uInt16 nMonth; + sal_uInt16 nYear; long nTempDays = DateToDays( GetDay(), GetMonth(), GetYear() ); if ( nTempDays > 1 ) { nTempDays--; DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((ULONG)nDay) + (((ULONG)nMonth)*100) + (((ULONG)nYear)*10000); + nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); } return *this; } @@ -487,9 +487,9 @@ Date operator -( const Date& rDate, long nDays ) long operator -( const Date& rDate1, const Date& rDate2 ) { - ULONG nTempDays1 = Date::DateToDays( rDate1.GetDay(), rDate1.GetMonth(), + sal_uIntPtr nTempDays1 = Date::DateToDays( rDate1.GetDay(), rDate1.GetMonth(), rDate1.GetYear() ); - ULONG nTempDays2 = Date::DateToDays( rDate2.GetDay(), rDate2.GetMonth(), + sal_uIntPtr nTempDays2 = Date::DateToDays( rDate2.GetDay(), rDate2.GetMonth(), rDate2.GetYear() ); return nTempDays1 - nTempDays2; } |