2
* Copyright (C) 2011 Tuomo Penttinen, all rights reserved.
4
* Author: Tuomo Penttinen <tp@herqq.org>
6
* This file is part of Herqq UPnP Av (HUPnPAv) library.
8
* Herqq UPnP Av is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
13
* Herqq UPnP Av is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with Herqq UPnP Av. If not, see <http://www.gnu.org/licenses/>.
22
#include "hdatetimerange.h"
24
#include <QtCore/QDateTime>
26
static bool registerMetaTypes()
28
qRegisterMetaType<Herqq::Upnp::Av::HDateTimeRange>(
29
"Herqq::Upnp::Av::HDateTimeRange");
34
static bool regMetaT = registerMetaTypes();
45
class HDateTimeRangePrivate :
48
H_DISABLE_ASSIGN(HDateTimeRangePrivate)
52
QDateTime m_startTime, m_endTime;
53
HDaylightSaving m_dlSaving;
55
HDateTimeRangePrivate() :
56
m_startTime(), m_endTime(), m_dlSaving(Unknown_DaylightSaving)
61
HDateTimeRange::HDateTimeRange() :
62
h_ptr(new HDateTimeRangePrivate())
66
HDateTimeRange::HDateTimeRange(const QString& value, HDaylightSaving dlSaving) :
67
h_ptr(new HDateTimeRangePrivate())
69
int index = value.indexOf('/');
72
QDateTime start = QDateTime::fromString(value.left(index), Qt::ISODate);
75
QDateTime end = QDateTime::fromString(value.mid(index+1), Qt::ISODate);
78
h_ptr->m_startTime = start;
79
h_ptr->m_endTime = end;
80
h_ptr->m_dlSaving = dlSaving;
86
HDateTimeRange::HDateTimeRange(const HDateTimeRange& other) :
89
Q_ASSERT(&other != this);
92
HDateTimeRange& HDateTimeRange::operator=(const HDateTimeRange& other)
94
Q_ASSERT(&other != this);
99
HDateTimeRange::~HDateTimeRange()
103
bool HDateTimeRange::isValid() const
105
return h_ptr->m_startTime.isValid() && h_ptr->m_endTime.isValid();
108
QDateTime HDateTimeRange::startTime() const
110
return h_ptr->m_startTime;
113
QDateTime HDateTimeRange::endTime() const
115
return h_ptr->m_endTime;
118
HDaylightSaving HDateTimeRange::daylightSaving() const
120
return h_ptr->m_dlSaving;
123
QString HDateTimeRange::toString() const
129
return QString("%1/%2").arg(
130
startTime().toString(Qt::ISODate), endTime().toString(Qt::ISODate));
133
void HDateTimeRange::setStartTime(const QDateTime& value)
135
h_ptr->m_startTime = value;
138
void HDateTimeRange::setEndTime(const QDateTime& value)
140
h_ptr->m_endTime = value;
143
void HDateTimeRange::setDaylightSaving(HDaylightSaving dlSaving)
145
h_ptr->m_dlSaving = dlSaving;
148
bool operator==(const HDateTimeRange& obj1, const HDateTimeRange& obj2)
150
return obj1.toString() == obj2.toString() &&
151
obj1.daylightSaving() == obj2.daylightSaving();