xref: /aoo42x/main/tools/inc/tools/datetime.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _DATETIME_HXX
28 #define _DATETIME_HXX
29 
30 #include "tools/toolsdllapi.h"
31 #include <tools/solar.h>
32 #include <tools/date.hxx>
33 #include <tools/time.hxx>
34 
35 // ------------
36 // - DateTime -
37 // ------------
38 
39 class TOOLS_DLLPUBLIC DateTime : public Date, public Time
40 {
41 public:
42                     DateTime() : Date(), Time() {}
43                     DateTime( const DateTime& rDateTime ) :
44                         Date( rDateTime ), Time( rDateTime ) {}
45                     DateTime( const Date& rDate ) : Date( rDate ), Time(0) {}
46                     DateTime( const Time& rTime ) : Date(0), Time( rTime ) {}
47                     DateTime( const Date& rDate, const Time& rTime ) :
48                         Date( rDate ), Time( rTime ) {}
49 
50     sal_Bool            IsBetween( const DateTime& rFrom,
51                                const DateTime& rTo ) const;
52 
53     sal_Bool            IsEqualIgnore100Sec( const DateTime& rDateTime ) const
54                         {
55                             if ( Date::operator!=( rDateTime ) )
56                                 return sal_False;
57                             return Time::IsEqualIgnore100Sec( rDateTime );
58                         }
59 
60     sal_Bool            operator ==( const DateTime& rDateTime ) const
61                         { return (Date::operator==( rDateTime ) &&
62                                   Time::operator==( rDateTime )); }
63     sal_Bool            operator !=( const DateTime& rDateTime ) const
64                         { return (Date::operator!=( rDateTime ) ||
65                                   Time::operator!=( rDateTime )); }
66     sal_Bool            operator  >( const DateTime& rDateTime ) const;
67     sal_Bool            operator  <( const DateTime& rDateTime ) const;
68     sal_Bool            operator >=( const DateTime& rDateTime ) const;
69     sal_Bool            operator <=( const DateTime& rDateTime ) const;
70 
71     long            GetSecFromDateTime( const Date& rDate ) const;
72     void            MakeDateTimeFromSec( const Date& rDate, sal_uIntPtr nSec );
73 
74     void            ConvertToUTC()       { *this -= Time::GetUTCOffset(); }
75     void            ConvertToLocalTime() { *this += Time::GetUTCOffset(); }
76 
77     DateTime&       operator +=( long nDays )
78                         { Date::operator+=( nDays ); return *this; }
79     DateTime&       operator -=( long nDays )
80                         { Date::operator-=( nDays ); return *this; }
81 	DateTime&		operator +=( double fTimeInDays );
82 	DateTime&		operator -=( double fTimeInDays )
83 						{ return operator+=( -fTimeInDays ); }
84     DateTime&       operator +=( const Time& rTime );
85     DateTime&       operator -=( const Time& rTime );
86 
87     TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, long nDays );
88     TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, long nDays );
89     TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, double fTimeInDays );
90     TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, double fTimeInDays )
91 						{ return operator+( rDateTime, -fTimeInDays ); }
92     TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, const Time& rTime );
93     TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, const Time& rTime );
94 	TOOLS_DLLPUBLIC friend double	operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 );
95 	TOOLS_DLLPUBLIC friend long		operator -( const DateTime& rDateTime, const Date& rDate )
96 						{ return (const Date&) rDateTime - rDate; }
97 
98     DateTime&       operator =( const DateTime& rDateTime );
99 
100     void            GetWin32FileDateTime( sal_uInt32 & rLower, sal_uInt32 & rUpper );
101     static DateTime CreateFromWin32FileDateTime( const sal_uInt32 & rLower, const sal_uInt32 & rUpper );
102 };
103 
104 inline DateTime& DateTime::operator =( const DateTime& rDateTime )
105 {
106     Date::operator=( rDateTime );
107     Time::operator=( rDateTime );
108     return *this;
109 }
110 
111 #endif // _DATETIME_HXX
112