25#if !defined WIN32_LEAN_AND_MEAN 
   26# define WIN32_LEAN_AND_MEAN 
   37#include <mach/clock.h> 
   39#include <mach/mach_time.h> 
   42#include <rtl/math.hxx> 
   44#include <com/sun/star/util/DateTime.hpp> 
   48#if defined(__sun) && defined(__GNUC__) 
   54    const sal_Int64 nanoSecInSec = 1000000000;
 
   55    const sal_Int16 secInMin     = 60;
 
   56    const sal_Int16 minInHour    = 60;
 
   60        short  nSign   = (rTime.
GetTime() >= 0) ? +1 : -1;
 
   61        sal_Int32   nHour    = rTime.
GetHour();
 
   62        sal_Int32   nMin     = rTime.
GetMin();
 
   63        sal_Int32   nSec     = rTime.
GetSec();
 
   66        sal_Int64 nRet = nNanoSec;
 
   67        nRet     +=            nSec * nanoSecInSec;
 
   68        nRet     +=       nMin * secInMin * nanoSecInSec;
 
   69        nRet     += nHour * minInHour * secInMin * nanoSecInSec;
 
   71        return (nRet * nSign);
 
   86        aTime.SetTime( aTime.GetTime() * nSign );
 
  105Time::Time( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec, sal_uInt64 nNanoSec )
 
  107    init(nHour, nMin, nSec, nNanoSec);
 
  111    init(_rTime.Hours, _rTime.Minutes, _rTime.Seconds, _rTime.NanoSeconds);
 
  115    init(_rDateTime.Hours, _rDateTime.Minutes, _rDateTime.Seconds, _rDateTime.NanoSeconds);
 
  118void tools::Time::init( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec, sal_uInt64 nNanoSec )
 
  121    nSec     += nNanoSec / nanoSecInSec;
 
  122    nNanoSec %= nanoSecInSec;
 
  123    nMin     += nSec / secInMin;
 
  125    nHour    += nMin / minInHour;
 
  130    assert(
HOUR_MASK * nHour >= 0 && 
"use tools::Duration with days instead!");
 
  136    assert(nHour <= 
SAL_MAX_UINT16 && 
"use tools::Duration with days instead!");
 
  149    short  nSign          = (nTime >= 0) ? +1 : -1;
 
  150    sal_Int32   nMin      = GetMin();
 
  151    sal_Int32   nSec      = GetSec();
 
  152    sal_Int32   nNanoSec  = GetNanoSec();
 
  163    short  nSign          = (nTime >= 0) ? +1 : -1;
 
  164    sal_Int32   nHour     = GetHour();
 
  165    sal_Int32   nSec      = GetSec();
 
  166    sal_Int32   nNanoSec  = GetNanoSec();
 
  169    nNewMin = nNewMin % minInHour;
 
  180    short       nSign     = (nTime >= 0) ? +1 : -1;
 
  181    sal_Int32   nHour     = GetHour();
 
  182    sal_Int32   nMin      = GetMin();
 
  183    sal_Int32   nNanoSec   = GetNanoSec();
 
  186    nNewSec = nNewSec % secInMin;
 
  197    short       nSign     = (nTime >= 0) ? +1 : -1;
 
  198    sal_Int32   nHour     = GetHour();
 
  199    sal_Int32   nMin      = GetMin();
 
  200    sal_Int32   nSec      = GetSec();
 
  203    nNewNanoSec = nNewNanoSec % nanoSecInSec;
 
  214    short       nSign     = (nTime >= 0) ? +1 : -1;
 
  215    sal_Int32   nHour     = GetHour();
 
  216    sal_Int32   nMin      = GetMin();
 
  217    sal_Int32   nSec      = GetSec();
 
  218    sal_Int32   nNanoSec  = GetNanoSec();
 
  222             nSec  * nanoSecInSec +
 
  223             nMin  * (secInMin * nanoSecInSec) +
 
  224             nHour * (minInHour * secInMin * nanoSecInSec) );
 
  239    tools::Time aTime( 0, 0, nNS/nanoSecInSec, nNS % nanoSecInSec );
 
  240    SetTime( aTime.
GetTime() * nSign );
 
  245    short       nSign     = (nTime >= 0) ? +1 : -1;
 
  246    sal_Int32   nHour     = GetHour();
 
  247    sal_Int32   nMin      = GetMin();
 
  248    sal_Int32   nSec      = GetSec();
 
  249    sal_Int32   nNanoSec  = GetNanoSec();
 
  270    tools::Time aTime( 0, 0, nMS/1000, (nMS % 1000) * 1000000 );
 
  271    SetTime( aTime.
GetTime() * nSign );
 
  276    short  nSign      = (nTime >= 0) ? +1 : -1;
 
  277    double nHour      = GetHour();
 
  278    double nMin       = GetMin();
 
  279    double nSec       = GetSec();
 
  280    double nNanoSec   = GetNanoSec();
 
  282    return (nHour + (nMin / 60) + (nSec / (minInHour * secInMin)) + (nNanoSec / (minInHour * secInMin * nanoSecInSec))) / 24 * nSign;
 
  287                            sal_uInt16& nHour, sal_uInt16& nMinute, sal_uInt16& nSecond,
 
  288                            double& fFractionOfSecond, 
int nFractionDecimals )
 
  290    const double fTime = fTimeInDays - rtl::math::approxFloor(fTimeInDays); 
 
  299    if (fTime <= 0.0 || fTime >= 1.0)
 
  301        nHour = nMinute = nSecond = 0;
 
  302        fFractionOfSecond = 0.0;
 
  318    const double fAbsTimeInDays = fabs( fTimeInDays);
 
  319    if (fAbsTimeInDays >= 1.0)
 
  321        const int nDig = 
static_cast<int>(ceil( log10( fAbsTimeInDays)));
 
  322        nDec = std::clamp( 10 - nDig, 2, 9 );
 
  324    double fSeconds = rtl::math::round( fRawSeconds, nDec);
 
  329        fSeconds = fRawSeconds;
 
  341    assert(fSeconds < 1.0);     
 
  343    if (nFractionDecimals > 0)
 
  348        fFractionOfSecond = rtl::math::round( fSeconds, nFractionDecimals);
 
  349        if (fFractionOfSecond >= 1.0)
 
  350            fFractionOfSecond = rtl::math::pow10Exp( std::trunc(
 
  351                        rtl::math::pow10Exp( fSeconds, nFractionDecimals)), -nFractionDecimals);
 
  354        fFractionOfSecond = fSeconds;
 
  365    nTime = NanoSecToTime( TimeToNanoSec( *
this ) +
 
  366                           TimeToNanoSec( rTime ) ).
GetTime();
 
  372    nTime = NanoSecToTime( TimeToNanoSec( *
this ) -
 
  373                           TimeToNanoSec( rTime ) ).
GetTime();
 
  379    return NanoSecToTime( TimeToNanoSec( rTime1 ) +
 
  380                          TimeToNanoSec( rTime2 ) );
 
  385    return NanoSecToTime( TimeToNanoSec( rTime1 ) -
 
  386                          TimeToNanoSec( rTime2 ) );
 
  391    sal_Int32 
n1 = (nTime       < 0 ? -
static_cast<sal_Int32
>(GetNanoSec())       : GetNanoSec() );
 
  393    return (nTime - 
n1) == (rTime.
nTime - 
n2);
 
  399    TIME_ZONE_INFORMATION   aTimeZone;
 
  401    DWORD nTimeZoneRet = GetTimeZoneInformation( &aTimeZone );
 
  402    sal_Int32 nTempTime = aTimeZone.Bias;
 
  403    if ( nTimeZoneRet == TIME_ZONE_ID_STANDARD )
 
  404        nTempTime += aTimeZone.StandardBias;
 
  405    else if ( nTimeZoneRet == TIME_ZONE_ID_DAYLIGHT )
 
  406        nTempTime += aTimeZone.DaylightBias;
 
  407    tools::Time aTime( 0, 
static_cast<sal_uInt16
>(
abs( nTempTime )) );
 
  412    static sal_uInt64   nCacheTicks = 0;
 
  413    static sal_Int32    nCacheSecOffset = -1;
 
  420    if ( (nCacheSecOffset == -1)            ||
 
  421         ((nTicks - nCacheTicks) > 360000)  ||
 
  422         ( nTicks < nCacheTicks ) 
 
  425        nTime = time( 
nullptr );
 
  426        localtime_r( &nTime, &aTM );
 
  427        auto nLocalTime = mktime( &aTM );
 
  431        auto nUTC = nLocalTime + ( aTM.tm_isdst == 0 ? timezone : altzone );
 
  432#elif defined( LINUX ) 
  434        auto nUTC = nLocalTime - aTM.tm_gmtoff;
 
  436        gmtime_r( &nTime, &aTM );
 
  437        auto nUTC = mktime( &aTM );
 
  439        nCacheTicks = nTicks;
 
  440        nCacheSecOffset = (nLocalTime-nUTC) / 60;
 
  443    nTempTime = 
abs( nCacheSecOffset );
 
  444    tools::Time aTime( 0, 
static_cast<sal_uInt16
>(nTempTime) );
 
  445    if ( nCacheSecOffset < 0 )
 
  457static LARGE_INTEGER initPerformanceFrequency()
 
  459    LARGE_INTEGER nTicksPerSecond = { 0, 0 };
 
  460    if (!QueryPerformanceFrequency(&nTicksPerSecond))
 
  461        nTicksPerSecond.QuadPart = 0;
 
  462    return nTicksPerSecond;
 
  469    static const LARGE_INTEGER nTicksPerSecond = initPerformanceFrequency();
 
  470    if (nTicksPerSecond.QuadPart > 0)
 
  472        LARGE_INTEGER nPerformanceCount;
 
  473        QueryPerformanceCounter(&nPerformanceCount);
 
  474        return static_cast<sal_uInt64
>(
 
  475            ( nPerformanceCount.QuadPart * 1000 * 1000 ) / nTicksPerSecond.QuadPart );
 
  479        return static_cast<sal_uInt64
>( timeGetTime() * 1000 );
 
  482    sal_uInt64 nMicroSeconds;
 
  484    static mach_timebase_info_data_t info = { 0, 0 };
 
  485    if ( 0 == info.numer )
 
  486        mach_timebase_info( &info );
 
  487    nMicroSeconds = mach_absolute_time() * 
static_cast<double>(info.numer / info.denom) / 1000;
 
  489#if defined(_POSIX_TIMERS) 
  490    struct timespec currentTime;
 
  491    clock_gettime( CLOCK_MONOTONIC, ¤tTime );
 
  493        = 
static_cast<sal_uInt64
>(currentTime.tv_sec) * 1000 * 1000 + currentTime.tv_nsec / 1000;
 
  495    struct timeval currentTime;
 
  496    gettimeofday( ¤tTime, 
nullptr );
 
  497    nMicroSeconds = 
static_cast<sal_uInt64
>(currentTime.tv_sec) * 1000 * 1000 + currentTime.tv_usec;
 
  500    return nMicroSeconds;
 
Degree100 abs(Degree100 x)
 
bool GetSystemDateTime(sal_Int32 *pDate, sal_Int64 *pTime)
Get current local timestamp.
 
constexpr sal_Int64 SEC_MASK
 
constexpr sal_Int64 HOUR_MASK
 
constexpr sal_Int64 MIN_MASK
 
TransliterationModules tm