LibreOffice Module tools (master) 1
duration.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#pragma once
11
12#include <tools/time.hxx>
13
14class DateTime;
15
16namespace tools
17{
22{
23public:
25
28 Duration(const ::DateTime& rStart, const ::DateTime& rEnd);
29
32 Duration(const Time& rStart, const Time& rEnd);
33
35 explicit Duration(double fTimeInDays);
36
40 Duration(sal_Int32 nDays, const Time& rTime);
41
47 Duration(sal_Int32 nDays, sal_uInt32 nHours, sal_uInt32 nMinutes, sal_uInt32 nSeconds,
48 sal_uInt64 nNanoseconds);
49
50 bool IsNegative() const { return mnDays < 0 || maTime.GetTime() < 0; }
51 sal_Int32 GetDays() const { return mnDays; }
52 const Time& GetTime() const { return maTime; }
53 double GetInDays() const { return static_cast<double>(GetDays()) + GetTime().GetTimeInDays(); }
54
56 operator bool() const { return maTime.GetTime() != 0 || mnDays != 0; }
57
59 Duration operator-() const;
60
62 Duration& Add(const Duration& rDuration, bool& rbOverflow);
63
65 Duration Mult(sal_Int32 nMult, bool& rbOverflow) const;
66
67private:
69 Duration(sal_Int32 nDays, sal_Int64 nTime);
70
72 void Normalize(sal_uInt64 nHours, sal_uInt64 nMinutes, sal_uInt64 nSeconds,
73 sal_uInt64 nNanoseconds, bool bNegative);
74
77 void ApplyTime(sal_Int64 nNS);
78
81 void SetTimeDiff(const Time& rStart, const Time& rEnd);
82
83private:
84 Time maTime = Time(0);
85 sal_Int32 mnDays = 0;
86};
87}
88
89/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Duration in days and time.
Definition: duration.hxx:22
bool IsNegative() const
Definition: duration.hxx:50
const Time & GetTime() const
Definition: duration.hxx:52
sal_Int32 GetDays() const
Definition: duration.hxx:51
double GetInDays() const
Definition: duration.hxx:53
Any GetTime(const OUString &val)
Note: this class is a true marvel of engineering: because the author could not decide whether it's be...
Time operator-(const tools::Time &rTime1, const tools::Time &rTime2)
Definition: ttime.cxx:383
#define TOOLS_DLLPUBLIC
Definition: toolsdllapi.h:28
#define SAL_WARN_UNUSED