Skip to content

Commit

Permalink
expose date custom formating by refactoring CDateTime::GetAsLocalized…
Browse files Browse the repository at this point in the history
…Date
  • Loading branch information
pieh committed Aug 29, 2011
1 parent a1246de commit 74bb7db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions xbmc/XBDateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,9 +1116,12 @@ CStdString CDateTime::GetAsLocalizedTime(const CStdString &format, bool withSeco

CStdString CDateTime::GetAsLocalizedDate(bool longDate/*=false*/, bool withShortNames/*=true*/) const
{
CStdString strOut;
return GetAsLocalizedDate(g_langInfo.GetDateFormat(longDate), withShortNames);
}

const CStdString& strFormat=g_langInfo.GetDateFormat(longDate);
CStdString CDateTime::GetAsLocalizedDate(const CStdString &strFormat, bool withShortNames/*=true*/) const
{
CStdString strOut;

SYSTEMTIME dateTime;
GetAsSystemTime(dateTime);
Expand Down Expand Up @@ -1150,7 +1153,7 @@ CStdString CDateTime::GetAsLocalizedDate(bool longDate/*=false*/, bool withShort
strPart.Replace("''", "'");
strOut+=strPart;
}
else if (c=='D') // parse days
else if (c=='D' || c=='d') // parse days
{
int partLength=0;

Expand Down Expand Up @@ -1178,11 +1181,11 @@ CStdString CDateTime::GetAsLocalizedDate(bool longDate/*=false*/, bool withShort
{
int wday = dateTime.wDayOfWeek;
if (wday < 1 || wday > 7) wday = 7;
str = g_localizeStrings.Get((withShortNames ? 40 : 10) + wday);
str = g_localizeStrings.Get(((withShortNames || c =='d') ? 40 : 10) + wday);
}
strOut+=str;
}
else if (c=='M') // parse month
else if (c=='M' || c=='m') // parse month
{
int partLength=0;

Expand Down Expand Up @@ -1210,11 +1213,11 @@ CStdString CDateTime::GetAsLocalizedDate(bool longDate/*=false*/, bool withShort
{
int wmonth = dateTime.wMonth;
if (wmonth < 1 || wmonth > 12) wmonth = 12;
str = g_localizeStrings.Get((withShortNames ? 50 : 20) + wmonth);
str = g_localizeStrings.Get(((withShortNames || c =='m') ? 50 : 20) + wmonth);
}
strOut+=str;
}
else if (c=='Y') // parse year
else if (c=='Y' || c =='y') // parse year
{
int partLength=0;

Expand Down
1 change: 1 addition & 0 deletions xbmc/XBDateTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class CDateTime : public IArchivable
CStdString GetAsDBDateTime() const;
CStdString GetAsDBDate() const;
CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
CStdString GetAsLocalizedDate(const CStdString &strFormat, bool withShortNames=true) const;
CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
CStdString GetAsRFC1123DateTime() const;
Expand Down

0 comments on commit 74bb7db

Please sign in to comment.