Kaydet (Commit) a3de32ac authored tarafından Matteo Casalin's avatar Matteo Casalin

Rename (private) Date::init and reuse it

Change-Id: I3123876860cf6cce1e16c8f516f3d08fa7e15d83
üst 24c28ac7
...@@ -32,7 +32,7 @@ class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Date ...@@ -32,7 +32,7 @@ class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Date
{ {
private: private:
sal_uInt32 nDate; 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 ) ) + { nDate = ( sal_uInt32( nDay % 100 ) ) +
( ( sal_uInt32( nMonth % 100 ) ) * 100 ) + ( ( sal_uInt32( nMonth % 100 ) ) * 100 ) +
( ( sal_uInt32( nYear % 10000 ) ) * 10000); } ( ( sal_uInt32( nYear % 10000 ) ) * 10000); }
...@@ -56,11 +56,11 @@ public: ...@@ -56,11 +56,11 @@ public:
Date( const Date& rDate ) Date( const Date& rDate )
{ nDate = rDate.nDate; } { nDate = rDate.nDate; }
Date( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ) Date( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear )
{ init(nDay, nMonth, nYear); } { setDateFromDMY(nDay, nMonth, nYear); }
Date( const css::util::Date& _rDate ) Date( const css::util::Date& _rDate )
{ {
SAL_WARN_IF(_rDate.Year < 0, "tools.datetime", "Negative year in css::util::Date to ::Date conversion"); 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 ); Date( const css::util::DateTime& _rDateTime );
......
...@@ -143,9 +143,7 @@ Date::Date( DateInitSystem ) ...@@ -143,9 +143,7 @@ Date::Date( DateInitSystem )
GetLocalTime( &aDateTime ); GetLocalTime( &aDateTime );
// Combine to date // Combine to date
nDate = ((sal_uIntPtr)aDateTime.wDay) + setDateFromDMY( aDateTime.wDay, aDateTime.wMonth, aDateTime.wYear );
(((sal_uIntPtr)aDateTime.wMonth)*100) +
(((sal_uIntPtr)aDateTime.wYear)*10000);
#else #else
time_t nTmpTime; time_t nTmpTime;
struct tm aTime; struct tm aTime;
...@@ -156,42 +154,33 @@ Date::Date( DateInitSystem ) ...@@ -156,42 +154,33 @@ Date::Date( DateInitSystem )
// compute date // compute date
if ( localtime_r( &nTmpTime, &aTime ) ) if ( localtime_r( &nTmpTime, &aTime ) )
{ {
nDate = ((sal_uIntPtr)aTime.tm_mday) + setDateFromDMY( static_cast<sal_uInt16>(aTime.tm_mday),
(((sal_uIntPtr)(aTime.tm_mon+1))*100) + static_cast<sal_uInt16>(aTime.tm_mon+1),
(((sal_uIntPtr)(aTime.tm_year+1900))*10000); static_cast<sal_uInt16>(aTime.tm_year+1900) );
} }
else else
nDate = 1 + 100 + (((sal_uIntPtr)1900)*10000); setDateFromDMY( 1, 100, 1900 );
#endif #endif
} }
Date::Date( const ::com::sun::star::util::DateTime& rDateTime ) 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 ) void Date::SetDay( sal_uInt16 nNewDay )
{ {
sal_uIntPtr nMonth = GetMonth(); setDateFromDMY( nNewDay, GetMonth(), GetYear() );
sal_uIntPtr nYear = GetYear();
nDate = ((sal_uIntPtr)(nNewDay%100)) + (nMonth*100) + (nYear*10000);
} }
void Date::SetMonth( sal_uInt16 nNewMonth ) void Date::SetMonth( sal_uInt16 nNewMonth )
{ {
sal_uIntPtr nDay = GetDay(); setDateFromDMY( GetDay(), nNewMonth, GetYear() );
sal_uIntPtr nYear = GetYear();
nDate = nDay + (((sal_uIntPtr)(nNewMonth%100))*100) + (nYear*10000);
} }
void Date::SetYear( sal_uInt16 nNewYear ) void Date::SetYear( sal_uInt16 nNewYear )
{ {
sal_uIntPtr nDay = GetDay(); setDateFromDMY( GetDay(), GetMonth(), nNewYear );
sal_uIntPtr nMonth = GetMonth();
nDate = nDay + (nMonth*100) + (((sal_uIntPtr)(nNewYear%10000))*10000);
} }
DayOfWeek Date::GetDayOfWeek() const DayOfWeek Date::GetDayOfWeek() const
...@@ -364,9 +353,7 @@ bool Date::Normalize() ...@@ -364,9 +353,7 @@ bool Date::Normalize()
if (!Normalize( nDay, nMonth, nYear)) if (!Normalize( nDay, nMonth, nYear))
return false; return false;
SetDay( nDay); setDateFromDMY( nDay, nMonth, nYear );
SetMonth( nMonth);
SetYear( nYear);
return true; return true;
} }
...@@ -433,13 +420,13 @@ Date& Date::operator +=( long nDays ) ...@@ -433,13 +420,13 @@ Date& Date::operator +=( long nDays )
nTempDays += nDays; nTempDays += nDays;
if ( nTempDays > MAX_DAYS ) if ( nTempDays > MAX_DAYS )
nDate = 31 + (12*100) + (((sal_uIntPtr)9999)*10000); setDateFromDMY( 31, 12, 9999 );
else if ( nTempDays <= 0 ) else if ( nTempDays <= 0 )
nDate = 1 + 100; setDateFromDMY( 1, 100, 0 );
else else
{ {
DaysToDate( nTempDays, nDay, nMonth, nYear ); DaysToDate( nTempDays, nDay, nMonth, nYear );
nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); setDateFromDMY( nDay, nMonth, nYear );
} }
return *this; return *this;
...@@ -458,13 +445,13 @@ Date& Date::operator -=( long nDays ) ...@@ -458,13 +445,13 @@ Date& Date::operator -=( long nDays )
nTempDays -= nDays; nTempDays -= nDays;
if ( nTempDays > MAX_DAYS ) if ( nTempDays > MAX_DAYS )
nDate = 31 + (12*100) + (((sal_uIntPtr)9999)*10000); setDateFromDMY( 31, 12, 9999 );
else if ( nTempDays <= 0 ) else if ( nTempDays <= 0 )
nDate = 1 + 100; setDateFromDMY( 1, 100, 0 );
else else
{ {
DaysToDate( nTempDays, nDay, nMonth, nYear ); DaysToDate( nTempDays, nDay, nMonth, nYear );
nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); setDateFromDMY( nDay, nMonth, nYear );
} }
return *this; return *this;
...@@ -481,7 +468,7 @@ Date& Date::operator ++() ...@@ -481,7 +468,7 @@ Date& Date::operator ++()
{ {
nTempDays++; nTempDays++;
DaysToDate( nTempDays, nDay, nMonth, nYear ); DaysToDate( nTempDays, nDay, nMonth, nYear );
nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); setDateFromDMY( nDay, nMonth, nYear );
} }
return *this; return *this;
...@@ -498,7 +485,7 @@ Date& Date::operator --() ...@@ -498,7 +485,7 @@ Date& Date::operator --()
{ {
nTempDays--; nTempDays--;
DaysToDate( nTempDays, nDay, nMonth, nYear ); DaysToDate( nTempDays, nDay, nMonth, nYear );
nDate = ((sal_uIntPtr)nDay) + (((sal_uIntPtr)nMonth)*100) + (((sal_uIntPtr)nYear)*10000); setDateFromDMY( nDay, nMonth, nYear );
} }
return *this; return *this;
} }
......
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