kplato

kptdatetime.h
1/* This file is part of the KDE project
2 Copyright (C) 2003 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19#ifndef KPTDATETIME_H
20#define KPTDATETIME_H
21
22#include <tqdatetime.h>
23#include "kptduration.h"
24
25namespace KPlato
26{
27
28class Duration;
29
33class DateTime : public TQDateTime {
34
35public:
36 DateTime();
37 DateTime(const TQDateTime &dt);
38 DateTime(const TQDate &date, const TQTime &time);
39
43 DateTime operator+(const Duration &duration) const;
47 DateTime operator-(const Duration &duration) const ;
51 Duration operator-(const DateTime &dt) const { return duration(dt); }
52 Duration operator-(const DateTime &dt) { return duration(dt); }
53
54 DateTime &operator+=(const Duration &duration);
55 DateTime &operator-=(const Duration &duration);
56
57 static DateTime fromString(const TQString dts) {
58 TQDateTime dt;
59 if (dts.isEmpty())
60 return DateTime();
61 dt = TQDateTime::fromString(dts, TQt::ISODate);
62 if (dt.isValid())
63 return DateTime(dt);
64 return DateTime(TQDateTime::fromString(dts));
65 }
66private:
67
68 Duration duration(const DateTime &dt) const;
69 void add(const Duration &duration);
70 void subtract(const Duration &duration);
71
72};
73
74} //KPlato namespace
75
76#endif
DateTime is a TQDateTime which knows about Duration.
Definition kptdatetime.h:33
Duration operator-(const DateTime &dt) const
Returns the absolute duration between the two datetimes.
Definition kptdatetime.h:51
DateTime operator-(const Duration &duration) const
Subtracts the duration.
DateTime operator+(const Duration &duration) const
Adds the duration.
The duration class can be used to store a timespan in a convenient format.
Definition kptduration.h:34