MCPcopy Create free account
hub / github.com/KDE/labplot / saveLoadDateTime

Method saveLoadDateTime

tests/backend/Column/ColumnTest.cpp:765–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

763//////////////////////////////////////////////////
764
765void ColumnTest::saveLoadDateTime() {
766 Column c(QStringLiteral("Datetime column"), Column::ColumnMode::DateTime);
767 c.setDateTimes({
768 QDateTime::fromString(
769 QStringLiteral("2017-03-26T02:14:34.000Z"),
770 Qt::DateFormat::ISODateWithMs), // without the timezone declaration it would be invalid (in some regions), because of the daylight time
771 QDateTime::fromString(QStringLiteral("2018-03-26T02:14:34.000Z"), Qt::DateFormat::ISODateWithMs),
772 QDateTime::fromString(QStringLiteral("2019-03-26T02:14:34.000Z"), Qt::DateFormat::ISODateWithMs),
773 QDateTime::fromString(QStringLiteral("2019-26-03 02:14:34:000"), QStringLiteral("yyyy-dd-MM hh:mm:ss:zzz")),
774 });
775
776 QByteArray array;
777 QXmlStreamWriter writer(&array);
778 c.save(&writer);
779
780 QDEBUG(array);
781
782 Column c2(QStringLiteral("Datetime 2 column"), Column::ColumnMode::DateTime);
783 XmlStreamReader reader(array);
784 bool found = false;
785 while (!reader.atEnd()) {
786 reader.readNext();
787 if (reader.isStartElement() && reader.name() == QLatin1String("column")) {
788 found = true;
789 break;
790 }
791 }
792 QCOMPARE(found, true);
793 QCOMPARE(c2.load(&reader, false), true);
794
795 QCOMPARE(c2.rowCount(), 4);
796 QCOMPARE(c2.dateTimeAt(0).isValid(), true);
797 QCOMPARE(c2.dateTimeAt(0), QDateTime::fromString(QStringLiteral("2017-03-26T02:14:34.000Z"), Qt::DateFormat::ISODateWithMs));
798 QCOMPARE(c2.dateTimeAt(1).isValid(), true);
799 QCOMPARE(c2.dateTimeAt(1), QDateTime::fromString(QStringLiteral("2018-03-26T02:14:34.000Z"), Qt::DateFormat::ISODateWithMs));
800 QCOMPARE(c2.dateTimeAt(2).isValid(), true);
801 QCOMPARE(c2.dateTimeAt(2), QDateTime::fromString(QStringLiteral("2019-03-26T02:14:34.000Z"), Qt::DateFormat::ISODateWithMs));
802 QCOMPARE(c2.dateTimeAt(3).isValid(), true);
803 QCOMPARE(c2.dateTimeAt(3), QDateTime::fromString(QStringLiteral("2019-03-26T02:14:34.000Z"), Qt::DateFormat::ISODateWithMs));
804}
805
806void ColumnTest::loadDoubleFromProject() {
807 Project project;

Callers

nothing calls this directly

Calls 8

setDateTimesMethod · 0.80
atEndMethod · 0.80
saveMethod · 0.45
nameMethod · 0.45
loadMethod · 0.45
rowCountMethod · 0.45
isValidMethod · 0.45
dateTimeAtMethod · 0.45

Tested by

no test coverage detected