mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00

interestingly QLocale is not used for many things but that is about to change, Katie uses it a lot internally (e.g. for QDateTime formatting and such) so instead of bolting a calendar system on top of KLocale perhaps a QLocale wrapped around in KLocale will fit the general idea of using QLocale in widgets when necessary (as does QCalendarWidget). that however means no way to specify a calendar system (in general, other than changing the widgets locale itself) but the QDateTime and related classes are tied to gregorian calendar already - the system time itself carries no information about the calendar and any conversions from one calendar to another are basically made up stuff (there is the time zone thing ofcourse but that is not a calendar) another interesting thing to note is that KLocale was written such that it is read-write - changing the date formats for example is possible because there are public KLocale methods for that. Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
113 lines
3.5 KiB
C++
113 lines
3.5 KiB
C++
/*
|
|
This file is part of the KDE libraries
|
|
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
|
|
|
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 "ktimezonestest.h"
|
|
#include "ksystemtimezone.h"
|
|
#include "qtest_kde.h"
|
|
#include "kdebug.h"
|
|
|
|
#include <QtCore/QDir>
|
|
#include <QtCore/QDateTime>
|
|
|
|
#include <stdlib.h>
|
|
|
|
QTEST_KDEMAIN_CORE(KTimeZonesTest)
|
|
|
|
void KTimeZonesTest::initTestCase()
|
|
{
|
|
}
|
|
|
|
void KTimeZonesTest::cleanupTestCase()
|
|
{
|
|
}
|
|
|
|
///////////////////
|
|
// KTimeZone: UTC
|
|
///////////////////
|
|
|
|
void KTimeZonesTest::utc()
|
|
{
|
|
KTimeZone utc = KTimeZone::utc();
|
|
QVERIFY(utc.isValid());
|
|
QCOMPARE(utc.name(), QString("UTC"));
|
|
KTimeZone systemUtc = KSystemTimeZones::zone("UTC");
|
|
QCOMPARE(utc, systemUtc);
|
|
}
|
|
|
|
/////////////////////////
|
|
// KSystemTimeZones tests
|
|
/////////////////////////
|
|
|
|
void KTimeZonesTest::local()
|
|
{
|
|
const QByteArray tz = qgetenv("TZ");
|
|
::setenv("TZ", "Europe/Paris", 1);
|
|
KTimeZone local = KSystemTimeZones::local();
|
|
QVERIFY(local.isValid());
|
|
QCOMPARE(local.name(), QString::fromLatin1("Europe/Paris"));
|
|
::setenv("TZ", tz.constData(), 1);
|
|
}
|
|
|
|
void KTimeZonesTest::zone()
|
|
{
|
|
KTimeZone utc = KSystemTimeZones::zone("UTC");
|
|
QVERIFY(utc.isValid());
|
|
|
|
KTimeZone london = KSystemTimeZones::zone("Europe/London");
|
|
QVERIFY(london.isValid());
|
|
QCOMPARE(london.name(), QString("Europe/London"));
|
|
QCOMPARE(london.countryCode(), QString("GB"));
|
|
QCOMPARE(london.latitude(), float(51.5083));
|
|
QCOMPARE(london.longitude(), float(-0.125278));
|
|
QCOMPARE(london.comment(), QString());
|
|
|
|
KTimeZone losAngeles = KSystemTimeZones::zone("America/Los_Angeles");
|
|
QVERIFY(losAngeles.isValid());
|
|
QCOMPARE(losAngeles.name(), QString("America/Los_Angeles"));
|
|
QCOMPARE(losAngeles.countryCode(), QString("US"));
|
|
QCOMPARE(losAngeles.latitude(), float(34.0522));
|
|
QCOMPARE(losAngeles.longitude(), float(-118.243));
|
|
QCOMPARE(losAngeles.comment(), QString("Pacific"));
|
|
}
|
|
|
|
void KTimeZonesTest::zoneinfoDir()
|
|
{
|
|
const QString zoneinfo = KSystemTimeZones::zoneinfoDir();
|
|
QVERIFY(!zoneinfo.isEmpty());
|
|
}
|
|
|
|
void KTimeZonesTest::abbreviation()
|
|
{
|
|
KTimeZone london = KSystemTimeZones::zone("Europe/London");
|
|
QVERIFY(london.isValid());
|
|
QDateTime gmt(QDate(2006, 3, 26), QTime(0, 59, 0), Qt::UTC);
|
|
QDateTime bst(QDate(2006, 3, 26), QTime(1, 0, 0), Qt::UTC);
|
|
QCOMPARE(london.abbreviation(gmt), QByteArray("GMT"));
|
|
QCOMPARE(london.abbreviation(bst), QByteArray("BST"));
|
|
|
|
KTimeZone losAngeles = KSystemTimeZones::zone("America/Los_Angeles");
|
|
QVERIFY(losAngeles.isValid());
|
|
QDateTime pdt(QDate(2012, 11, 4), QTime(8, 59, 59), Qt::UTC);
|
|
QDateTime pst(QDate(2012, 11, 4), QTime(9, 0, 0), Qt::UTC);
|
|
QCOMPARE(losAngeles.abbreviation(pdt), QByteArray("PDT"));
|
|
QCOMPARE(losAngeles.abbreviation(pst), QByteArray("PST"));
|
|
}
|
|
|
|
#include "moc_ktimezonestest.cpp"
|