// Ok int KCalendarSystemHebrew::daysInYear(const TQDate & date) const { TQDate first, last; setYMD(first, year(date), 1, 1); // 1 Tishrey setYMD(last, year(date) + 1, 1, 1); // 1 Tishrey the year later return first.daysTo(last); }
// Ok int KCalendarSystemHebrew::dayOfYear(const TQDate & date) const { TQDate first; setYMD(first, year(date), 1, 1); return first.daysTo(date) + 1; }
// Ok int KCalendarSystemHebrew::weeksInYear(int year) const { TQDate temp; setYMD(temp, year, 1, 1); // don't pass an uninitialized TQDate to // monthsInYear in the next call setYMD(temp, year, monthsInYear(temp), hndays(monthsInYear(temp), year) ); int nWeekNumber = weekNumber(temp); if(nWeekNumber == 1) // last week belongs to next year { temp = TQT_TQDATE_OBJECT(temp.addDays(-7)); nWeekNumber = weekNumber(temp); } return nWeekNumber; }
int KCalendarSystemHebrew::weekNumber(const TQDate& date, int * yearNum) const { TQDate firstDayWeek1, lastDayOfYear; int y = year(date); int week; int weekDay1, dayOfWeek1InYear; // let's guess 1st day of 1st week setYMD(firstDayWeek1, y, 1, 1); weekDay1 = dayOfWeek(firstDayWeek1); // iso 8601: week 1 is the first containing thursday and week starts on // monday if (weekDay1 > 4 /*Thursday*/) firstDayWeek1 = addDays(firstDayWeek1 , 7 - weekDay1 + 1); // next monday dayOfWeek1InYear = dayOfYear(firstDayWeek1); if ( dayOfYear(date) < dayOfWeek1InYear ) // our date in prev year's week { if ( yearNum ) *yearNum = y - 1; return weeksInYear(y - 1); } // let's check if its last week belongs to next year setYMD(lastDayOfYear, y + 1, 1, 1); lastDayOfYear = addDays(lastDayOfYear, -1); if ( (dayOfYear(date) >= daysInYear(date) - dayOfWeek(lastDayOfYear) + 1) // our date is in last week && dayOfWeek(lastDayOfYear) < 4) // 1st week in next year has thursday { if ( yearNum ) *yearNum = y + 1; week = 1; } else { if( weekDay1 < 5 ) // To calculate properly the number of weeks // from day a to x let's make a day 1 of week firstDayWeek1 = addDays( firstDayWeek1, -( weekDay1 - 1)); week = firstDayWeek1.daysTo(date) / 7 + 1; } return week; }
// Ok TQDate KCalendarSystemHebrew::addYears( const TQDate & date, int nyears ) const { TQDate result = date; int y = year(date) + nyears; setYMD( result, y, month(date), day(date) ); return result; }
QDate KCalendarSystemJalali::addMonths( const QDate &date, int nmonths ) const { QDate result = date; int m = month( date ); int y = year( date ); if ( nmonths < 0 ) { m += 12; y -= 1; } --m; // this only works if we start counting at zero m += nmonths; y += m / 12; m %= 12; ++m; setYMD( result, y, m, day( date ) ); return result; }
QDate::QDate( int y, int m, int d ) { jd = 0; setYMD( y, m, d ); }