MythTV master
mythtimezone.cpp
Go to the documentation of this file.
1#include "mythtimezone.h"
2
3#include <QtGlobal>
4#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
5#include <QtEnvironmentVariables>
6#include <QtSystemDetection>
7#include <QtVersionChecks>
8#endif
9#include <QDataStream>
10#include <QTextStream>
11#include <QDateTime>
12#include <QTimeZone>
13#include <QFileInfo>
14#include <QDir>
15
16#include "mythdate.h"
17
18namespace MythTZ
19{
20
22{
23 QDateTime loc = QDateTime::currentDateTime();
24 QDateTime utc = loc.toUTC();
25#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
26 loc = QDateTime(loc.date(), loc.time(), Qt::UTC);
27#else
28 loc = QDateTime(loc.date(), loc.time(), QTimeZone(QTimeZone::UTC));
29#endif
30 return utc.secsTo(loc);
31}
32
37QString getTimeZoneID(void)
38{
39 QString zone_id("UNDEF");
40#ifndef Q_OS_WINDOWS
41 // First, try the TZ environment variable to check for environment-specific
42 // overrides
43 QString tz = qEnvironmentVariable("TZ");
44 if (tz.isEmpty())
45 {
46 // No TZ, so attempt to determine the system-configured time zone ID
47 QDateTime dt = QDateTime::currentDateTime();
48 tz = dt.timeZone().id();
49 }
50
51 if (!tz.isEmpty())
52 {
53 zone_id = tz;
54 if (zone_id.startsWith("\"") || zone_id.startsWith("'"))
55 zone_id.remove(0, 1);
56 if (zone_id.endsWith("\"") || zone_id.endsWith("'"))
57 zone_id.chop(1);
58 if (zone_id.startsWith(":"))
59 zone_id.remove(0, 1);
60 // the "posix/" subdirectory typically contains the same files as the
61 // "zoneinfo/" parent directory, but are not typically what are in use
62 if (zone_id.startsWith("posix/"))
63 zone_id.remove(0, 6);
64 }
65#else
66 // Sadly, Windows zone names are different to the (probably Unix)
67 // backend's names - "AUS Eastern Standard Time" vs "Australia/Sydney".
68 // Translation is not worthwhile. Leave it as UNDEF to check the offset.
69#endif
70 return zone_id;
71}
72
77bool checkTimeZone(void)
78{
79 return true;
80}
81
84bool checkTimeZone(const QStringList &/*master_settings*/)
85{
86 return true;
87}
88
89}; // namespace MythTZ
int calc_utc_offset(void)
QString getTimeZoneID(void)
Returns the zoneinfo time zone ID or as much time zone information as possible.
bool checkTimeZone(void)
Verifies the time zone settings on this system agree with those on the master backend.