std::string InnerConfig::GetUTCStringFromTimeT( int32 time )//Fri, 19 Jul 2013 02:09:39 GMT
{
std::string domain_long_polling;
base::Time local_time = base::Time::FromTimeT(time);
base::Time::Exploded server_exploded;
local_time.UTCExplode(&server_exploded);
std::string week[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
std::string month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
#if defined(OS_MACOSX)
server_exploded.day_of_week = GetWeekdayByYMD(server_exploded.year, server_exploded.month, server_exploded.day_of_month);
#endif
char c_DateTime[128];
base::snprintf(c_DateTime, 128, "%s, %d %s %d %02d:%02d:%02d GMT", week[server_exploded.day_of_week].c_str(), server_exploded.day_of_month,
month[server_exploded.month - 1].c_str(), server_exploded.year, server_exploded.hour, server_exploded.minute, server_exploded.second);
domain_long_polling.append(c_DateTime);
return domain_long_polling;
}
int InnerConfig::GetWeekdayByYMD(const int year, const int month, const int day)
{
int a = (14 - month) / 12;
int y = year - a;
int m = month + 12 * a - 2;
int d = (day + y + y / 4 - y / 100 + y / 400 + 31 * m / 12) % 7;
return d;
}
int InnerConfig::CompareUTCString( const std::string& utc_src, const std::string& utc_dst )//Fri, 19 Jul 2013 02:09:39 GMT
{
base::Time time_src;
base::Time time_dst;
if (!base::Time::FromString(base::SysUTF8ToWide(utc_src).c_str(), &time_src) || !base::Time::FromString(base::SysUTF8ToWide(utc_dst).c_str(), &time_dst))
{
return 0;
}
int64 int_src = time_src.ToInternalValue();
int64 int_dst = time_dst.ToInternalValue();
if (int_src < int_dst)
return -1;
else if (int_src == int_dst)
return 0;
else
return 1;
}