diff options
-rw-r--r-- | include/tools/date.hxx | 6 | ||||
-rw-r--r-- | tools/source/datetime/tdate.cxx | 49 |
2 files changed, 21 insertions, 34 deletions
diff --git a/include/tools/date.hxx b/include/tools/date.hxx index 22cec9abf78f..ffb425c2a0ff 100644 --- a/include/tools/date.hxx +++ b/include/tools/date.hxx @@ -32,7 +32,7 @@ class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Date { private: sal_uInt32 nDate; - void init( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ) + void setDateFromDMY( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ) { nDate = ( sal_uInt32( nDay % 100 ) ) + ( ( sal_uInt32( nMonth % 100 ) ) * 100 ) + ( ( sal_uInt32( nYear % 10000 ) ) * 10000); } @@ -56,11 +56,11 @@ public: Date( const Date& rDate ) { nDate = rDate.nDate; } Date( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ) - { init(nDay, nMonth, nYear); } + { setDateFromDMY(nDay, nMonth, nYear); } Date( const css::util::Date& _rDate ) { SAL_WARN_IF(_rDate.Year < 0, "tools.datetime", "Negative year in css::util::Date to ::Date conversion"); - init(_rDate.Day, _rDate.Month, _rDate.Year); + setDateFromDMY(_rDate.Day, _rDate.Month, _rDate.Year); } Date( const css::util::DateTime& _rDateTime ); diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx index b957441864f1..811a0fddf1a0 100644 --- a/tools/source/datetime/tdate.cxx +++ b/tools/source/datetime/tdate.cxx @@ -143,9 +143,7 @@ Date::Date( DateInitSystem ) GetLocalTime( &aDateTime ); // Combine to date - nDate = ((sal_uIntPtr)aDateTime.wDay) + - (((sal_uIntPtr)aDateTime.wMonth)*100) + - (((sal_uIntPtr)aDateTime.wYear)*10000); + setDateFromDMY( aDateTime.wDay, aDateTime.wMonth, aDateTime.wYear ); #else time_t nTmpTime; struct tm aTime; @@ -156,42 +154,33 @@ Date::Date( DateInitSystem ) // compute date if ( localtime_r( &nTmpTime, &aTime ) ) { - nDate = ((sal_uIntPtr)aTime.tm_mday) + - (((sal_uIntPtr)(aTime.tm_mon+1))*100) + - (((sal_uIntPtr)(aTime.tm_year+1900))*10000); + setDateFromDMY( static_cast<sal_uInt16>(aTime.tm_mday), + static_cast<sal_uInt16>(aTime.tm_mon+1), + static_cast<sal_uInt16>(aTime.tm_year+1900) ); } else - nDate = 1 + 100 + (((sal_uIntPtr)1900)*10000); + setDateFromDMY( 1, 100, 1900 ); #endif } Date::Date( const ::com::sun::star::util::DateTime& rDateTime ) { - init( rDateTime.Day, rDateTime.Month, rDateTime.Year ); + setDateFromDMY( rDateTime.Day, rDateTime.Month, rDateTime.Year ); } void Date::SetDay( sal_uInt16 nNewDay ) { - sal_uIntPtr nMonth = GetMonth(); - sal_uIntPtr nYear = GetYear(); - - nDate = ((sal_uIntPtr)(nNewDay%100)) + (nMonth*100) + (nYear*10000); + setDateFromDMY( nNewDay, GetMonth(), GetYear() ); } void Date::SetMonth( sal_uInt16 nNewMonth ) { - sal_uIntPtr nDay = GetDay(); - sal_uIntPtr nYear = GetYear(); - - nDate = nDay + (((sal_uIntPtr)(nNewMonth%100))*100) + (nYear*10000); + setDateFromDMY( GetDay(), nNewMonth, GetYear() ); } void Date::SetYear( sal_uInt16 nNewYear ) { - sal_uIntPtr nDay = GetDay(); - sal_uIntPtr nMonth = GetMonth(); - - nDate = nDay + (nMonth*100) + (((sal_uIntPtr)(nNewYear%10000))*10000); + setDateFromDMY( GetDay(), GetMonth(), nNewYear ); } DayOfWeek Date::GetDayOfWeek() const @@ -364,9 +353,7 @@ bool Date::Normalize() if (!Normalize( nDay, nMonth, nYear)) return false; - SetDay( nDay); - SetMonth( nMonth); - SetYear( nYear); + setDateFromDMY( nDay, nMonth, nYear ); return true; } @@ -433,13 +420,13 @@ Date& Date::operator +=( long nDays ) nTempDays += nDays; if ( nTempDays > MAX_DAYS ) - nDate = 31 + (12*100) + (((sal_uIntPtr)9999)*10000); + setDateFromDMY( 31, 12, 9999 ); else if ( nTempDays <= 0 ) - nDate = 1 + 100; + setDateFromDMY( 1, 100, 0 ); else { DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); + setDateFromDMY( nDay, nMonth, nYear ); } return *this; @@ -458,13 +445,13 @@ Date& Date::operator -=( long nDays ) nTempDays -= nDays; if ( nTempDays > MAX_DAYS ) - nDate = 31 + (12*100) + (((sal_uIntPtr)9999)*10000); + setDateFromDMY( 31, 12, 9999 ); else if ( nTempDays <= 0 ) - nDate = 1 + 100; + setDateFromDMY( 1, 100, 0 ); else { DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); + setDateFromDMY( nDay, nMonth, nYear ); } return *this; @@ -481,7 +468,7 @@ Date& Date::operator ++() { nTempDays++; DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); + setDateFromDMY( nDay, nMonth, nYear ); } return *this; @@ -498,7 +485,7 @@ Date& Date::operator --() { nTempDays--; DaysToDate( nTempDays, nDay, nMonth, nYear ); - nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); + setDateFromDMY( nDay, nMonth, nYear ); } return *this; } |