1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _TOOLS_TIME_HXX 24 #define _TOOLS_TIME_HXX 25 26 #include "tools/toolsdllapi.h" 27 #include <tools/solar.h> 28 29 class ResId; 30 31 // -------- 32 // - Time - 33 // -------- 34 35 class TOOLS_DLLPUBLIC Time 36 { 37 private: 38 sal_Int32 nTime; 39 40 public: 41 Time(); 42 Time( const ResId & rResId ); Time(sal_Int32 _nTime)43 Time( sal_Int32 _nTime ) { Time::nTime = _nTime; } 44 Time( const Time& rTime ); 45 Time( sal_uIntPtr nHour, sal_uIntPtr nMin, 46 sal_uIntPtr nSec = 0, sal_uIntPtr n100Sec = 0 ); 47 SetTime(sal_Int32 nNewTime)48 void SetTime( sal_Int32 nNewTime ) { nTime = nNewTime; } GetTime() const49 sal_Int32 GetTime() const { return nTime; } 50 51 void SetHour( sal_uInt16 nNewHour ); 52 void SetMin( sal_uInt16 nNewMin ); 53 void SetSec( sal_uInt16 nNewSec ); 54 void Set100Sec( sal_uInt16 nNew100Sec ); GetHour() const55 sal_uInt16 GetHour() const 56 { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; 57 return (sal_uInt16)(nTempTime / 1000000); } GetMin() const58 sal_uInt16 GetMin() const 59 { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; 60 return (sal_uInt16)((nTempTime / 10000) % 100); } GetSec() const61 sal_uInt16 GetSec() const 62 { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; 63 return (sal_uInt16)((nTempTime / 100) % 100); } Get100Sec() const64 sal_uInt16 Get100Sec() const 65 { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; 66 return (sal_uInt16)(nTempTime % 100); } 67 68 sal_Int32 GetMSFromTime() const; 69 void MakeTimeFromMS( sal_Int32 nMS ); 70 71 /// 12 hours == 0.5 days 72 double GetTimeInDays() const; 73 IsBetween(const Time & rFrom,const Time & rTo) const74 sal_Bool IsBetween( const Time& rFrom, const Time& rTo ) const 75 { return ((nTime >= rFrom.nTime) && (nTime <= rTo.nTime)); } 76 77 sal_Bool IsEqualIgnore100Sec( const Time& rTime ) const; 78 operator ==(const Time & rTime) const79 sal_Bool operator ==( const Time& rTime ) const 80 { return (nTime == rTime.nTime); } operator !=(const Time & rTime) const81 sal_Bool operator !=( const Time& rTime ) const 82 { return (nTime != rTime.nTime); } operator >(const Time & rTime) const83 sal_Bool operator >( const Time& rTime ) const 84 { return (nTime > rTime.nTime); } operator <(const Time & rTime) const85 sal_Bool operator <( const Time& rTime ) const 86 { return (nTime < rTime.nTime); } operator >=(const Time & rTime) const87 sal_Bool operator >=( const Time& rTime ) const 88 { return (nTime >= rTime.nTime); } operator <=(const Time & rTime) const89 sal_Bool operator <=( const Time& rTime ) const 90 { return (nTime <= rTime.nTime); } 91 92 static Time GetUTCOffset(); 93 static sal_uIntPtr GetSystemTicks(); // Elapsed time 94 static sal_uIntPtr GetProcessTicks(); // CPU time 95 ConvertToUTC()96 void ConvertToUTC() { *this -= Time::GetUTCOffset(); } ConvertToLocalTime()97 void ConvertToLocalTime() { *this += Time::GetUTCOffset(); } 98 99 Time& operator =( const Time& rTime ); operator -() const100 Time operator -() const 101 { return Time( nTime * -1 ); } 102 Time& operator +=( const Time& rTime ); 103 Time& operator -=( const Time& rTime ); 104 TOOLS_DLLPUBLIC friend Time operator +( const Time& rTime1, const Time& rTime2 ); 105 TOOLS_DLLPUBLIC friend Time operator -( const Time& rTime1, const Time& rTime2 ); 106 }; 107 108 #endif // _TOOLS_TIME_HXX 109