Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1531 from opdenkamp/tzconversion

cache timezone bias
  • Loading branch information...
commit 2336e3a739abef58f81b8852cf6d64797da7ffdf 2 parents 06a932f + 16466cf
@opdenkamp opdenkamp authored
View
71 xbmc/XBDateTime.cpp
@@ -282,22 +282,8 @@ CDateTime CDateTime::GetCurrentDateTime()
CDateTime CDateTime::GetUTCDateTime()
{
- TIME_ZONE_INFORMATION tz;
-
CDateTime time(GetCurrentDateTime());
- switch(GetTimeZoneInformation(&tz))
- {
- case TIME_ZONE_ID_DAYLIGHT:
- time += CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
- break;
- case TIME_ZONE_ID_STANDARD:
- time += CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
- break;
- case TIME_ZONE_ID_UNKNOWN:
- time += CDateTimeSpan(0, 0, tz.Bias, 0);
- break;
- }
-
+ time += GetTimezoneBias();
return time;
}
@@ -879,24 +865,43 @@ CStdString CDateTime::GetAsSaveString() const
void CDateTime::SetFromUTCDateTime(const CDateTime &dateTime)
{
- TIME_ZONE_INFORMATION tz;
CDateTime tmp(dateTime);
+ tmp -= GetTimezoneBias();
+
+ m_time = tmp.m_time;
+ m_state = tmp.m_state;
+}
+
+static bool bGotTimezoneBias = false;
+
+void CDateTime::ResetTimezoneBias(void)
+{
+ bGotTimezoneBias = false;
+}
+
+CDateTimeSpan CDateTime::GetTimezoneBias(void)
+{
+ static CDateTimeSpan timezoneBias;
- switch(GetTimeZoneInformation(&tz))
+ if (!bGotTimezoneBias)
{
- case TIME_ZONE_ID_DAYLIGHT:
- tmp -= CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
+ bGotTimezoneBias = true;
+ TIME_ZONE_INFORMATION tz;
+ switch(GetTimeZoneInformation(&tz))
+ {
+ case TIME_ZONE_ID_DAYLIGHT:
+ timezoneBias = CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
break;
- case TIME_ZONE_ID_STANDARD:
- tmp -= CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
+ case TIME_ZONE_ID_STANDARD:
+ timezoneBias = CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
break;
- case TIME_ZONE_ID_UNKNOWN:
- tmp -= CDateTimeSpan(0, 0, tz.Bias, 0);
+ case TIME_ZONE_ID_UNKNOWN:
+ timezoneBias = CDateTimeSpan(0, 0, tz.Bias, 0);
break;
+ }
}
- m_time = tmp.m_time;
- m_state = tmp.m_state;
+ return timezoneBias;
}
void CDateTime::SetFromUTCDateTime(const time_t &dateTime)
@@ -1328,22 +1333,8 @@ CStdString CDateTime::GetAsLocalizedDateTime(bool longDate/*=false*/, bool withS
CDateTime CDateTime::GetAsUTCDateTime() const
{
- TIME_ZONE_INFORMATION tz;
-
CDateTime time(m_time);
- switch(GetTimeZoneInformation(&tz))
- {
- case TIME_ZONE_ID_DAYLIGHT:
- time += CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
- break;
- case TIME_ZONE_ID_STANDARD:
- time += CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
- break;
- case TIME_ZONE_ID_UNKNOWN:
- time += CDateTimeSpan(0, 0, tz.Bias, 0);
- break;
- }
-
+ time += GetTimezoneBias();
return time;
}
View
3  xbmc/XBDateTime.h
@@ -196,6 +196,9 @@ class CDateTime : public IArchivable
void SetValid(bool yesNo);
bool IsValid() const;
+ static void ResetTimezoneBias(void);
+ static CDateTimeSpan GetTimezoneBias(void);
+
private:
bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
View
10 xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -1880,6 +1880,8 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
CGUISpinControlEx *tzControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezone")->GetID());
g_guiSettings.SetString("locale.timezone", tzControl->GetLabel().c_str());
+
+ CDateTime::ResetTimezoneBias();
}
else if (strSetting.Equals("locale.timezone"))
{
@@ -1889,6 +1891,8 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
tzControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezonecountry")->GetID());
g_guiSettings.SetString("locale.timezonecountry", tzControl->GetLabel().c_str());
+
+ CDateTime::ResetTimezoneBias();
}
#endif
else if (strSetting.Equals("lookandfeel.skinzoom"))
@@ -1908,12 +1912,18 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
{
if (g_PVRManager.CheckParentalPIN(g_localizeStrings.Get(19262).c_str()) &&
CGUIDialogYesNo::ShowAndGetInput(19098, 19186, 750, 0))
+ {
+ CDateTime::ResetTimezoneBias();
g_PVRManager.ResetDatabase();
+ }
}
else if (strSetting.Equals("epg.resetepg"))
{
if (CGUIDialogYesNo::ShowAndGetInput(19098, 19188, 750, 0))
+ {
+ CDateTime::ResetTimezoneBias();
g_PVRManager.ResetEPG();
+ }
}
else if (strSetting.Equals("pvrmanager.channelscan") && g_PVRManager.IsStarted())
{
Please sign in to comment.
Something went wrong with that request. Please try again.