1/* This file is part of the KDE project
2 Copyright (C) 2003-2007 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 <kdatetime.h>
23
24#include "kplatokernel_export.h"
25#include "kptduration.h"
26
27/// The main namespace.
28namespace KPlato
29{
30
31class Duration;
32
33/**
34 * DateTime is a QDateTime which knows about Duration
35 * Note that in Plan all datetimes are often in the time zone specified
36 * in the project.
37 * Exception to this is the calendar related dates and times which has
38 * their own time zone specification.
39 */
40class KPLATOKERNEL_EXPORT DateTime : public QDateTime {
41
42public:
43 /// Create a DateTime.
44 DateTime();
45 /// Constructs a datetime with the given date, a valid time(00:00:00.000), and sets the timeSpec() to Qt::LocalTime.
46 explicit DateTime( const QDate & );
47 ///Constructs a datetime with the given date and time, using the time specification defined by @p spec.
48 /// If date is valid and time is not, the time will be set to midnight.
49 DateTime( const QDate &, const QTime &, Qt::TimeSpec spec = Qt::LocalTime );
50 /// Constructs a copy of the @p other datetime.
51 DateTime( const QDateTime &other );
52
53 /// Constructs a datetime from @p dt with timespec @p spec
54 DateTime( const QDateTime &dt, const KDateTime::Spec &spec );
55 /// Constructs a copy of the @p dt KDateTime.
56 DateTime( const KDateTime &dt );
57 /**
58 * Adds the duration @p duration to the datetime
59 */
60 DateTime operator+(const Duration &duration) const;
61 /**
62 * Subtracts the duration @p duration from the datetime
63 */
64 DateTime operator-(const Duration &duration) const ;
65 /**
66 * Returns the absolute duration between the two datetimes
67 */
68 Duration operator-(const DateTime &dt) const { return duration(dt); }
69 /**
70 * Returns the absolute duration between the two datetimes
71 */
72 Duration operator-(const DateTime &dt) { return duration(dt); }
73 /// Add @p duration to this datetime.
74 DateTime &operator+=(const Duration &duration);
75 /// Subtract the @p duration from this datetime.
76 DateTime &operator-=(const Duration &duration);
77
78 /**
79 * Parse a datetime string and return a DateTime.
80 */
81 static DateTime fromString(const QString dts, const KDateTime::Spec &spec=KDateTime::LocalZone);
82private:
83
84 Duration duration(const DateTime &dt) const;
85 void add(const Duration &duration);
86 void subtract(const Duration &duration);
87
88};
89
90} //KPlato namespace
91
92#endif
93