2014-11-13 01:04:59 +02:00
|
|
|
/*
|
|
|
|
This file is part of the KDE libraries
|
2023-07-21 06:13:59 +03:00
|
|
|
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kdatetime.h"
|
2023-07-21 06:13:59 +03:00
|
|
|
#include "ksystemtimezone.h"
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
KDateTime::KDateTime()
|
2023-07-21 06:13:59 +03:00
|
|
|
: QDateTime()
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-21 06:13:59 +03:00
|
|
|
KDateTime::KDateTime(const QDate &date)
|
|
|
|
: QDateTime(date)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-21 06:13:59 +03:00
|
|
|
KDateTime::KDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec)
|
|
|
|
: QDateTime(date, time, spec)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-21 06:13:59 +03:00
|
|
|
KDateTime::KDateTime(const QDateTime &other)
|
|
|
|
: QDateTime(other)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KDateTime::KDateTime(const KDateTime &other)
|
2023-07-21 06:13:59 +03:00
|
|
|
: QDateTime(other)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2021-07-29 19:50:21 +03:00
|
|
|
}
|
|
|
|
|
2014-11-13 01:04:59 +02:00
|
|
|
KTimeZone KDateTime::timeZone() const
|
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
switch (timeSpec()) {
|
|
|
|
case Qt::LocalTime: {
|
|
|
|
return KSystemTimeZones::local();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2023-07-21 06:13:59 +03:00
|
|
|
case Qt::UTC: {
|
|
|
|
return KTimeZone::utc();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2023-07-21 06:13:59 +03:00
|
|
|
case Qt::OffsetFromUTC: {
|
|
|
|
return KTimeZone();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
}
|
2023-07-21 06:13:59 +03:00
|
|
|
return KTimeZone();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-07-21 06:13:59 +03:00
|
|
|
bool KDateTime::isNightTime() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
const int month = date().month();
|
|
|
|
const int hour = time().hour();
|
|
|
|
if (month <= 3 || month >= 9) {
|
|
|
|
return (hour >= 19 || hour <= 6);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2023-07-21 06:13:59 +03:00
|
|
|
return (hour >= 20 || hour <= 5);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-07-21 06:13:59 +03:00
|
|
|
QDate KDateTime::currentLocalDate()
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
return QDateTime::currentDateTime().date();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KDateTime KDateTime::currentLocalDateTime()
|
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
return QDateTime::currentDateTime();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KDateTime KDateTime::currentUtcDateTime()
|
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
return QDateTime::currentDateTimeUtc();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-07-21 06:13:59 +03:00
|
|
|
KDateTime KDateTime::currentDateTime(const KTimeZone &zone)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
return zone.toZoneTime(QDateTime::currentDateTimeUtc());
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 09:17:49 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
2023-07-21 06:13:59 +03:00
|
|
|
QDataStream& operator<<(QDataStream &s, const KDateTime &kdt)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
s << kdt.date() << kdt.time() << int(kdt.timeSpec());
|
2014-11-13 01:04:59 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2023-07-21 06:13:59 +03:00
|
|
|
QDataStream& operator>>(QDataStream &s, KDateTime &kdt)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-21 06:13:59 +03:00
|
|
|
QDate date;
|
|
|
|
QTime time;
|
|
|
|
int spec = int(Qt::UTC);
|
|
|
|
s >> date >> time >> spec;
|
|
|
|
kdt = KDateTime(date, time, static_cast<Qt::TimeSpec>(spec));
|
2014-11-13 01:04:59 +02:00
|
|
|
return s;
|
|
|
|
}
|
2017-08-04 09:17:49 +00:00
|
|
|
QT_END_NAMESPACE
|