MythTV  master
mythtimezone.cpp
Go to the documentation of this file.
1 #include "mythtimezone.h"
2 
3 #include <cstdlib> // for malloc, getenv
4 #include <ctime>
5 
6 #include <QDataStream>
7 #include <QTextStream>
8 #include <QDateTime>
9 #include <QTimeZone>
10 #include <QFileInfo>
11 #include <QDir>
12 
13 #include "mythcorecontext.h"
14 #include "mythlogging.h"
15 #include "mythdate.h"
16 
17 namespace MythTZ
18 {
19 
20 int calc_utc_offset(void)
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 
36 QString 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 
76 bool checkTimeZone(void)
77 {
78  return true;
79 }
80 
83 bool checkTimeZone(const QStringList &/*master_settings*/)
84 {
85  return true;
86 }
87 
88 }; // namespace MythTZ
MythTZ::getTimeZoneID
QString getTimeZoneID(void)
Returns the zoneinfo time zone ID or as much time zone information as possible.
Definition: mythtimezone.cpp:36
mythdate.h
mythlogging.h
MythTZ::checkTimeZone
bool checkTimeZone(void)
Verifies the time zone settings on this system agree with those on the master backend.
Definition: mythtimezone.cpp:76
MythTZ
Definition: mythtimezone.cpp:17
MythTZ::calc_utc_offset
int calc_utc_offset(void)
Definition: mythtimezone.cpp:20
mythcorecontext.h
mythtimezone.h