Permalink
Browse files

store the timezone bias in a static, so we don't call GetTimeZoneInfo…

…rmation() on each conversion (it's slow)
  • Loading branch information...
1 parent 35d401b commit 6801b9f23f5f1430d96ab8d60fd29ce9ca05e365 @opdenkamp committed Oct 4, 2012
Showing with 27 additions and 40 deletions.
  1. +25 −40 xbmc/XBDateTime.cpp
  2. +2 −0 xbmc/XBDateTime.h
View
@@ -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,37 @@ 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;
+}
+
+CDateTimeSpan CDateTime::GetTimezoneBias(void)
+{
+ static bool bGotTimezoneBias = false;
+ 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 +1327,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
@@ -196,6 +196,8 @@ class CDateTime : public IArchivable
void SetValid(bool yesNo);
bool IsValid() const;
+ static CDateTimeSpan GetTimezoneBias(void);
+
private:
bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
bool ToFileTime(const time_t& time, FILETIME& fileTime) const;

0 comments on commit 6801b9f

Please sign in to comment.