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  loc = QDateTime(loc.date(), loc.time(), Qt::UTC);
25  return utc.secsTo(loc);
26 }
27 
32 QString getTimeZoneID(void)
33 {
34  QString zone_id("UNDEF");
35 #ifndef _WIN32
36  // First, try the TZ environment variable to check for environment-specific
37  // overrides
38  QString tz = qEnvironmentVariable("TZ");
39  if (tz.isEmpty())
40  {
41  // No TZ, so attempt to determine the system-configured time zone ID
42  QDateTime dt = QDateTime::currentDateTime();
43  tz = dt.timeZone().id();
44  }
45 
46  if (!tz.isEmpty())
47  {
48  zone_id = tz;
49  if (zone_id.startsWith("\"") || zone_id.startsWith("'"))
50  zone_id.remove(0, 1);
51  if (zone_id.endsWith("\"") || zone_id.endsWith("'"))
52  zone_id.chop(1);
53  if (zone_id.startsWith(":"))
54  zone_id.remove(0, 1);
55  // the "posix/" subdirectory typically contains the same files as the
56  // "zoneinfo/" parent directory, but are not typically what are in use
57  if (zone_id.startsWith("posix/"))
58  zone_id.remove(0, 6);
59  }
60 #else
61  // Sadly, Windows zone names are different to the (probably Unix)
62  // backend's names - "AUS Eastern Standard Time" vs "Australia/Sydney".
63  // Translation is not worthwhile. Leave it as UNDEF to check the offset.
64 #endif
65  return zone_id;
66 }
67 
72 bool checkTimeZone(void)
73 {
74  return true;
75 }
76 
79 bool checkTimeZone(const QStringList &/*master_settings*/)
80 {
81  return true;
82 }
83 
84 }; // namespace MythTZ
MythTZ::getTimeZoneID
QString getTimeZoneID(void)
Returns the zoneinfo time zone ID or as much time zone information as possible.
Definition: mythtimezone.cpp:32
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:72
MythTZ
Definition: mythtimezone.cpp:17
MythTZ::calc_utc_offset
int calc_utc_offset(void)
Definition: mythtimezone.cpp:20
mythcorecontext.h
mythtimezone.h