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 .
22 #include "tools/toolsdllapi.h"
23 #include <tools/solar.h>
24 #include <tools/date.hxx>
25 #include <tools/time.hxx>
27 class TOOLS_DLLPUBLIC SAL_WARN_UNUSED DateTime
: public Date
, public 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 Time
& rTime
) : Date(0), Time( rTime
) {}
47 DateTime( const Date
& rDate
, const Time
& rTime
) :
48 Date( rDate
), Time( rTime
) {}
50 sal_Bool
IsBetween( const DateTime
& rFrom
,
51 const DateTime
& rTo
) const;
53 sal_Bool
IsEqualIgnoreNanoSec( const DateTime
& rDateTime
) const
55 if ( Date::operator!=( rDateTime
) )
57 return Time::IsEqualIgnoreNanoSec( rDateTime
);
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;
71 long GetSecFromDateTime( const Date
& rDate
) const;
73 void ConvertToUTC() { *this -= Time::GetUTCOffset(); }
74 void ConvertToLocalTime() { *this += Time::GetUTCOffset(); }
76 DateTime
& operator +=( long nDays
)
77 { Date::operator+=( nDays
); return *this; }
78 DateTime
& operator -=( long nDays
)
79 { Date::operator-=( nDays
); return *this; }
80 DateTime
& operator +=( double fTimeInDays
);
81 DateTime
& operator -=( double fTimeInDays
)
82 { return operator+=( -fTimeInDays
); }
83 DateTime
& operator +=( const Time
& rTime
);
84 DateTime
& operator -=( const Time
& rTime
);
86 TOOLS_DLLPUBLIC
friend DateTime
operator +( const DateTime
& rDateTime
, long nDays
);
87 TOOLS_DLLPUBLIC
friend DateTime
operator -( const DateTime
& rDateTime
, long nDays
);
88 TOOLS_DLLPUBLIC
friend DateTime
operator +( const DateTime
& rDateTime
, double fTimeInDays
);
89 TOOLS_DLLPUBLIC
friend DateTime
operator -( const DateTime
& rDateTime
, double fTimeInDays
)
90 { return operator+( rDateTime
, -fTimeInDays
); }
91 TOOLS_DLLPUBLIC
friend DateTime
operator +( const DateTime
& rDateTime
, const Time
& rTime
);
92 TOOLS_DLLPUBLIC
friend DateTime
operator -( const DateTime
& rDateTime
, const Time
& rTime
);
93 TOOLS_DLLPUBLIC
friend double operator -( const DateTime
& rDateTime1
, const DateTime
& rDateTime2
);
94 TOOLS_DLLPUBLIC
friend long operator -( const DateTime
& rDateTime
, const Date
& rDate
)
95 { return (const Date
&) rDateTime
- rDate
; }
97 DateTime
& operator =( const DateTime
& rDateTime
);
99 void GetWin32FileDateTime( sal_uInt32
& rLower
, sal_uInt32
& rUpper
);
100 static DateTime
CreateFromWin32FileDateTime( const sal_uInt32
& rLower
, const sal_uInt32
& rUpper
);
103 inline DateTime
& DateTime::operator =( const DateTime
& rDateTime
)
105 Date::operator=( rDateTime
);
106 Time::operator=( rDateTime
);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */