Implement new static function wxDateTime::GetFirstWeekDay()

This function tries to determine the preferred first day of week to use in
calendars. The procedure for obtaining this information is highly
platform-dependent, and is not possible on all platforms; in that case
Sunday is used as the fallback value.

Implementations are included for MSW, OSX, and Linux.
This commit is contained in:
Lauri Nurmi
2017-07-09 12:12:04 +03:00
parent 6527607af7
commit 94c35b2cdd
7 changed files with 142 additions and 0 deletions

View File

@@ -541,6 +541,55 @@ bool wxDateTime::IsLeapYear(int year, wxDateTime::Calendar cal)
}
}
#ifdef __WINDOWS__
#include "wx/msw/registry.h"
/* static */
bool wxDateTime::GetFirstWeekDay(wxDateTime::WeekDay *firstDay)
{
wxCHECK_MSG( firstDay, false, wxS("output parameter must be non-null") );
wxRegKey key(wxRegKey::HKCU, "Control Panel\\International");
wxString val;
if ( key.Exists() && key.HasValue("iFirstDayOfWeek") )
{
key.QueryValue("iFirstDayOfWeek", val);
*firstDay = wxDateTime::WeekDay((wxAtoi(val) + 1) % 7);
return true;
}
else
{
*firstDay = wxDateTime::Sun;
return false;
}
}
#elif defined(__APPLE__)
// implementation in utils_base.mm
#elif defined(HAVE_NL_TIME_FIRST_WEEKDAY)
#include <langinfo.h>
/* static */
bool wxDateTime::GetFirstWeekDay(wxDateTime::WeekDay *firstDay)
{
wxCHECK_MSG( firstDay, false, wxS("output parameter must be non-null") );
*firstDay = wxDateTime::WeekDay((*nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7);
return true;
}
#else
/* static */
bool wxDateTime::GetFirstWeekDay(wxDateTime::WeekDay *firstDay)
{
wxCHECK_MSG( firstDay, false, wxS("output parameter must be non-null") );
*firstDay = wxDateTime::Sun;
return false;
}
#endif
/* static */
int wxDateTime::GetCentury(int year)
{