Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / XBDateTime.cpp
index fed91ff..995f9b7 100644 (file)
 #include "LangInfo.h"
 #include "guilib/LocalizeStrings.h"
 #include "utils/log.h"
+#include "utils/StringUtils.h"
+#ifdef TARGET_POSIX
+#include "XTimeUtils.h"
+#include "XFileUtils.h"
+#else
+#include <Windows.h>
+#endif
 
 #define SECONDS_PER_DAY 86400UL
 #define SECONDS_PER_HOUR 3600UL
@@ -174,9 +181,12 @@ void CDateTimeSpan::SetDateTimeSpan(int day, int hour, int minute, int second)
 
 void CDateTimeSpan::SetFromTimeString(const CStdString& time) // hh:mm
 {
-  int hour    = atoi(time.Mid(0,2).c_str());
-  int minutes = atoi(time.Mid(3,2).c_str());
-  SetDateTimeSpan(0,hour,minutes,0);
+  if (time.size() >= 5 && time[2] == ':')
+  {
+    int hour    = atoi(time.substr(0, 2).c_str());
+    int minutes = atoi(time.substr(3, 2).c_str());
+    SetDateTimeSpan(0,hour,minutes,0);
+  }
 }
 
 int CDateTimeSpan::GetDays() const
@@ -211,17 +221,25 @@ int CDateTimeSpan::GetSeconds() const
   return (int)(((time.QuadPart/SECONDS_TO_FILETIME%SECONDS_PER_DAY)%SECONDS_PER_HOUR)%SECONDS_PER_MINUTE)%SECONDS_PER_MINUTE;
 }
 
+int CDateTimeSpan::GetSecondsTotal() const
+{
+  ULARGE_INTEGER time;
+  ToULargeInt(time);
+  
+  return (int)(time.QuadPart/SECONDS_TO_FILETIME);
+}
+
 void CDateTimeSpan::SetFromPeriod(const CStdString &period)
 {
   long days = atoi(period.c_str());
   // find the first non-space and non-number
-  int pos = period.find_first_not_of("0123456789 ", 0);
-  if (pos >= 0)
+  size_t pos = period.find_first_not_of("0123456789 ", 0);
+  if (pos != std::string::npos)
   {
-    CStdString units = period.Mid(pos, 3);
-    if (units.CompareNoCase("wee") == 0)
+    CStdString units = period.substr(pos, 3);
+    if (StringUtils::EqualsNoCase(units, "wee"))
       days *= 7;
-    else if (units.CompareNoCase("mon") == 0)
+    else if (StringUtils::EqualsNoCase(units, "mon"))
       days *= 31;
   }
 
@@ -669,42 +687,43 @@ void CDateTime::FromULargeInt(const ULARGE_INTEGER& time)
   m_time.dwLowDateTime=time.u.LowPart;
 }
 
-void CDateTime::SetFromDateString(const CStdString &date)
+bool CDateTime::SetFromDateString(const CStdString &date)
 {
-  if (date.IsEmpty())
+  /* TODO:STRING_CLEANUP */
+  if (date.empty())
   {
     SetValid(false);
-    return;
+    return false;
   }
 
+  if (SetFromDBDate(date))
+    return true;
+
   const char* months[] = {"january","february","march","april","may","june","july","august","september","october","november","december",NULL};
   int j=0;
-  int iDayPos = date.Find("day");
-  int iPos = date.Find(" ");
-  if (iDayPos < iPos && iDayPos > -1)
+  size_t iDayPos = date.find("day");
+  size_t iPos = date.find(" ");
+  if (iDayPos < iPos && iDayPos != std::string::npos)
   {
-    iDayPos = iPos+1;
-    iPos = date.Find(" ",iPos+1);
+    iDayPos = iPos + 1;
+    iPos = date.find(" ", iPos+1);
   }
   else
     iDayPos = 0;
 
-  CStdString strMonth = date.Mid(iDayPos,iPos-iDayPos);
-  if (strMonth.IsEmpty()) // assume dbdate format
-  {
-    SetFromDBDate(date);
-    return;
-  }
+  CStdString strMonth = date.substr(iDayPos, iPos - iDayPos);
+  if (strMonth.empty())
+    return false;
 
-  int iPos2 = date.Find(",");
-  CStdString strDay = date.Mid(iPos,iPos2-iPos);
-  CStdString strYear = date.Mid(date.Find(" ",iPos2)+1);
+  size_t iPos2 = date.find(",");
+  CStdString strDay = (date.size() >= iPos) ? date.substr(iPos, iPos2-iPos) : "";
+  CStdString strYear = date.substr(date.find(" ", iPos2) + 1);
   while (months[j] && stricmp(strMonth.c_str(),months[j]) != 0)
     j++;
   if (!months[j])
-    return;
+    return false;
 
-  SetDateTime(atol(strYear.c_str()),j+1,atol(strDay.c_str()),0,0,0);
+  return SetDateTime(atol(strYear.c_str()),j+1,atol(strDay.c_str()),0,0,0);
 }
 
 int CDateTime::GetDay() const
@@ -770,7 +789,7 @@ int CDateTime::GetMinuteOfDay() const
   return st.wHour*60+st.wMinute;
 }
 
-void CDateTime::SetDateTime(int year, int month, int day, int hour, int minute, int second)
+bool CDateTime::SetDateTime(int year, int month, int day, int hour, int minute, int second)
 {
   SYSTEMTIME st;
   ZeroMemory(&st, sizeof(SYSTEMTIME));
@@ -783,17 +802,18 @@ void CDateTime::SetDateTime(int year, int month, int day, int hour, int minute,
   st.wSecond=second;
 
   m_state = ToFileTime(st, m_time) ? valid : invalid;
+  return m_state == valid;
 }
 
-void CDateTime::SetDate(int year, int month, int day)
+bool CDateTime::SetDate(int year, int month, int day)
 {
-  SetDateTime(year, month, day, 0, 0, 0);
+  return SetDateTime(year, month, day, 0, 0, 0);
 }
 
-void CDateTime::SetTime(int hour, int minute, int second)
+bool CDateTime::SetTime(int hour, int minute, int second)
 {
   // 01.01.1601 00:00:00 is 0 as filetime
-  SetDateTime(1601, 1, 1, hour, minute, second);
+  return SetDateTime(1601, 1, 1, hour, minute, second);
 }
 
 void CDateTime::GetAsSystemTime(SYSTEMTIME& time) const
@@ -835,10 +855,7 @@ CStdString CDateTime::GetAsDBDate() const
   SYSTEMTIME st;
   GetAsSystemTime(st);
 
-  CStdString date;
-  date.Format("%04i-%02i-%02i", st.wYear, st.wMonth, st.wDay);
-
-  return date;
+  return StringUtils::Format("%04i-%02i-%02i", st.wYear, st.wMonth, st.wDay);
 }
 
 CStdString CDateTime::GetAsDBDateTime() const
@@ -846,10 +863,7 @@ CStdString CDateTime::GetAsDBDateTime() const
   SYSTEMTIME st;
   GetAsSystemTime(st);
 
-  CStdString date;
-  date.Format("%04i-%02i-%02i %02i:%02i:%02i", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
-
-  return date;
+  return StringUtils::Format("%04i-%02i-%02i %02i:%02i:%02i", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
 }
 
 CStdString CDateTime::GetAsSaveString() const
@@ -857,19 +871,17 @@ CStdString CDateTime::GetAsSaveString() const
   SYSTEMTIME st;
   GetAsSystemTime(st);
 
-  CStdString date;
-  date.Format("%04i%02i%02i_%02i%02i%02i", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
-
-  return date;
+  return StringUtils::Format("%04i%02i%02i_%02i%02i%02i", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);;
 }
 
-void CDateTime::SetFromUTCDateTime(const CDateTime &dateTime)
+bool CDateTime::SetFromUTCDateTime(const CDateTime &dateTime)
 {
   CDateTime tmp(dateTime);
   tmp -= GetTimezoneBias();
 
   m_time = tmp.m_time;
   m_state = tmp.m_state;
+  return m_state == valid;
 }
 
 static bool bGotTimezoneBias = false;
@@ -904,27 +916,27 @@ CDateTimeSpan CDateTime::GetTimezoneBias(void)
   return timezoneBias;
 }
 
-void CDateTime::SetFromUTCDateTime(const time_t &dateTime)
+bool CDateTime::SetFromUTCDateTime(const time_t &dateTime)
 {
   CDateTime tmp(dateTime);
-  SetFromUTCDateTime(tmp);
+  return SetFromUTCDateTime(tmp);
 }
 
-void CDateTime::SetFromW3CDate(const CStdString &dateTime)
+bool CDateTime::SetFromW3CDate(const CStdString &dateTime)
 {
   CStdString date, time, zone;
 
-  int posT = dateTime.Find("T");
-  if(posT >= 0)
+  size_t posT = dateTime.find("T");
+  if(posT != std::string::npos)
   {
-    date = dateTime.Left(posT);
+    date = dateTime.substr(0, posT);
     CStdString::size_type posZ = dateTime.find_first_of("+-Z", posT);
     if(posZ == CStdString::npos)
-      time = dateTime.Mid(posT+1);
+      time = dateTime.substr(posT + 1);
     else
     {
-      time = dateTime.Mid(posT+1, posZ-posT-1);
-      zone = dateTime.Mid(posZ);
+      time = dateTime.substr(posT + 1, posZ - posT - 1);
+      zone = dateTime.substr(posZ);
     }
   }
   else
@@ -933,85 +945,91 @@ void CDateTime::SetFromW3CDate(const CStdString &dateTime)
   int year = 0, month = 1, day = 1, hour = 0, min = 0, sec = 0;
 
   if (date.size() >= 4)
-    year  = atoi(date.Mid(0,4).c_str());
+    year  = atoi(date.substr(0, 4).c_str());
 
   if (date.size() >= 10)
   {
-    month = atoi(date.Mid(5,2).c_str());
-    day   = atoi(date.Mid(8,2).c_str());
+    month = atoi(date.substr(5, 2).c_str());
+    day   = atoi(date.substr(8, 2).c_str());
   }
 
   if (time.length() >= 5)
   {
-    hour = atoi(time.Mid(0,2).c_str());
-    min  = atoi(time.Mid(3,2).c_str());
+    hour = atoi(time.substr(0, 2).c_str());
+    min  = atoi(time.substr(3, 2).c_str());
   }
 
   if (time.length() >= 8)
-    sec  = atoi(time.Mid(6,2).c_str());
+    sec  = atoi(time.substr(6, 2).c_str());
 
-  SetDateTime(year, month, day, hour, min, sec);
+  return SetDateTime(year, month, day, hour, min, sec);
 }
 
-void CDateTime::SetFromDBDateTime(const CStdString &dateTime)
+bool CDateTime::SetFromDBDateTime(const CStdString &dateTime)
 {
   // assumes format YYYY-MM-DD HH:MM:SS
   if (dateTime.size() == 19)
   {
-    int year  = atoi(dateTime.Mid(0,4).c_str());
-    int month = atoi(dateTime.Mid(5,2).c_str());
-    int day   = atoi(dateTime.Mid(8,2).c_str());
-    int hour  = atoi(dateTime.Mid(11,2).c_str());
-    int min   = atoi(dateTime.Mid(14,2).c_str());
-    int sec   = atoi(dateTime.Mid(17,2).c_str());
-    SetDateTime(year, month, day, hour, min, sec);
+    int year  = atoi(dateTime.substr(0, 4).c_str());
+    int month = atoi(dateTime.substr(5, 2).c_str());
+    int day   = atoi(dateTime.substr(8, 2).c_str());
+    int hour  = atoi(dateTime.substr(11, 2).c_str());
+    int min   = atoi(dateTime.substr(14, 2).c_str());
+    int sec   = atoi(dateTime.substr(17, 2).c_str());
+    return SetDateTime(year, month, day, hour, min, sec);
   }
+  return false;
 }
 
-void CDateTime::SetFromDBDate(const CStdString &date)
+bool CDateTime::SetFromDBDate(const CStdString &date)
 {
+  if (date.size() < 10)
+    return false;
   // assumes format:
   // YYYY-MM-DD or DD-MM-YYYY
+  const static std::string sep_chars = "-./";
   int year = 0, month = 0, day = 0;
-  if (date.size() > 2 && (date[2] == '-' || date[2] == '.'))
+  if (sep_chars.find(date[2]) != std::string::npos)
   {
-    day = atoi(date.Mid(0,2).c_str());
-    month = atoi(date.Mid(3,2).c_str());
-    year = atoi(date.Mid(6,4).c_str());
+    day = atoi(date.substr(0, 2).c_str());
+    month = atoi(date.substr(3, 2).c_str());
+    year = atoi(date.substr(6, 4).c_str());
   }
-  else
+  else if (sep_chars.find(date[4]) != std::string::npos)
   {
-    year = atoi(date.Mid(0,4).c_str());
-    month = atoi(date.Mid(5,2).c_str());
-    day = atoi(date.Mid(8,2).c_str());
+    year = atoi(date.substr(0, 4).c_str());
+    month = atoi(date.substr(5, 2).c_str());
+    day = atoi(date.substr(8, 2).c_str());
   }
-  SetDate(year, month, day);
+  return SetDate(year, month, day);
 }
 
-void CDateTime::SetFromDBTime(const CStdString &time)
+bool CDateTime::SetFromDBTime(const CStdString &time)
 {
+  if (time.size() < 8)
+    return false;
   // assumes format:
   // HH:MM:SS
   int hour, minute, second;
 
-  hour   = atoi(time.Mid(0,2).c_str());
-  minute = atoi(time.Mid(3,2).c_str());
-  second = atoi(time.Mid(6,2).c_str());
+  hour   = atoi(time.substr(0, 2).c_str());
+  minute = atoi(time.substr(3, 2).c_str());
+  second = atoi(time.substr(6, 2).c_str());
 
-  SetTime(hour, minute, second);
+  return SetTime(hour, minute, second);
 }
 
-void CDateTime::SetFromRFC1123DateTime(const CStdString &dateTime)
+bool CDateTime::SetFromRFC1123DateTime(const CStdString &dateTime)
 {
   CStdString date = dateTime;
-  date.Trim();
+  StringUtils::Trim(date);
 
   if (date.size() != 29)
-    return;
+    return false;
 
-  int day  = strtol(date.Mid(5, 2).c_str(), NULL, 10);
+  int day  = strtol(date.substr(5, 2).c_str(), NULL, 10);
 
-  CStdString strMonth = date.Mid(8, 3);
+  CStdString strMonth = date.substr(8, 3);
   int month = 0;
   for (unsigned int index = 0; index < 12; index++)
   {
@@ -1023,20 +1041,20 @@ void CDateTime::SetFromRFC1123DateTime(const CStdString &dateTime)
   }
 
   if (month < 1)
-    return;
+    return false;
 
-  int year = strtol(date.Mid(12, 4).c_str(), NULL, 10);
-  int hour = strtol(date.Mid(17, 2).c_str(), NULL, 10);
-  int min  = strtol(date.Mid(20, 2).c_str(), NULL, 10);
-  int sec  = strtol(date.Mid(23, 2).c_str(), NULL, 10);
+  int year = strtol(date.substr(12, 4).c_str(), NULL, 10);
+  int hour = strtol(date.substr(17, 2).c_str(), NULL, 10);
+  int min  = strtol(date.substr(20, 2).c_str(), NULL, 10);
+  int sec  = strtol(date.substr(23, 2).c_str(), NULL, 10);
 
-  SetDateTime(year, month, day, hour, min, sec);
+  return SetDateTime(year, month, day, hour, min, sec);
 }
 
 CStdString CDateTime::GetAsLocalizedTime(const CStdString &format, bool withSeconds) const
 {
   CStdString strOut;
-  const CStdString& strFormat = format.IsEmpty() ? g_langInfo.GetTimeFormat() : format;
+  const CStdString& strFormat = format.empty() ? g_langInfo.GetTimeFormat() : format;
 
   SYSTEMTIME dateTime;
   GetAsSystemTime(dateTime);
@@ -1044,31 +1062,32 @@ CStdString CDateTime::GetAsLocalizedTime(const CStdString &format, bool withSeco
   // Prefetch meridiem symbol
   const CStdString& strMeridiem=g_langInfo.GetMeridiemSymbol(dateTime.wHour > 11 ? CLangInfo::MERIDIEM_SYMBOL_PM : CLangInfo::MERIDIEM_SYMBOL_AM);
 
-  int length=strFormat.GetLength();
-  for (int i=0; i<length; ++i)
+  size_t length = strFormat.size();
+  for (size_t i=0; i < length; ++i)
   {
     char c=strFormat[i];
     if (c=='\'')
     {
       // To be able to display a "'" in the string,
       // find the last "'" that doesn't follow a "'"
-      int pos=i+1;
-      while(((pos=strFormat.Find(c,pos+1))>-1 && pos<strFormat.GetLength()) && strFormat[pos+1]=='\'') {}
+      size_t pos=i + 1;
+      while(((pos = strFormat.find(c, pos + 1)) != std::string::npos &&
+             pos<strFormat.size()) && strFormat[pos+1]=='\'') {}
 
       CStdString strPart;
-      if (pos>-1)
+      if (pos != std::string::npos)
       {
         // Extract string between ' '
-        strPart=strFormat.Mid(i+1, pos-i-1);
+        strPart=strFormat.substr(i + 1, pos - i - 1);
         i=pos;
       }
       else
       {
-        strPart=strFormat.Mid(i+1, length-i-1);
+        strPart=strFormat.substr(i + 1, length - i - 1);
         i=length;
       }
 
-      strPart.Replace("''", "'");
+      StringUtils::Replace(strPart, "''", "'");
 
       strOut+=strPart;
     }
@@ -1102,9 +1121,9 @@ CStdString CDateTime::GetAsLocalizedTime(const CStdString &format, bool withSeco
       // Format hour string with the length of the mask
       CStdString str;
       if (partLength==1)
-        str.Format("%d", hour);
+        str = StringUtils::Format("%d", hour);
       else
-        str.Format("%02d", hour);
+        str = StringUtils::Format("%02d", hour);
 
       strOut+=str;
     }
@@ -1129,9 +1148,9 @@ CStdString CDateTime::GetAsLocalizedTime(const CStdString &format, bool withSeco
       // Format minute string with the length of the mask
       CStdString str;
       if (partLength==1)
-        str.Format("%d", dateTime.wMinute);
+        str = StringUtils::Format("%d", dateTime.wMinute);
       else
-        str.Format("%02d", dateTime.wMinute);
+        str = StringUtils::Format("%02d", dateTime.wMinute);
 
       strOut+=str;
     }
@@ -1158,14 +1177,14 @@ CStdString CDateTime::GetAsLocalizedTime(const CStdString &format, bool withSeco
         // Format seconds string with the length of the mask
         CStdString str;
         if (partLength==1)
-          str.Format("%d", dateTime.wSecond);
+          str = StringUtils::Format("%d", dateTime.wSecond);
         else
-          str.Format("%02d", dateTime.wSecond);
+          str = StringUtils::Format("%02d", dateTime.wSecond);
 
         strOut+=str;
       }
       else
-        strOut.Delete(strOut.GetLength()-1,1);
+        strOut.erase(strOut.size()-1,1);
     }
     else if (c=='x') // add meridiem symbol
     {
@@ -1202,39 +1221,40 @@ CStdString CDateTime::GetAsLocalizedDate(const CStdString &strFormat, bool withS
   SYSTEMTIME dateTime;
   GetAsSystemTime(dateTime);
 
-  int length=strFormat.GetLength();
-
-  for (int i=0; i<length; ++i)
+  size_t length = strFormat.size();
+  for (size_t i = 0; i < length; ++i)
   {
     char c=strFormat[i];
     if (c=='\'')
     {
       // To be able to display a "'" in the string,
       // find the last "'" that doesn't follow a "'"
-      int pos=i+1;
-      while(((pos=strFormat.Find(c,pos+1))>-1 && pos<strFormat.GetLength()) && strFormat[pos+1]=='\'') {}
+      size_t pos = i + 1;
+      while(((pos = strFormat.find(c, pos + 1)) != std::string::npos &&
+             pos < strFormat.size()) &&
+            strFormat[pos + 1] == '\'') {}
 
       CStdString strPart;
-      if (pos>-1)
+      if (pos != std::string::npos)
       {
         // Extract string between ' '
-        strPart=strFormat.Mid(i+1, pos-i-1);
-        i=pos;
+        strPart = strFormat.substr(i + 1, pos - i - 1);
+        i = pos;
       }
       else
       {
-        strPart=strFormat.Mid(i+1, length-i-1);
-        i=length;
+        strPart = strFormat.substr(i + 1, length - i - 1);
+        i = length;
       }
-      strPart.Replace("''", "'");
+      StringUtils::Replace(strPart, "''", "'");
       strOut+=strPart;
     }
     else if (c=='D' || c=='d') // parse days
     {
-      int partLength=0;
+      size_t partLength=0;
 
-      int pos=strFormat.find_first_not_of(c,i+1);
-      if (pos>-1)
+      size_t pos = strFormat.find_first_not_of(c, i+1);
+      if (pos != std::string::npos)
       {
         // Get length of the day mask, eg. DDDD
         partLength=pos-i;
@@ -1250,9 +1270,9 @@ CStdString CDateTime::GetAsLocalizedDate(const CStdString &strFormat, bool withS
       // Format string with the length of the mask
       CStdString str;
       if (partLength==1) // single-digit number
-        str.Format("%d", dateTime.wDay);
+        str = StringUtils::Format("%d", dateTime.wDay);
       else if (partLength==2) // two-digit number
-        str.Format("%02d", dateTime.wDay);
+        str = StringUtils::Format("%02d", dateTime.wDay);
       else // Day of week string
       {
         int wday = dateTime.wDayOfWeek;
@@ -1263,10 +1283,10 @@ CStdString CDateTime::GetAsLocalizedDate(const CStdString &strFormat, bool withS
     }
     else if (c=='M' || c=='m') // parse month
     {
-      int partLength=0;
+      size_t partLength=0;
 
-      int pos=strFormat.find_first_not_of(c,i+1);
-      if (pos>-1)
+      size_t pos=strFormat.find_first_not_of(c,i+1);
+      if (pos != std::string::npos)
       {
         // Get length of the month mask, eg. MMMM
         partLength=pos-i;
@@ -1282,9 +1302,9 @@ CStdString CDateTime::GetAsLocalizedDate(const CStdString &strFormat, bool withS
       // Format string with the length of the mask
       CStdString str;
       if (partLength==1) // single-digit number
-        str.Format("%d", dateTime.wMonth);
+        str = StringUtils::Format("%d", dateTime.wMonth);
       else if (partLength==2) // two-digit number
-        str.Format("%02d", dateTime.wMonth);
+        str = StringUtils::Format("%02d", dateTime.wMonth);
       else // Month string
       {
         int wmonth = dateTime.wMonth;
@@ -1295,10 +1315,10 @@ CStdString CDateTime::GetAsLocalizedDate(const CStdString &strFormat, bool withS
     }
     else if (c=='Y' || c =='y') // parse year
     {
-      int partLength=0;
+      size_t partLength = 0;
 
-      int pos=strFormat.find_first_not_of(c,i+1);
-      if (pos>-1)
+      size_t pos = strFormat.find_first_not_of(c,i+1);
+      if (pos != std::string::npos)
       {
         // Get length of the year mask, eg. YYYY
         partLength=pos-i;
@@ -1312,10 +1332,9 @@ CStdString CDateTime::GetAsLocalizedDate(const CStdString &strFormat, bool withS
       }
 
       // Format string with the length of the mask
-      CStdString str;
-      str.Format("%d", dateTime.wYear); // four-digit number
-      if (partLength<=2)
-        str.Delete(0, 2); // two-digit number
+      CStdString str = StringUtils::Format("%d", dateTime.wYear); // four-digit number
+      if (partLength <= 2)
+        str.erase(0, 2); // two-digit number
 
       strOut+=str;
     }
@@ -1358,8 +1377,7 @@ CStdString CDateTime::GetAsRFC1123DateTime() const
   if (month != time.GetMonth())
     CLog::Log(LOGWARNING, "Invalid month %d in %s", time.GetMonth(), time.GetAsDBDateTime().c_str());
 
-  CStdString result;
-  result.Format("%s, %02i %s %04i %02i:%02i:%02i GMT", DAY_NAMES[weekDay], time.GetDay(), MONTH_NAMES[month - 1], time.GetYear(), time.GetHour(), time.GetMinute(), time.GetSecond());
+  CStdString result = StringUtils::Format("%s, %02i %s %04i %02i:%02i:%02i GMT", DAY_NAMES[weekDay], time.GetDay(), MONTH_NAMES[month - 1], time.GetYear(), time.GetHour(), time.GetMinute(), time.GetSecond());
   return result;
 }
 
@@ -1369,7 +1387,7 @@ int CDateTime::MonthStringToMonthNum(const CStdString& month)
   const char* abr_months[] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
 
   int i = 0;
-  for (; i < 12 && month.CompareNoCase(months[i]) != 0 && month.CompareNoCase(abr_months[i]) != 0; i++);
+  for (; i < 12 && !StringUtils::EqualsNoCase(month, months[i]) && !StringUtils::EqualsNoCase(month, abr_months[i]); i++);
   i++;
 
   return i;