diff options
author | Noel Grandin <noel@peralex.com> | 2014-09-28 15:49:26 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2014-10-01 07:34:23 +0000 |
commit | fc04f76336fdf8c96e35382cdeb497e2f939705c (patch) | |
tree | 70c9bbd054a34a9bca9d22bb7afbb9c4349beff0 /tools | |
parent | eb4811590c85895ce531674596bdd6afb3397725 (diff) |
fdo#82577: Handle Time
Put the TOOLS Time class in the tools namespace. Avoids clash with the X11
Time typedef.
Change-Id: Iac57d5aef35e81ace1ee0d5e6d76cb278f8ad866
Reviewed-on: https://gerrit.libreoffice.org/11684
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/datetime/datetime.cxx | 32 | ||||
-rw-r--r-- | tools/source/datetime/datetimeutils.cxx | 2 | ||||
-rw-r--r-- | tools/source/datetime/ttime.cxx | 58 | ||||
-rw-r--r-- | tools/source/inet/inetmsg.cxx | 8 | ||||
-rw-r--r-- | tools/source/rc/rc.cxx | 6 |
5 files changed, 57 insertions, 49 deletions
diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index 3056bf89947b..667eef6efc56 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -30,7 +30,7 @@ bool DateTime::IsBetween( const DateTime& rFrom, const DateTime& rTo ) const bool DateTime::operator >( const DateTime& rDateTime ) const { if ( (Date::operator>( rDateTime )) || - (Date::operator==( rDateTime ) && Time::operator>( rDateTime )) ) + (Date::operator==( rDateTime ) && tools::Time::operator>( rDateTime )) ) return true; else return false; @@ -39,7 +39,7 @@ bool DateTime::operator >( const DateTime& rDateTime ) const bool DateTime::operator <( const DateTime& rDateTime ) const { if ( (Date::operator<( rDateTime )) || - (Date::operator==( rDateTime ) && Time::operator<( rDateTime )) ) + (Date::operator==( rDateTime ) && tools::Time::operator<( rDateTime )) ) return true; else return false; @@ -48,7 +48,7 @@ bool DateTime::operator <( const DateTime& rDateTime ) const bool DateTime::operator >=( const DateTime& rDateTime ) const { if ( (Date::operator>( rDateTime )) || - (Date::operator==( rDateTime ) && Time::operator>=( rDateTime )) ) + (Date::operator==( rDateTime ) && tools::Time::operator>=( rDateTime )) ) return true; else return false; @@ -57,7 +57,7 @@ bool DateTime::operator >=( const DateTime& rDateTime ) const bool DateTime::operator <=( const DateTime& rDateTime ) const { if ( (Date::operator<( rDateTime )) || - (Date::operator==( rDateTime ) && Time::operator<=( rDateTime )) ) + (Date::operator==( rDateTime ) && tools::Time::operator<=( rDateTime )) ) return true; else return false; @@ -78,9 +78,9 @@ long DateTime::GetSecFromDateTime( const Date& rDate ) const } } -DateTime& DateTime::operator +=( const Time& rTime ) +DateTime& DateTime::operator +=( const tools::Time& rTime ) { - Time aTime = *this; + tools::Time aTime = *this; aTime += rTime; sal_uInt16 nHours = aTime.GetHour(); if ( aTime.GetTime() > 0 ) @@ -102,14 +102,14 @@ DateTime& DateTime::operator +=( const Time& rTime ) Date::operator--(); aTime = Time( 24, 0, 0 )+aTime; } - Time::operator=( aTime ); + tools::Time::operator=( aTime ); return *this; } -DateTime& DateTime::operator -=( const Time& rTime ) +DateTime& DateTime::operator -=( const tools::Time& rTime ) { - Time aTime = *this; + tools::Time aTime = *this; aTime -= rTime; sal_uInt16 nHours = aTime.GetHour(); if ( aTime.GetTime() > 0 ) @@ -131,7 +131,7 @@ DateTime& DateTime::operator -=( const Time& rTime ) Date::operator--(); aTime = Time( 24, 0, 0 )+aTime; } - Time::operator=( aTime ); + tools::Time::operator=( aTime ); return *this; } @@ -150,14 +150,14 @@ DateTime operator -( const DateTime& rDateTime, long nDays ) return aDateTime; } -DateTime operator +( const DateTime& rDateTime, const Time& rTime ) +DateTime operator +( const DateTime& rDateTime, const tools::Time& rTime ) { DateTime aDateTime( rDateTime ); aDateTime += rTime; return aDateTime; } -DateTime operator -( const DateTime& rDateTime, const Time& rTime ) +DateTime operator -( const DateTime& rDateTime, const tools::Time& rTime ) { DateTime aDateTime( rDateTime ); aDateTime -= rTime; @@ -180,8 +180,8 @@ DateTime& DateTime::operator +=( double fTimeInDays ) Date::operator+=( long(fInt) ); // full days if ( fFrac ) { - Time aTime(0); // default ctor calls system time, we don't need that - fFrac *= ::Time::nanoSecPerDay; // time expressed in nanoseconds + tools::Time aTime(0); // default ctor calls system time, we don't need that + fFrac *= ::tools::Time::nanoSecPerDay; // time expressed in nanoseconds aTime.MakeTimeFromNS( static_cast<sal_Int64>(fFrac) ); // method handles negative ns operator+=( aTime ); } @@ -202,7 +202,7 @@ double operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 ) if ( nTime ) { double fTime = double(nTime); - fTime /= ::Time::nanoSecPerDay; // convert from nanoseconds to fraction + fTime /= ::tools::Time::nanoSecPerDay; // convert from nanoseconds to fraction if ( nDays < 0 && fTime > 0.0 ) fTime = 1.0 - fTime; return double(nDays) + fTime; @@ -259,7 +259,7 @@ DateTime DateTime::CreateFromWin32FileDateTime( const sal_uInt32 & rLower, const Date _aDate( (sal_uInt16)( nDays + 1 ), nMonths, sal::static_int_cast< sal_uInt16 >(nYears + 1601) ); - Time _aTime( sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 * 60 ) ) % sal_Int64( 24 ) ), + tools::Time _aTime( sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 * 60 ) ) % sal_Int64( 24 ) ), sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 ) ) % sal_Int64( 60 ) ), sal_uIntPtr( ( aTime / ( a100nPerSecond ) ) % sal_Int64( 60 ) ), (aTime % a100nPerSecond) * 100 ); diff --git a/tools/source/datetime/datetimeutils.cxx b/tools/source/datetime/datetimeutils.cxx index 417271c60eee..cc34d8e316e2 100644 --- a/tools/source/datetime/datetimeutils.cxx +++ b/tools/source/datetime/datetimeutils.cxx @@ -57,7 +57,7 @@ OString DateTimeToOString( const DateTime& rDateTime ) OString DateToOString( const Date& rDate ) { - Time aTime( Time::EMPTY ); + tools::Time aTime( tools::Time::EMPTY ); return DateTimeToOString( DateTime( rDate, aTime ) ); } diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx index 66d16b4ce059..d5b83a3ad7de 100644 --- a/tools/source/datetime/ttime.cxx +++ b/tools/source/datetime/ttime.cxx @@ -49,7 +49,7 @@ namespace { const sal_Int16 secInMin = 60; const sal_Int16 minInHour = 60; - sal_Int64 TimeToNanoSec( const Time& rTime ) + sal_Int64 TimeToNanoSec( const tools::Time& rTime ) { short nSign = (rTime.GetTime() >= 0) ? +1 : -1; sal_Int32 nHour = rTime.GetHour(); @@ -65,7 +65,7 @@ namespace { return (nRet * nSign); } - Time NanoSecToTime( sal_Int64 nNanoSec ) + tools::Time NanoSecToTime( sal_Int64 nNanoSec ) { short nSign; if ( nNanoSec < 0 ) @@ -76,13 +76,15 @@ namespace { else nSign = 1; - Time aTime( 0, 0, 0, nNanoSec ); + tools::Time aTime( 0, 0, 0, nNanoSec ); aTime.SetTime( aTime.GetTime() * nSign ); return aTime; } } // anonymous namespace +namespace tools { + Time::Time( TimeInitSystem ) { #if defined( WNT ) @@ -133,7 +135,7 @@ Time::Time( TimeInitSystem ) #endif // WNT } -Time::Time( const Time& rTime ) +Time::Time( const tools::Time& rTime ) { nTime = rTime.nTime; } @@ -146,7 +148,7 @@ Time::Time( const ::com::sun::star::util::Time &_rTime ) { init(_rTime.Hours, _rTime.Minutes, _rTime.Seconds, _rTime.NanoSeconds); } -void Time::init( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec, sal_uInt64 nNanoSec ) +void tools::Time::init( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec, sal_uInt64 nNanoSec ) { // normalize time nSec += nNanoSec / nanoSecInSec; @@ -163,7 +165,7 @@ void Time::init( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec, sal_uInt64 nHour * hourMask; } -void Time::SetHour( sal_uInt16 nNewHour ) +void tools::Time::SetHour( sal_uInt16 nNewHour ) { short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nMin = GetMin(); @@ -177,7 +179,7 @@ void Time::SetHour( sal_uInt16 nNewHour ) nNewHour * hourMask ); } -void Time::SetMin( sal_uInt16 nNewMin ) +void tools::Time::SetMin( sal_uInt16 nNewMin ) { short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); @@ -194,7 +196,7 @@ void Time::SetMin( sal_uInt16 nNewMin ) nHour * hourMask ); } -void Time::SetSec( sal_uInt16 nNewSec ) +void tools::Time::SetSec( sal_uInt16 nNewSec ) { short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); @@ -211,7 +213,7 @@ void Time::SetSec( sal_uInt16 nNewSec ) nHour * hourMask ); } -void Time::SetNanoSec( sal_uInt32 nNewNanoSec ) +void tools::Time::SetNanoSec( sal_uInt32 nNewNanoSec ) { short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); @@ -228,7 +230,7 @@ void Time::SetNanoSec( sal_uInt32 nNewNanoSec ) nHour * hourMask ); } -sal_Int64 Time::GetNSFromTime() const +sal_Int64 tools::Time::GetNSFromTime() const { short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); @@ -243,7 +245,7 @@ sal_Int64 Time::GetNSFromTime() const nHour * (minInHour * secInMin * nanoSecInSec) ); } -void Time::MakeTimeFromNS( sal_Int64 nNS ) +void tools::Time::MakeTimeFromNS( sal_Int64 nNS ) { short nSign; if ( nNS < 0 ) @@ -255,11 +257,11 @@ void Time::MakeTimeFromNS( sal_Int64 nNS ) nSign = 1; // avoid overflow when sal_uIntPtr is 32 bits - Time aTime( 0, 0, nNS/nanoSecInSec, nNS % nanoSecInSec ); + tools::Time aTime( 0, 0, nNS/nanoSecInSec, nNS % nanoSecInSec ); SetTime( aTime.GetTime() * nSign ); } -sal_Int32 Time::GetMSFromTime() const +sal_Int32 tools::Time::GetMSFromTime() const { short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); @@ -274,7 +276,7 @@ sal_Int32 Time::GetMSFromTime() const nHour * 360000 ); } -void Time::MakeTimeFromMS( sal_Int32 nMS ) +void tools::Time::MakeTimeFromMS( sal_Int32 nMS ) { short nSign; if ( nMS < 0 ) @@ -286,11 +288,11 @@ void Time::MakeTimeFromMS( sal_Int32 nMS ) nSign = 1; // avoid overflow when sal_uIntPtr is 32 bits - Time aTime( 0, 0, nMS/1000, (nMS % 1000) * 1000000 ); + tools::Time aTime( 0, 0, nMS/1000, (nMS % 1000) * 1000000 ); SetTime( aTime.GetTime() * nSign ); } -double Time::GetTimeInDays() const +double tools::Time::GetTimeInDays() const { short nSign = (nTime >= 0) ? +1 : -1; double nHour = GetHour(); @@ -301,46 +303,46 @@ double Time::GetTimeInDays() const return (nHour + (nMin / 60) + (nSec / (minInHour * secInMin)) + (nNanoSec / (minInHour * secInMin * nanoSecInSec))) / 24 * nSign; } -Time& Time::operator =( const Time& rTime ) +Time& tools::Time::operator =( const tools::Time& rTime ) { nTime = rTime.nTime; return *this; } -Time& Time::operator +=( const Time& rTime ) +Time& tools::Time::operator +=( const tools::Time& rTime ) { nTime = NanoSecToTime( TimeToNanoSec( *this ) + TimeToNanoSec( rTime ) ).GetTime(); return *this; } -Time& Time::operator -=( const Time& rTime ) +Time& tools::Time::operator -=( const tools::Time& rTime ) { nTime = NanoSecToTime( TimeToNanoSec( *this ) - TimeToNanoSec( rTime ) ).GetTime(); return *this; } -Time operator +( const Time& rTime1, const Time& rTime2 ) +Time operator +( const tools::Time& rTime1, const tools::Time& rTime2 ) { return NanoSecToTime( TimeToNanoSec( rTime1 ) + TimeToNanoSec( rTime2 ) ); } -Time operator -( const Time& rTime1, const Time& rTime2 ) +Time operator -( const tools::Time& rTime1, const tools::Time& rTime2 ) { return NanoSecToTime( TimeToNanoSec( rTime1 ) - TimeToNanoSec( rTime2 ) ); } -bool Time::IsEqualIgnoreNanoSec( const Time& rTime ) const +bool tools::Time::IsEqualIgnoreNanoSec( const tools::Time& rTime ) const { sal_Int32 n1 = (nTime < 0 ? -static_cast<sal_Int32>(GetNanoSec()) : GetNanoSec() ); sal_Int32 n2 = (rTime.nTime < 0 ? -static_cast<sal_Int32>(rTime.GetNanoSec()) : rTime.GetNanoSec() ); return (nTime - n1) == (rTime.nTime - n2); } -Time Time::GetUTCOffset() +Time tools::Time::GetUTCOffset() { #if defined( WNT ) TIME_ZONE_INFORMATION aTimeZone; @@ -351,14 +353,14 @@ Time Time::GetUTCOffset() nTempTime += aTimeZone.StandardBias; else if ( nTimeZoneRet == TIME_ZONE_ID_DAYLIGHT ) nTempTime += aTimeZone.DaylightBias; - Time aTime( 0, (sal_uInt16)abs( nTempTime ) ); + tools::Time aTime( 0, (sal_uInt16)abs( nTempTime ) ); if ( nTempTime > 0 ) aTime = -aTime; return aTime; #else static sal_uIntPtr nCacheTicks = 0; static sal_Int32 nCacheSecOffset = -1; - sal_uIntPtr nTicks = Time::GetSystemTicks(); + sal_uIntPtr nTicks = tools::Time::GetSystemTicks(); time_t nTime; tm aTM; sal_Int32 nLocalTime; @@ -390,14 +392,14 @@ Time Time::GetUTCOffset() } nTempTime = abs( nCacheSecOffset ); - Time aTime( 0, (sal_uInt16)nTempTime ); + tools::Time aTime( 0, (sal_uInt16)nTempTime ); if ( nCacheSecOffset < 0 ) aTime = -aTime; return aTime; #endif } -sal_uIntPtr Time::GetSystemTicks() +sal_uIntPtr tools::Time::GetSystemTicks() { #if defined WNT static LARGE_INTEGER nTicksPerSecond; @@ -425,4 +427,6 @@ sal_uIntPtr Time::GetSystemTicks() #endif } +} /* namespace tools */ + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx index 01b753cf9f8a..3a527124587d 100644 --- a/tools/source/inet/inetmsg.cxx +++ b/tools/source/inet/inetmsg.cxx @@ -224,7 +224,7 @@ INetRFC822Message::~INetRFC822Message() /* ParseDateField and local helper functions. * - * Parses a String in (implied) GMT format into class Date and Time objects. + * Parses a String in (implied) GMT format into class Date and tools::Time objects. * Four formats are accepted: * * [Wkd,] 1*2DIGIT Mon 2*4DIGIT 00:00:00 [GMT] (rfc1123) @@ -335,7 +335,7 @@ bool INetRFC822Message::ParseDateField ( sal_uInt16 nOffset = ParseNumber (aDateField, nIndex); if (nOffset > 0) { - Time aDiff( Time::EMPTY ); + tools::Time aDiff( tools::Time::EMPTY ); aDiff.SetHour (nOffset / 100); aDiff.SetMin (nOffset % 100); aDiff.SetSec (0); @@ -352,7 +352,7 @@ bool INetRFC822Message::ParseDateField ( else if (comphelper::string::isdigitAsciiString(aDateField)) { // Format: delta seconds. - Time aDelta (0); + tools::Time aDelta (0); aDelta.SetTime (aDateField.toInt32() * 100); DateTime aNow( DateTime::SYSTEM ); @@ -977,7 +977,7 @@ bool INetMIMEMessage::EnableAttachChild (INetMessageContainerType eType) { // Generate a unique boundary from current time. sal_Char sTail[16 + 1]; - Time aCurTime( Time::SYSTEM ); + tools::Time aCurTime( tools::Time::SYSTEM ); sal_uInt64 nThis = reinterpret_cast< sal_uIntPtr >( this ); // we can be on a 64bit architecture nThis = ( ( nThis >> 32 ) ^ nThis ) & SAL_MAX_UINT32; sprintf (sTail, "%08X%08X", diff --git a/tools/source/rc/rc.cxx b/tools/source/rc/rc.cxx index 5700f151ee46..a4bd8f269e18 100644 --- a/tools/source/rc/rc.cxx +++ b/tools/source/rc/rc.cxx @@ -39,6 +39,8 @@ void Resource::GetRes( const ResId& rResId ) IncrementRes( sizeof( RSHEADER_TYPE ) ); } +namespace tools { + Time::Time( const ResId& rResId ) { nTime = 0; @@ -59,9 +61,11 @@ Time::Time( const ResId& rResId ) // TODO: when we change the place that writes this binary resource format to match: // SetNanoSec( pResMgr->ReadLong() ); // In the meantime: - SetNanoSec( pResMgr->ReadShort() * ::Time::nanoPerCenti ); + SetNanoSec( pResMgr->ReadShort() * ::tools::Time::nanoPerCenti ); } +} /* namespace tools */ + Date::Date( const ResId& rResId ) : nDate(0) { rResId.SetRT( RSC_DATE ); |