[frameworks/kholidays] /: lunarphase.cpp - use the system timezone rather than utc

Allen Winter <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit e54b0d76b8058599c28e31e7b1e351d948999bc0 by Allen Winter.
Committed on 05/08/2026 at 19:56.
Pushed by winterz into branch 'master'.

lunarphase.cpp - use the system timezone rather than utc

utc can be a long time from where the user's actual timezone
so use the system timezone instead.

M  +16   -1    autotests/testlunar.cpp
M  +2    -2    src/lunarphase.cpp
M  +3    -1    src/lunarphase.h

https://invent.kde.org/frameworks/kholidays/-/commit/e54b0d76b8058599c28e31e7b1e351d948999bc0

diff --git a/autotests/testlunar.cpp b/autotests/testlunar.cpp
index b31c24d..970cf88 100644
--- a/autotests/testlunar.cpp
+++ b/autotests/testlunar.cpp
@@ -7,17 +7,28 @@
 */
 
 #include "testlunar.h"
+#include "kholidays/lunarphase.h"
 
 #include <QDebug>
 #include <QTest>
 
 QTEST_MAIN(LunarTest)
 
-#include "kholidays/lunarphase.h"
+static void setTimeZone(const char *zonename)
+{
+    QVERIFY(QTimeZone(zonename).isValid());
+    qputenv("TZ", zonename);
+    const QDateTime currentDateTime = QDateTime::currentDateTime();
+    QVERIFY(currentDateTime.timeZone().isValid());
+    QCOMPARE(currentDateTime.timeZoneAbbreviation(), QString::fromLatin1(zonename));
+}
+
 using namespace KHolidays;
 
 void LunarTest::test2005()
 {
+    setTimeZone("UTC");
+
     QList<QDate> fQ2005;
     QList<QDate> fM2005;
     QList<QDate> lQ2005;
@@ -111,6 +122,8 @@ void LunarTest::test2005()
 
 void LunarTest::test2007()
 {
+    setTimeZone("UTC");
+
     QList<QDate> fQ2007;
     QList<QDate> fM2007;
     QList<QDate> lQ2007;
@@ -204,6 +217,8 @@ void LunarTest::test2007()
 
 void LunarTest::testIntermediatePhases()
 {
+    setTimeZone("UTC");
+
     struct {
         QDate date;
         LunarPhase::Phase phase;
diff --git a/src/lunarphase.cpp b/src/lunarphase.cpp
index e6ff155..4443212 100644
--- a/src/lunarphase.cpp
+++ b/src/lunarphase.cpp
@@ -55,9 +55,9 @@ LunarPhase::Phase LunarPhase::phaseAtDate(const QDate &date)
     Phase retPhase = None;
 
     const QTime midnight(0, 0, 0);
-    const QDateTime todayStart(date, midnight, QTimeZone::utc());
+    const QDateTime todayStart(date, midnight, QTimeZone::systemTimeZone());
     const double startAngle = phaseAngle(todayStart.toMSecsSinceEpoch());
-    const QDateTime todayEnd(date.addDays(1), midnight, QTimeZone::utc());
+    const QDateTime todayEnd(date.addDays(1), midnight, QTimeZone::systemTimeZone());
     const double endAngle = phaseAngle(todayEnd.toMSecsSinceEpoch());
 
     if (startAngle > endAngle) {
diff --git a/src/lunarphase.h b/src/lunarphase.h
index 7f2dc09..23e7438 100644
--- a/src/lunarphase.h
+++ b/src/lunarphase.h
@@ -1,7 +1,7 @@
 /*
     This file is part of the kholidays library.
 
-    SPDX-FileCopyrightText: 2004, 2007, 2009 Allen Winter <[email protected]>
+    SPDX-FileCopyrightText: Allen Winter <[email protected]>
 
     SPDX-License-Identifier: LGPL-2.0-or-later
 */
@@ -46,6 +46,8 @@ namespace KHolidays
 
   A very good description of the lunar phases can be read at the Wikipedia,
      https://en.wikipedia.org/wiki/Lunar_phase
+
+  The phase is computed for noon in the system timezone.
 */
 class KHOLIDAYS_EXPORT LunarPhase // krazy:exclude=dpointer
 {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.