LCOV - code coverage report
Current view: top level - include/tools - time.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 31 33 93.9 %
Date: 2014-04-11 Functions: 17 18 94.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef INCLUDED_TOOLS_TIME_HXX
      20             : #define INCLUDED_TOOLS_TIME_HXX
      21             : 
      22             : #include <tools/toolsdllapi.h>
      23             : #include <tools/solar.h>
      24             : #include <com/sun/star/util/Time.hpp>
      25             : 
      26             : class ResId;
      27             : 
      28             : /**
      29             :  @WARNING: This class can serve both as wall clock time and time duration, and
      30             :            the mixing of these concepts leads to problems such as there being
      31             :            25 hours or 10 minus 20 seconds being (non-negative) 10 seconds.
      32             : */
      33             : 
      34             : class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Time
      35             : {
      36             : private:
      37             :     sal_Int64       nTime;
      38             :     void            init( sal_uInt32 nHour, sal_uInt32 nMin,
      39             :                           sal_uInt32 nSec, sal_uInt64 nNanoSec);
      40             : 
      41             : public:
      42             :     enum TimeInitSystem
      43             :     {
      44             :         SYSTEM
      45             :     };
      46             : 
      47             :     // temporary until all uses are inspected and resolved
      48             :     enum TimeInitEmpty
      49             :     {
      50             :         EMPTY
      51             :     };
      52             :     static const sal_Int64 hourPerDay = 24;
      53             :     static const sal_Int64 minutePerHour = 60;
      54             :     static const sal_Int64 secondPerMinute = 60;
      55             :     static const sal_Int64 nanoSecPerSec = 1000000000;
      56             :     static const sal_Int64 nanoSecPerMinute = nanoSecPerSec * secondPerMinute;
      57             :     static const sal_Int64 nanoSecPerHour = nanoSecPerSec * secondPerMinute * minutePerHour;
      58             :     static const sal_Int64 nanoSecPerDay = nanoSecPerSec * secondPerMinute * minutePerHour * hourPerDay;
      59             :     static const sal_Int64 secondPerHour = secondPerMinute * minutePerHour;
      60             :     static const sal_Int64 secondPerDay  = secondPerMinute * minutePerHour * hourPerDay;
      61             :     static const sal_Int64 minutePerDay  = minutePerHour * hourPerDay;
      62             :     static const sal_Int64 nanoPerMicro  = 1000;
      63             :     static const sal_Int64 nanoPerMilli  = 1000000;
      64             :     static const sal_Int64 nanoPerCenti  = 10000000;
      65             : 
      66       43262 :                     Time( TimeInitEmpty )
      67       43262 :                         { nTime = 0; }
      68             :                     Time( TimeInitSystem );
      69             :                     Time( const ResId & rResId );
      70        2061 :                     Time( sal_Int64 _nTime ) { Time::nTime = _nTime; }
      71             :                     Time( const Time& rTime );
      72             :                     Time( const ::com::sun::star::util::Time& rTime );
      73             :                     Time( sal_uInt32 nHour, sal_uInt32 nMin,
      74             :                           sal_uInt32 nSec = 0, sal_uInt64 nNanoSec = 0 );
      75             : 
      76         358 :     void            SetTime( sal_Int64 nNewTime ) { nTime = nNewTime; }
      77        2012 :     sal_Int64       GetTime() const { return nTime; }
      78          18 :     ::com::sun::star::util::Time GetUNOTime() const { return ::com::sun::star::util::Time(GetNanoSec(),GetSec(),GetMin(),GetHour(),false); }
      79             : 
      80             :     void            SetHour( sal_uInt16 nNewHour );
      81             :     void            SetMin( sal_uInt16 nNewMin );
      82             :     void            SetSec( sal_uInt16 nNewSec );
      83             :     void            SetNanoSec( sal_uInt32 nNewNanoSec );
      84        9254 :     sal_uInt16      GetHour() const
      85        9254 :                     { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime;
      86        9254 :                       return static_cast<sal_uInt16>(nTempTime / SAL_CONST_UINT64(10000000000000)); }
      87        9154 :     sal_uInt16      GetMin() const
      88        9154 :                     { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime;
      89        9154 :                       return static_cast<sal_uInt16>((nTempTime / SAL_CONST_UINT64(100000000000)) % 100); }
      90        7342 :     sal_uInt16      GetSec() const
      91        7342 :                     { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime;
      92        7342 :                       return static_cast<sal_uInt16>((nTempTime / SAL_CONST_UINT64(1000000000)) % 100); }
      93        7152 :     sal_uInt32      GetNanoSec() const
      94        7152 :                     { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime;
      95        7152 :                       return static_cast<sal_uInt32>( nTempTime % SAL_CONST_UINT64(1000000000)); }
      96             : 
      97             :     // TODO: consider removing GetMSFromTime and MakeTimeFromMS?
      98             :     sal_Int32       GetMSFromTime() const;
      99             :     void            MakeTimeFromMS( sal_Int32 nMS );
     100             :     sal_Int64       GetNSFromTime() const;
     101             :     void            MakeTimeFromNS( sal_Int64 nNS );
     102             : 
     103             :                     /// 12 hours == 0.5 days
     104             :     double          GetTimeInDays() const;
     105             : 
     106             :     bool            IsBetween( const Time& rFrom, const Time& rTo ) const
     107             :                     { return ((nTime >= rFrom.nTime) && (nTime <= rTo.nTime)); }
     108             : 
     109             :     bool            IsEqualIgnoreNanoSec( const Time& rTime ) const;
     110             : 
     111         945 :     bool            operator ==( const Time& rTime ) const
     112         945 :                     { return (nTime == rTime.nTime); }
     113          65 :     bool            operator !=( const Time& rTime ) const
     114          65 :                     { return (nTime != rTime.nTime); }
     115         249 :     bool            operator  >( const Time& rTime ) const
     116         249 :                     { return (nTime > rTime.nTime); }
     117         281 :     bool            operator  <( const Time& rTime ) const
     118         281 :                     { return (nTime < rTime.nTime); }
     119          11 :     bool            operator >=( const Time& rTime ) const
     120          11 :                     { return (nTime >= rTime.nTime); }
     121           0 :     bool            operator <=( const Time& rTime ) const
     122           0 :                     { return (nTime <= rTime.nTime); }
     123             : 
     124             :     static Time     GetUTCOffset();
     125             :     static sal_uIntPtr  GetSystemTicks();       // Elapsed time
     126             : 
     127             :     void            ConvertToUTC()       { *this -= Time::GetUTCOffset(); }
     128             :     void            ConvertToLocalTime() { *this += Time::GetUTCOffset(); }
     129             : 
     130             :     Time&           operator =( const Time& rTime );
     131           2 :     Time            operator -() const
     132           2 :                         { return Time( -nTime ); }
     133             :     Time&           operator +=( const Time& rTime );
     134             :     Time&           operator -=( const Time& rTime );
     135             :     TOOLS_DLLPUBLIC friend Time     operator +( const Time& rTime1, const Time& rTime2 );
     136             :     TOOLS_DLLPUBLIC friend Time     operator -( const Time& rTime1, const Time& rTime2 );
     137         177 : };
     138             : 
     139             : #endif
     140             : 
     141             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10