1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_TOOLS_DATETIME_HXX
20 #define INCLUDED_TOOLS_DATETIME_HXX
22 #include <tools/toolsdllapi.h>
23 #include <tools/date.hxx>
24 #include <tools/time.hxx>
25 #include <com/sun/star/util/DateTime.hpp>
27 class TOOLS_DLLPUBLIC SAL_WARN_UNUSED DateTime
: public Date
, public tools::Time
30 enum DateTimeInitSystem
35 // TODO temporary until all uses are inspected and resolved
36 enum DateTimeInitEmpty
41 DateTime( DateTimeInitEmpty
) : Date( Date::EMPTY
), Time( Time::EMPTY
) {}
42 DateTime( DateTimeInitSystem
) : Date( Date::SYSTEM
), Time( Time::SYSTEM
) {}
43 DateTime( const DateTime
& rDateTime
) :
44 Date( rDateTime
), Time( rDateTime
) {}
45 DateTime( const Date
& rDate
) : Date( rDate
), Time(0) {}
46 DateTime( const tools::Time
& rTime
) : Date(0), Time( rTime
) {}
47 DateTime( const Date
& rDate
, const tools::Time
& rTime
) :
48 Date( rDate
), Time( rTime
) {}
49 DateTime( const css::util::DateTime
& rDateTime
);
52 GetUNODateTime() const
53 { return css::util::DateTime(GetNanoSec(), GetSec(), GetMin(), GetHour(),
54 GetDay(), GetMonth(), GetYear(), false); }
56 bool IsBetween( const DateTime
& rFrom
,
57 const DateTime
& rTo
) const;
59 bool IsEqualIgnoreNanoSec( const DateTime
& rDateTime
) const
61 if ( Date::operator!=( rDateTime
) )
63 return Time::IsEqualIgnoreNanoSec( rDateTime
);
66 bool operator ==( const DateTime
& rDateTime
) const
67 { return (Date::operator==( rDateTime
) &&
68 Time::operator==( rDateTime
)); }
69 bool operator !=( const DateTime
& rDateTime
) const
70 { return (Date::operator!=( rDateTime
) ||
71 Time::operator!=( rDateTime
)); }
72 bool operator >( const DateTime
& rDateTime
) const;
73 bool operator <( const DateTime
& rDateTime
) const;
74 bool operator >=( const DateTime
& rDateTime
) const;
75 bool operator <=( const DateTime
& rDateTime
) const;
77 long GetSecFromDateTime( const Date
& rDate
) const;
79 void ConvertToUTC() { *this -= Time::GetUTCOffset(); }
80 void ConvertToLocalTime() { *this += Time::GetUTCOffset(); }
82 DateTime
& operator +=( long nDays
)
83 { Date::operator+=( nDays
); return *this; }
84 DateTime
& operator -=( long nDays
)
85 { Date::operator-=( nDays
); return *this; }
86 DateTime
& operator +=( double fTimeInDays
);
87 DateTime
& operator -=( double fTimeInDays
)
88 { return operator+=( -fTimeInDays
); }
89 DateTime
& operator +=( const tools::Time
& rTime
);
90 DateTime
& operator -=( const tools::Time
& rTime
);
92 TOOLS_DLLPUBLIC
friend DateTime
operator +( const DateTime
& rDateTime
, long nDays
);
93 TOOLS_DLLPUBLIC
friend DateTime
operator -( const DateTime
& rDateTime
, long nDays
);
94 TOOLS_DLLPUBLIC
friend DateTime
operator +( const DateTime
& rDateTime
, double fTimeInDays
);
95 TOOLS_DLLPUBLIC
friend DateTime
operator -( const DateTime
& rDateTime
, double fTimeInDays
)
96 { return operator+( rDateTime
, -fTimeInDays
); }
97 TOOLS_DLLPUBLIC
friend DateTime
operator +( const DateTime
& rDateTime
, const tools::Time
& rTime
);
98 TOOLS_DLLPUBLIC
friend DateTime
operator -( const DateTime
& rDateTime
, const tools::Time
& rTime
);
99 TOOLS_DLLPUBLIC
friend double operator -( const DateTime
& rDateTime1
, const DateTime
& rDateTime2
);
100 TOOLS_DLLPUBLIC
friend long operator -( const DateTime
& rDateTime
, const Date
& rDate
)
101 { return (const Date
&) rDateTime
- rDate
; }
103 DateTime
& operator =( const DateTime
& rDateTime
);
105 void GetWin32FileDateTime( sal_uInt32
& rLower
, sal_uInt32
& rUpper
);
106 static DateTime
CreateFromWin32FileDateTime( const sal_uInt32
& rLower
, const sal_uInt32
& rUpper
);
109 inline DateTime
& DateTime::operator =( const DateTime
& rDateTime
)
111 Date::operator=( rDateTime
);
112 Time::operator=( rDateTime
);
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */