connectivity: add neutral context parser
[LibreOffice.git] / include / tools / datetime.hxx
blob7b78b29bdfc58bde681b5b2aea546f4300fbec5e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <iomanip>
29 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC DateTime : public Date, public tools::Time
31 public:
32 enum DateTimeInitSystem
34 SYSTEM
37 enum DateTimeInitEmpty
39 EMPTY
42 explicit DateTime( DateTimeInitEmpty ) : Date( Date::EMPTY ), Time( Time::EMPTY ) {}
43 explicit DateTime( DateTimeInitSystem );
44 DateTime( const DateTime& rDateTime ) :
45 Date( rDateTime ), Time( rDateTime ) {}
46 DateTime( const Date& rDate ) : Date( rDate ), Time(0) {}
47 DateTime( const tools::Time& rTime ) : Date(0), Time( rTime ) {}
48 DateTime( const Date& rDate, const tools::Time& rTime ) :
49 Date( rDate ), Time( rTime ) {}
50 DateTime( const css::util::DateTime& rDateTime );
52 css::util::DateTime
53 GetUNODateTime() const
54 { return css::util::DateTime(GetNanoSec(), GetSec(), GetMin(), GetHour(),
55 GetDay(), GetMonth(), GetYear(), false); }
57 bool IsBetween( const DateTime& rFrom,
58 const DateTime& rTo ) const;
60 bool IsEqualIgnoreNanoSec( const DateTime& rDateTime ) const
62 if ( Date::operator!=( rDateTime ) )
63 return false;
64 return Time::IsEqualIgnoreNanoSec( rDateTime );
67 bool operator ==( const DateTime& rDateTime ) const
68 { return (Date::operator==( rDateTime ) &&
69 Time::operator==( rDateTime )); }
70 bool operator !=( const DateTime& rDateTime ) const
71 { return (Date::operator!=( rDateTime ) ||
72 Time::operator!=( rDateTime )); }
73 bool operator >( const DateTime& rDateTime ) const;
74 bool operator <( const DateTime& rDateTime ) const;
75 bool operator >=( const DateTime& rDateTime ) const;
76 bool operator <=( const DateTime& rDateTime ) const;
78 sal_Int64 GetSecFromDateTime( const Date& rDate ) const;
80 void ConvertToUTC() { *this -= Time::GetUTCOffset(); }
81 void ConvertToLocalTime() { *this += Time::GetUTCOffset(); }
83 void AddTime( double fTimeInDays );
84 DateTime& operator +=( const tools::Time& rTime );
85 DateTime& operator -=( const tools::Time& rTime );
87 TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, sal_Int32 nDays );
88 TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, sal_Int32 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 tools::Time& rTime );
93 TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, const tools::Time& rTime );
94 TOOLS_DLLPUBLIC friend double operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 );
95 TOOLS_DLLPUBLIC friend sal_Int64 operator -( const DateTime& rDateTime, const Date& rDate )
96 { return static_cast<const Date&>(rDateTime) - rDate; }
98 DateTime& operator =( const DateTime& rDateTime );
99 DateTime& operator =( const css::util::DateTime& rUDateTime );
101 void GetWin32FileDateTime( sal_uInt32 & rLower, sal_uInt32 & rUpper ) const;
102 static DateTime CreateFromWin32FileDateTime( sal_uInt32 rLower, sal_uInt32 rUpper );
104 /// Creates DateTime given a unix time, which is the number of seconds
105 /// elapsed since Jan 1st, 1970.
106 static DateTime CreateFromUnixTime( const double fSecondsSinceEpoch );
109 inline DateTime& DateTime::operator =( const DateTime& rDateTime )
111 Date::operator=( rDateTime );
112 Time::operator=( rDateTime );
113 return *this;
116 template< typename charT, typename traits >
117 inline std::basic_ostream<charT, traits> & operator <<(
118 std::basic_ostream<charT, traits> & stream, const DateTime& datetime)
120 return stream << datetime.GetYear() << '-' <<
121 std::setw(2) << std::setfill('0') << datetime.GetMonth() << '-' <<
122 std::setw(2) << std::setfill('0') << datetime.GetDay() << ' ' <<
123 std::setw(2) << std::setfill('0') << datetime.GetHour() << ':' <<
124 std::setw(2) << std::setfill('0') << datetime.GetMin() << ':' <<
125 std::setw(2) << std::setfill('0') << datetime.GetSec() << "." <<
126 std::setw(9) << std::setfill('0') << datetime.GetNanoSec();
129 #endif
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */