Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and Test

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y qtbase5-dev qttools5-dev-tools cmake

- name: Configure
run: cmake -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build

- name: Test
run: ctest --test-dir build --output-on-failure
33 changes: 27 additions & 6 deletions AutoTests/tst_ClockTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QtTest>
#include <QDate>
#include <QDateTime>
#include <QTimeZone>
#include <QTextStream>

#include <OrgElement.h>
Expand All @@ -34,11 +35,13 @@

using namespace OrgMode;

// Use explicit timezone to ensure consistent DST handling across all platforms
const QTimeZone Berlin("Europe/Berlin");
const QDate today(2015, 4, 24);
const QDateTime six(today, QTime(6,0));
const QDateTime seven(today, QTime(7,0));
const QDateTime eight(today, QTime(8,0));
const QDateTime nine(today, QTime(9,0));
const QDateTime six(today, QTime(6,0), Berlin);
const QDateTime seven(today, QTime(7,0), Berlin);
const QDateTime eight(today, QTime(8,0), Berlin);
const QDateTime nine(today, QTime(9,0), Berlin);
const TimeInterval sixToEight(six, eight);
const TimeInterval sevenToNine(seven, nine);
const TimeInterval sevenToEight(seven, eight);
Expand All @@ -59,6 +62,7 @@ class ClockTests : public QObject
Q_OBJECT

private Q_SLOTS:
void initTestCase();
void testTimeIntervals_data();
void testTimeIntervals();
void testTimeIntervalsIsValid_data();
Expand All @@ -69,6 +73,17 @@ private Q_SLOTS:
void testAccumulateForInterval();
};

void ClockTests::initTestCase()
{
// Set timezone to Europe/Berlin to ensure consistent DST handling.
// The test data in WeirdClockEntries.org was created assuming German local time,
// and the Parser creates QDateTime objects using the system's local timezone.
qputenv("TZ", "Europe/Berlin");
#ifdef Q_OS_UNIX
tzset();
#endif
}

void ClockTests::testTimeIntervals_data()
{
QTest::addColumn<TimeInterval>("left");
Expand Down Expand Up @@ -145,12 +160,18 @@ void ClockTests::testAccumulateForInterval_data()
QTest::addColumn<int>("duration");
QTest::addColumn<int>("total");

// Use explicit Berlin timezone for DST-sensitive date calculations
const QDate mar26(2015, 3, 26);
const QDate mar27(mar26.addDays(1));
const QDate mar23(2015, 3, 23); //Monday
const QDate mar30(mar23.addDays(7)); //Monday a week later
const TimeInterval wk13(mar23, mar30);
QTest::newRow("headline_1_1") << FL1("headline_1_1") << TimeInterval(mar26, mar27) << 60 * 60 << 60 * 150;
// Construct TimeIntervals with explicit timezone to ensure correct DST handling
const auto startOfDay = [](const QDate& date) {
return QDateTime(date, QTime(0, 0), Berlin);
};
const TimeInterval wk13(startOfDay(mar23), startOfDay(mar30));
const TimeInterval mar26to27(startOfDay(mar26), startOfDay(mar27));
QTest::newRow("headline_1_1") << FL1("headline_1_1") << mar26to27 << 60 * 60 << 60 * 150;
QTest::newRow("headline_1_2") << FL1("headline_1_2") << wk13 << 60 * 60 << 60 * 150;
QTest::newRow("headline_1_3 DST switch") << FL1("headline_1_3") << wk13 << 60 * 60 * 11 << 60 * 60 * 11;
QTest::newRow("headline_1 full week") << FL1("headline_1") << wk13 << 52200 << 57600; //14:30h, 15:15h total
Expand Down