xref: /aoo42x/main/tools/inc/tools/datetime.hxx (revision 8b851043)
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 _DATETIME_HXX
24 #define _DATETIME_HXX
25 
26 #include "tools/toolsdllapi.h"
27 #include <tools/solar.h>
28 #include <tools/date.hxx>
29 #include <tools/time.hxx>
30 
31 // ------------
32 // - DateTime -
33 // ------------
34 
35 class TOOLS_DLLPUBLIC DateTime : public Date, public Time
36 {
37 public:
DateTime()38                     DateTime() : Date(), Time() {}
DateTime(const DateTime & rDateTime)39                     DateTime( const DateTime& rDateTime ) :
40                         Date( rDateTime ), Time( rDateTime ) {}
DateTime(const Date & rDate)41                     DateTime( const Date& rDate ) : Date( rDate ), Time(0) {}
DateTime(const Time & rTime)42                     DateTime( const Time& rTime ) : Date(0), Time( rTime ) {}
DateTime(const Date & rDate,const Time & rTime)43                     DateTime( const Date& rDate, const Time& rTime ) :
44                         Date( rDate ), Time( rTime ) {}
45 
46     sal_Bool            IsBetween( const DateTime& rFrom,
47                                const DateTime& rTo ) const;
48 
IsEqualIgnore100Sec(const DateTime & rDateTime) const49     sal_Bool            IsEqualIgnore100Sec( const DateTime& rDateTime ) const
50                         {
51                             if ( Date::operator!=( rDateTime ) )
52                                 return sal_False;
53                             return Time::IsEqualIgnore100Sec( rDateTime );
54                         }
55 
operator ==(const DateTime & rDateTime) const56     sal_Bool            operator ==( const DateTime& rDateTime ) const
57                         { return (Date::operator==( rDateTime ) &&
58                                   Time::operator==( rDateTime )); }
operator !=(const DateTime & rDateTime) const59     sal_Bool            operator !=( const DateTime& rDateTime ) const
60                         { return (Date::operator!=( rDateTime ) ||
61                                   Time::operator!=( rDateTime )); }
62     sal_Bool            operator  >( const DateTime& rDateTime ) const;
63     sal_Bool            operator  <( const DateTime& rDateTime ) const;
64     sal_Bool            operator >=( const DateTime& rDateTime ) const;
65     sal_Bool            operator <=( const DateTime& rDateTime ) const;
66 
67     long            GetSecFromDateTime( const Date& rDate ) const;
68     void            MakeDateTimeFromSec( const Date& rDate, sal_uIntPtr nSec );
69 
ConvertToUTC()70     void            ConvertToUTC()       { *this -= Time::GetUTCOffset(); }
ConvertToLocalTime()71     void            ConvertToLocalTime() { *this += Time::GetUTCOffset(); }
72 
operator +=(long nDays)73     DateTime&       operator +=( long nDays )
74                         { Date::operator+=( nDays ); return *this; }
operator -=(long nDays)75     DateTime&       operator -=( long nDays )
76                         { Date::operator-=( nDays ); return *this; }
77 	DateTime&		operator +=( double fTimeInDays );
operator -=(double fTimeInDays)78 	DateTime&		operator -=( double fTimeInDays )
79 						{ return operator+=( -fTimeInDays ); }
80     DateTime&       operator +=( const Time& rTime );
81     DateTime&       operator -=( const Time& rTime );
82 
83     TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, long nDays );
84     TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, long nDays );
85     TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, double fTimeInDays );
operator -(const DateTime & rDateTime,double fTimeInDays)86     TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, double fTimeInDays )
87 						{ return operator+( rDateTime, -fTimeInDays ); }
88     TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, const Time& rTime );
89     TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, const Time& rTime );
90 	TOOLS_DLLPUBLIC friend double	operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 );
operator -(const DateTime & rDateTime,const Date & rDate)91 	TOOLS_DLLPUBLIC friend long		operator -( const DateTime& rDateTime, const Date& rDate )
92 						{ return (const Date&) rDateTime - rDate; }
93 
94     DateTime&       operator =( const DateTime& rDateTime );
95 
96     void            GetWin32FileDateTime( sal_uInt32 & rLower, sal_uInt32 & rUpper );
97     static DateTime CreateFromWin32FileDateTime( const sal_uInt32 & rLower, const sal_uInt32 & rUpper );
98 };
99 
operator =(const DateTime & rDateTime)100 inline DateTime& DateTime::operator =( const DateTime& rDateTime )
101 {
102     Date::operator=( rDateTime );
103     Time::operator=( rDateTime );
104     return *this;
105 }
106 
107 #endif // _DATETIME_HXX
108