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