summaryrefslogtreecommitdiff
path: root/tools/source/datetime/ttime.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/source/datetime/ttime.cxx')
-rw-r--r--tools/source/datetime/ttime.cxx25
1 files changed, 19 insertions, 6 deletions
diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx
index c6c89c934886..fcfa2e080e99 100644
--- a/tools/source/datetime/ttime.cxx
+++ b/tools/source/datetime/ttime.cxx
@@ -125,6 +125,18 @@ void tools::Time::init( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec, sal_
nHour += nMin / minInHour;
nMin %= minInHour;
+ // 922337 * HOUR_MASK = 9223370000000000000 largest possible value, 922338
+ // would be -9223364073709551616.
+ assert(HOUR_MASK * nHour >= 0 && "use tools::Duration with days instead!");
+ if (HOUR_MASK * nHour < 0)
+ nHour = 922337;
+
+ // But as is, GetHour() retrieves only sal_uInt16. Though retrieving in
+ // nanoseconds or milliseconds might be possible this is all crap.
+ assert(nHour <= SAL_MAX_UINT16 && "use tools::Duration with days instead!");
+ if (nHour > SAL_MAX_UINT16)
+ nHour = SAL_MAX_UINT16;
+
// construct time
nTime = nNanoSec +
nSec * SEC_MASK +
@@ -412,17 +424,17 @@ Time tools::Time::GetUTCOffset()
{
nTime = time( nullptr );
localtime_r( &nTime, &aTM );
- sal_Int32 nLocalTime = mktime( &aTM );
+ auto nLocalTime = mktime( &aTM );
#if defined(__sun)
// Solaris gmtime_r() seems not to handle daylight saving time
// flags correctly
- nUTC = nLocalTime + ( aTM.tm_isdst == 0 ? timezone : altzone );
+ auto nUTC = nLocalTime + ( aTM.tm_isdst == 0 ? timezone : altzone );
#elif defined( LINUX )
// Linux mktime() seems not to handle tm_isdst correctly
- sal_Int32 nUTC = nLocalTime - aTM.tm_gmtoff;
+ auto nUTC = nLocalTime - aTM.tm_gmtoff;
#else
gmtime_r( &nTime, &aTM );
- sal_Int32 nUTC = mktime( &aTM );
+ auto nUTC = mktime( &aTM );
#endif
nCacheTicks = nTicks;
nCacheSecOffset = (nLocalTime-nUTC) / 60;
@@ -477,11 +489,12 @@ sal_uInt64 tools::Time::GetMonotonicTicks()
#if defined(_POSIX_TIMERS)
struct timespec currentTime;
clock_gettime( CLOCK_MONOTONIC, &currentTime );
- nMicroSeconds = currentTime.tv_sec * 1000 * 1000 + currentTime.tv_nsec / 1000;
+ nMicroSeconds
+ = static_cast<sal_uInt64>(currentTime.tv_sec) * 1000 * 1000 + currentTime.tv_nsec / 1000;
#else
struct timeval currentTime;
gettimeofday( &currentTime, nullptr );
- nMicroSeconds = currentTime.tv_sec * 1000 * 1000 + currentTime.tv_usec;
+ nMicroSeconds = static_cast<sal_uInt64>(currentTime.tv_sec) * 1000 * 1000 + currentTime.tv_usec;
#endif
#endif // __MACH__
return nMicroSeconds;