Skip to content
This repository

cache timezone bias #1531

Merged
merged 2 commits into from over 1 year ago

2 participants

Lars Op den Kamp jmarshallnz
Lars Op den Kamp
Collaborator

because GetTimeZoneInformation() is slow. speeds up things like the recordings list.

jmarshallnz
Owner

Looks OK to me, assuming the threadsafety isn't an issue (doesn't look as though it is - at worse you'll get incorrect timezone data).

Lars Op den Kamp
Collaborator

yeah thread safety isn't a problem here.

Lars Op den Kamp opdenkamp merged commit 2336e3a into from
Lars Op den Kamp opdenkamp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
71  xbmc/XBDateTime.cpp
@@ -282,22 +282,8 @@ CDateTime CDateTime::GetCurrentDateTime()
282 282
 
283 283
 CDateTime CDateTime::GetUTCDateTime()
284 284
 {
285  
-  TIME_ZONE_INFORMATION tz;
286  
-
287 285
   CDateTime time(GetCurrentDateTime());
288  
-  switch(GetTimeZoneInformation(&tz))
289  
-  {
290  
-    case TIME_ZONE_ID_DAYLIGHT:
291  
-        time += CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
292  
-        break;
293  
-    case TIME_ZONE_ID_STANDARD:
294  
-        time += CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
295  
-        break;
296  
-    case TIME_ZONE_ID_UNKNOWN:
297  
-        time += CDateTimeSpan(0, 0, tz.Bias, 0);
298  
-        break;
299  
-  }
300  
-
  286
+  time += GetTimezoneBias();
301 287
   return time;
302 288
 }
303 289
 
@@ -879,24 +865,43 @@ CStdString CDateTime::GetAsSaveString() const
879 865
 
880 866
 void CDateTime::SetFromUTCDateTime(const CDateTime &dateTime)
881 867
 {
882  
-  TIME_ZONE_INFORMATION tz;
883 868
   CDateTime tmp(dateTime);
  869
+  tmp -= GetTimezoneBias();
  870
+
  871
+  m_time = tmp.m_time;
  872
+  m_state = tmp.m_state;
  873
+}
  874
+
  875
+static bool bGotTimezoneBias = false;
  876
+
  877
+void CDateTime::ResetTimezoneBias(void)
  878
+{
  879
+  bGotTimezoneBias = false;
  880
+}
  881
+
  882
+CDateTimeSpan CDateTime::GetTimezoneBias(void)
  883
+{
  884
+  static CDateTimeSpan timezoneBias;
884 885
 
885  
-  switch(GetTimeZoneInformation(&tz))
  886
+  if (!bGotTimezoneBias)
886 887
   {
887  
-    case TIME_ZONE_ID_DAYLIGHT:
888  
-        tmp -= CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
  888
+    bGotTimezoneBias = true;
  889
+    TIME_ZONE_INFORMATION tz;
  890
+    switch(GetTimeZoneInformation(&tz))
  891
+    {
  892
+      case TIME_ZONE_ID_DAYLIGHT:
  893
+        timezoneBias = CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
889 894
         break;
890  
-    case TIME_ZONE_ID_STANDARD:
891  
-        tmp -= CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
  895
+      case TIME_ZONE_ID_STANDARD:
  896
+        timezoneBias = CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
892 897
         break;
893  
-    case TIME_ZONE_ID_UNKNOWN:
894  
-        tmp -= CDateTimeSpan(0, 0, tz.Bias, 0);
  898
+      case TIME_ZONE_ID_UNKNOWN:
  899
+        timezoneBias = CDateTimeSpan(0, 0, tz.Bias, 0);
895 900
         break;
  901
+    }
896 902
   }
897 903
 
898  
-  m_time = tmp.m_time;
899  
-  m_state = tmp.m_state;
  904
+  return timezoneBias;
900 905
 }
901 906
 
902 907
 void CDateTime::SetFromUTCDateTime(const time_t &dateTime)
@@ -1328,22 +1333,8 @@ CStdString CDateTime::GetAsLocalizedDateTime(bool longDate/*=false*/, bool withS
1328 1333
 
1329 1334
 CDateTime CDateTime::GetAsUTCDateTime() const
1330 1335
 {
1331  
-  TIME_ZONE_INFORMATION tz;
1332  
-
1333 1336
   CDateTime time(m_time);
1334  
-  switch(GetTimeZoneInformation(&tz))
1335  
-  {
1336  
-    case TIME_ZONE_ID_DAYLIGHT:
1337  
-        time += CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
1338  
-        break;
1339  
-    case TIME_ZONE_ID_STANDARD:
1340  
-        time += CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
1341  
-        break;
1342  
-    case TIME_ZONE_ID_UNKNOWN:
1343  
-        time += CDateTimeSpan(0, 0, tz.Bias, 0);
1344  
-        break;
1345  
-  }
1346  
-
  1337
+  time += GetTimezoneBias();
1347 1338
   return time;
1348 1339
 }
1349 1340
 
3  xbmc/XBDateTime.h
@@ -196,6 +196,9 @@ class CDateTime : public IArchivable
196 196
   void SetValid(bool yesNo);
197 197
   bool IsValid() const;
198 198
 
  199
+  static void ResetTimezoneBias(void);
  200
+  static CDateTimeSpan GetTimezoneBias(void);
  201
+
199 202
 private:
200 203
   bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
201 204
   bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
10  xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -1880,6 +1880,8 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
1880 1880
 
1881 1881
     CGUISpinControlEx *tzControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezone")->GetID());
1882 1882
     g_guiSettings.SetString("locale.timezone", tzControl->GetLabel().c_str());
  1883
+
  1884
+    CDateTime::ResetTimezoneBias();
1883 1885
   }
1884 1886
   else  if (strSetting.Equals("locale.timezone"))
1885 1887
   {
@@ -1889,6 +1891,8 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
1889 1891
 
1890 1892
      tzControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezonecountry")->GetID());
1891 1893
      g_guiSettings.SetString("locale.timezonecountry", tzControl->GetLabel().c_str());
  1894
+
  1895
+     CDateTime::ResetTimezoneBias();
1892 1896
   }
1893 1897
 #endif
1894 1898
   else if (strSetting.Equals("lookandfeel.skinzoom"))
@@ -1908,12 +1912,18 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
1908 1912
   {
1909 1913
     if (g_PVRManager.CheckParentalPIN(g_localizeStrings.Get(19262).c_str()) &&
1910 1914
         CGUIDialogYesNo::ShowAndGetInput(19098, 19186, 750, 0))
  1915
+    {
  1916
+      CDateTime::ResetTimezoneBias();
1911 1917
       g_PVRManager.ResetDatabase();
  1918
+    }
1912 1919
   }
1913 1920
   else if (strSetting.Equals("epg.resetepg"))
1914 1921
   {
1915 1922
     if (CGUIDialogYesNo::ShowAndGetInput(19098, 19188, 750, 0))
  1923
+    {
  1924
+      CDateTime::ResetTimezoneBias();
1916 1925
       g_PVRManager.ResetEPG();
  1926
+    }
1917 1927
   }
1918 1928
   else if (strSetting.Equals("pvrmanager.channelscan") && g_PVRManager.IsStarted())
1919 1929
   {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.