LCOV - code coverage report
Current view: top level - tools/inc/tools - time.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 29 51.7 %
Date: 2012-08-25 Functions: 7 14 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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 _TOOLS_TIME_HXX
      20                 :            : #define _TOOLS_TIME_HXX
      21                 :            : 
      22                 :            : #include "tools/toolsdllapi.h"
      23                 :            : #include <tools/solar.h>
      24                 :            : 
      25                 :            : class ResId;
      26                 :            : 
      27                 :            : /**
      28                 :            :  @WARNING: This class can serve both as call clock time and time duration, and
      29                 :            :            the mixing of these concepts leads to problems such as there being
      30                 :            :            25 hours or 10 minus 20 seconds being (non-negative) 10 seconds.
      31                 :            : */
      32                 :            : 
      33                 :            : class TOOLS_DLLPUBLIC Time
      34                 :            : {
      35                 :            : private:
      36                 :            :     sal_Int32       nTime;
      37                 :            : 
      38                 :            : public:
      39                 :            :     enum TimeInitSystem
      40                 :            :     {
      41                 :            :         SYSTEM
      42                 :            :     };
      43                 :            : 
      44                 :            :     // temporary until all uses are inspected and resolved
      45                 :            :     enum TimeInitEmpty
      46                 :            :     {
      47                 :            :         EMPTY
      48                 :            :     };
      49                 :            : 
      50                 :          0 :                     Time( TimeInitEmpty )
      51                 :          0 :                         { nTime = 0; }
      52                 :            :                     Time( TimeInitSystem );
      53                 :            :                     Time( const ResId & rResId );
      54                 :     155796 :                     Time( sal_Int32 _nTime ) { Time::nTime = _nTime; }
      55                 :            :                     Time( const Time& rTime );
      56                 :            :                     Time( sal_uIntPtr nHour, sal_uIntPtr nMin,
      57                 :            :                           sal_uIntPtr nSec = 0, sal_uIntPtr n100Sec = 0 );
      58                 :            : 
      59                 :        545 :     void            SetTime( sal_Int32 nNewTime ) { nTime = nNewTime; }
      60                 :       2713 :     sal_Int32       GetTime() const { return nTime; }
      61                 :            : 
      62                 :            :     void            SetHour( sal_uInt16 nNewHour );
      63                 :            :     void            SetMin( sal_uInt16 nNewMin );
      64                 :            :     void            SetSec( sal_uInt16 nNewSec );
      65                 :            :     void            Set100Sec( sal_uInt16 nNew100Sec );
      66                 :      11679 :     sal_uInt16      GetHour() const
      67                 :      11679 :                     { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1;
      68                 :      11679 :                       return (sal_uInt16)(nTempTime / 1000000); }
      69                 :      11679 :     sal_uInt16      GetMin() const
      70                 :      11679 :                     { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1;
      71                 :      11679 :                       return (sal_uInt16)((nTempTime / 10000) % 100); }
      72                 :       7792 :     sal_uInt16      GetSec() const
      73                 :       7792 :                     { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1;
      74                 :       7792 :                       return (sal_uInt16)((nTempTime / 100) % 100); }
      75                 :       7768 :     sal_uInt16      Get100Sec() const
      76                 :       7768 :                     { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1;
      77                 :       7768 :                       return (sal_uInt16)(nTempTime % 100); }
      78                 :            : 
      79                 :            :     sal_Int32       GetMSFromTime() const;
      80                 :            :     void            MakeTimeFromMS( sal_Int32 nMS );
      81                 :            : 
      82                 :            :                     /// 12 hours == 0.5 days
      83                 :            :     double          GetTimeInDays() const;
      84                 :            : 
      85                 :            :     sal_Bool        IsBetween( const Time& rFrom, const Time& rTo ) const
      86                 :            :                     { return ((nTime >= rFrom.nTime) && (nTime <= rTo.nTime)); }
      87                 :            : 
      88                 :            :     sal_Bool        IsEqualIgnore100Sec( const Time& rTime ) const;
      89                 :            : 
      90                 :          0 :     sal_Bool        operator ==( const Time& rTime ) const
      91                 :          0 :                     { return (nTime == rTime.nTime); }
      92                 :            :     sal_Bool        operator !=( const Time& rTime ) const
      93                 :            :                     { return (nTime != rTime.nTime); }
      94                 :          0 :     sal_Bool        operator  >( const Time& rTime ) const
      95                 :          0 :                     { return (nTime > rTime.nTime); }
      96                 :          0 :     sal_Bool        operator  <( const Time& rTime ) const
      97                 :          0 :                     { return (nTime < rTime.nTime); }
      98                 :          0 :     sal_Bool        operator >=( const Time& rTime ) const
      99                 :          0 :                     { return (nTime >= rTime.nTime); }
     100                 :          0 :     sal_Bool        operator <=( const Time& rTime ) const
     101                 :          0 :                     { return (nTime <= rTime.nTime); }
     102                 :            : 
     103                 :            :     static Time     GetUTCOffset();
     104                 :            :     static sal_uIntPtr  GetSystemTicks();       // Elapsed time
     105                 :            : 
     106                 :            :     void            ConvertToUTC()       { *this -= Time::GetUTCOffset(); }
     107                 :            :     void            ConvertToLocalTime() { *this += Time::GetUTCOffset(); }
     108                 :            : 
     109                 :            :     Time&           operator =( const Time& rTime );
     110                 :          0 :     Time            operator -() const
     111                 :          0 :                         { return Time( nTime * -1 ); }
     112                 :            :     Time&           operator +=( const Time& rTime );
     113                 :            :     Time&           operator -=( const Time& rTime );
     114                 :            :     TOOLS_DLLPUBLIC friend Time     operator +( const Time& rTime1, const Time& rTime2 );
     115                 :            :     TOOLS_DLLPUBLIC friend Time     operator -( const Time& rTime1, const Time& rTime2 );
     116                 :            : };
     117                 :            : 
     118                 :            : #endif
     119                 :            : 
     120                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10