Fixed wrong day of week shown in Time. Needs review as I used some trick
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16445 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f282009d15
commit
25a4d8f957
@ -393,7 +393,7 @@ TCalendarView::InitDates()
|
||||
|
||||
int32 label = 0;
|
||||
int idx = 0;
|
||||
f_firstday = getFirstDay(f_month+1, f_year);
|
||||
f_firstday = getFirstDay(f_month, f_year);
|
||||
int daycnt = getDaysInMonth(f_month, f_year);
|
||||
bool cday = false;
|
||||
for (int row = 0; row < 6; row++) {
|
||||
@ -403,7 +403,8 @@ TCalendarView::InitDates()
|
||||
if (idx < f_firstday || idx > daycnt +f_firstday +1)
|
||||
label = 0;
|
||||
else
|
||||
label = idx -(f_firstday +1);
|
||||
label = idx - (f_firstday - 1);
|
||||
|
||||
idx++;
|
||||
cday = label == f_day;
|
||||
day->SetTo(label, cday);
|
||||
@ -441,7 +442,7 @@ TCalendarView::SetTo(int32 year, int32 month, int32 day)
|
||||
InitDates();
|
||||
} else if (f_day != day) {
|
||||
f_day = day;
|
||||
int idx = ((f_day/7)*7) + (f_day%7 +f_firstday +1);
|
||||
int idx = ((f_day/7)*7) + (f_day%7 +f_firstday - 1);
|
||||
TDay *day = dynamic_cast<TDay *>(ChildAt(idx));
|
||||
f_cday->SetValue(B_CONTROL_OFF);
|
||||
f_cday = day;
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "DateUtils.h"
|
||||
#include "math.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
bool
|
||||
isLeapYear(const int year)
|
||||
{
|
||||
@ -28,26 +30,19 @@ getDaysInMonth(const int month, const int year)
|
||||
int
|
||||
getFirstDay(const int month, const int year)
|
||||
{
|
||||
int l_century = year/100;
|
||||
int l_decade = year%100;
|
||||
int l_month = (month +10)%12;
|
||||
int l_day = 1;
|
||||
struct tm tm;
|
||||
time_t currentTime = time(NULL);
|
||||
localtime_r(¤tTime, &tm);
|
||||
|
||||
if (l_month == 1 || l_month == 2) {
|
||||
if (l_decade == 0) {
|
||||
l_decade = 99;
|
||||
l_century -= 1;
|
||||
} else
|
||||
l_decade-= 1;
|
||||
}
|
||||
// TODO: review this.
|
||||
// We rely on the fact that tm.tm_wday is calculated
|
||||
// starting from the following parameters
|
||||
tm.tm_mon = month;
|
||||
tm.tm_year = year;
|
||||
tm.tm_mday = 1;
|
||||
|
||||
float tmp = (l_day +(floor(((13 *l_month) -1)/5))
|
||||
+l_decade +(floor(l_decade /4))
|
||||
+(floor(l_century/4)) -(2 *l_century));
|
||||
int result = static_cast<int>(tmp)%7;
|
||||
|
||||
if (result < 0)
|
||||
result += 7;
|
||||
currentTime = mktime(&tm);
|
||||
localtime_r(¤tTime, &tm);
|
||||
|
||||
return result;
|
||||
return tm.tm_wday;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user