Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
store the timezone bias in a static, so we don't call GetTimeZoneInfo…
Browse files Browse the repository at this point in the history
…rmation() on each conversion (it's slow)
  • Loading branch information
opdenkamp committed Oct 4, 2012
1 parent 35d401b commit 6801b9f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
65 changes: 25 additions & 40 deletions xbmc/XBDateTime.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -282,22 +282,8 @@ CDateTime CDateTime::GetCurrentDateTime()


CDateTime CDateTime::GetUTCDateTime() CDateTime CDateTime::GetUTCDateTime()
{ {
TIME_ZONE_INFORMATION tz;

CDateTime time(GetCurrentDateTime()); CDateTime time(GetCurrentDateTime());
switch(GetTimeZoneInformation(&tz)) time += GetTimezoneBias();
{
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;
}

return time; return time;
} }


Expand Down Expand Up @@ -879,24 +865,37 @@ CStdString CDateTime::GetAsSaveString() const


void CDateTime::SetFromUTCDateTime(const CDateTime &dateTime) void CDateTime::SetFromUTCDateTime(const CDateTime &dateTime)
{ {
TIME_ZONE_INFORMATION tz;
CDateTime tmp(dateTime); 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: bGotTimezoneBias = true;
tmp -= CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0); TIME_ZONE_INFORMATION tz;
switch(GetTimeZoneInformation(&tz))
{
case TIME_ZONE_ID_DAYLIGHT:
timezoneBias = CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
break; break;
case TIME_ZONE_ID_STANDARD: case TIME_ZONE_ID_STANDARD:
tmp -= CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0); timezoneBias = CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
break; break;
case TIME_ZONE_ID_UNKNOWN: case TIME_ZONE_ID_UNKNOWN:
tmp -= CDateTimeSpan(0, 0, tz.Bias, 0); timezoneBias = CDateTimeSpan(0, 0, tz.Bias, 0);
break; break;
}
} }


m_time = tmp.m_time; return timezoneBias;
m_state = tmp.m_state;
} }


void CDateTime::SetFromUTCDateTime(const time_t &dateTime) void CDateTime::SetFromUTCDateTime(const time_t &dateTime)
Expand Down Expand Up @@ -1328,22 +1327,8 @@ CStdString CDateTime::GetAsLocalizedDateTime(bool longDate/*=false*/, bool withS


CDateTime CDateTime::GetAsUTCDateTime() const CDateTime CDateTime::GetAsUTCDateTime() const
{ {
TIME_ZONE_INFORMATION tz;

CDateTime time(m_time); CDateTime time(m_time);
switch(GetTimeZoneInformation(&tz)) time += GetTimezoneBias();
{
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;
}

return time; return time;
} }


Expand Down
2 changes: 2 additions & 0 deletions xbmc/XBDateTime.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class CDateTime : public IArchivable
void SetValid(bool yesNo); void SetValid(bool yesNo);
bool IsValid() const; bool IsValid() const;


static CDateTimeSpan GetTimezoneBias(void);

private: private:
bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const; bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
bool ToFileTime(const time_t& time, FILETIME& fileTime) const; bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
Expand Down

0 comments on commit 6801b9f

Please sign in to comment.