23 #include <tqdatetime.h>
29 #include "kcalendarsystemhijri.h"
43 static int lastDayOfGregorianMonth(
int month,
int year) {
48 if ((((year % 4) == 0) && ((year % 100) != 0))
49 || ((year % 400) == 0))
68 GregorianDate(
int m,
int d,
int y) { month = m; day = d; year = y; }
70 GregorianDate(
int d) {
74 while (d >= GregorianDate(1,1,year+1))
78 while (d > GregorianDate(month, lastDayOfGregorianMonth(month,year), year))
80 day = d - GregorianDate(month,1,year) + 1;
85 for (
int m = month - 1; m > 0; m--)
86 N = N + lastDayOfGregorianMonth(m, year);
95 int getMonth() {
return month; }
96 int getDay() {
return day; }
97 int getYear() {
return year; }
101 static int IslamicLeapYear(
int year) {
104 if ((((11 * year) + 14) % 30) < 11)
110 static const int IslamicEpoch = 227014;
113 static int lastDayOfIslamicMonth(
int month,
int year) {
116 if (((month % 2) == 1) || ((month == 12) && IslamicLeapYear(year)))
129 IslamicDate(
int m,
int d,
int y) { month = m; day = d; year = y; }
132 if (d <= IslamicEpoch) {
139 year = (d - IslamicEpoch) / 355;
140 while (d >= IslamicDate(1,1,year+1))
144 while (d > IslamicDate(month, lastDayOfIslamicMonth(month,year), year))
146 day = d - IslamicDate(month,1,year) + 1;
155 + (3 + (11 * year)) / 30
159 int getMonth() {
return month; }
160 int getDay() {
return day; }
161 int getYear() {
return year; }
165 static void gregorianToHijri(
const TQDate & date,
int * pYear,
int * pMonth,
168 GregorianDate gregorian(date.month(),date.day(),date.year());
169 int absolute = gregorian;
171 IslamicDate islamic(absolute);
174 *pYear = islamic.getYear();
176 *pMonth = islamic.getMonth();
178 *pDay = islamic.getDay();
181 KCalendarSystemHijri::KCalendarSystemHijri(
const TDELocale * locale)
186 KCalendarSystemHijri::~KCalendarSystemHijri()
190 int KCalendarSystemHijri::year(
const TQDate& date)
const
193 gregorianToHijri(date, &y, 0, 0);
197 int KCalendarSystemHijri::month(
const TQDate& date)
const
200 gregorianToHijri(date, 0, &m, 0);
204 int KCalendarSystemHijri::day(
const TQDate& date)
const
207 gregorianToHijri(date, 0, 0, &d);
211 int KCalendarSystemHijri::monthsInYear(
const TQDate & date )
const
218 int KCalendarSystemHijri::weeksInYear(
int year)
const
221 setYMD(temp, year, 12, lastDayOfIslamicMonth(12, year));
225 if ( weekNumber(temp) == 1 )
226 temp = addDays(temp, -7);
228 return weekNumber(temp);
231 int KCalendarSystemHijri::weekNumber(
const TQDate& date,
int * yearNum)
const
233 TQDate firstDayWeek1, lastDayOfYear;
236 int weekDay1, dayOfWeek1InYear;
239 setYMD(firstDayWeek1, y, 1, 1);
240 weekDay1 = dayOfWeek(firstDayWeek1);
245 firstDayWeek1 = addDays(firstDayWeek1 , 7 - weekDay1 + 1);
247 dayOfWeek1InYear = dayOfYear(firstDayWeek1);
249 if ( dayOfYear(date) < dayOfWeek1InYear )
253 return weeksInYear(y - 1);
257 setYMD(lastDayOfYear, y, 12, lastDayOfIslamicMonth(12, y));
258 if ( (dayOfYear(date) >= daysInYear(date) - dayOfWeek(lastDayOfYear) + 1)
260 && dayOfWeek(lastDayOfYear) < 4)
269 firstDayWeek1 = addDays(firstDayWeek1, - (weekDay1 - 1));
271 week = firstDayWeek1.daysTo(date) / 7 + 1;
277 TQString KCalendarSystemHijri::monthName(
const TQDate& date,
278 bool shortName)
const
280 return monthName(month(date), year(date), shortName);
283 TQString KCalendarSystemHijri::monthNamePossessive(
const TQDate& date,
284 bool shortName)
const
286 return monthNamePossessive(month(date), year(date), shortName);
289 TQString KCalendarSystemHijri::monthName(
int month,
int year,
bool shortName)
298 return locale()->translate(
"Muharram");
300 return locale()->translate(
"Safar");
302 return locale()->translate(
"R. Awal");
304 return locale()->translate(
"R. Thaani");
306 return locale()->translate(
"J. Awal");
308 return locale()->translate(
"J. Thaani");
310 return locale()->translate(
"Rajab");
312 return locale()->translate(
"Sha`ban");
314 return locale()->translate(
"Ramadan");
316 return locale()->translate(
"Shawwal");
318 return locale()->translate(
"Qi`dah");
320 return locale()->translate(
"Hijjah");
326 return locale()->translate(
"Muharram");
328 return locale()->translate(
"Safar");
330 return locale()->translate(
"Rabi` al-Awal");
332 return locale()->translate(
"Rabi` al-Thaani");
334 return locale()->translate(
"Jumaada al-Awal");
336 return locale()->translate(
"Jumaada al-Thaani");
338 return locale()->translate(
"Rajab");
340 return locale()->translate(
"Sha`ban");
342 return locale()->translate(
"Ramadan");
344 return locale()->translate(
"Shawwal");
346 return locale()->translate(
"Thu al-Qi`dah");
348 return locale()->translate(
"Thu al-Hijjah");
351 return TQString::null;
354 TQString KCalendarSystemHijri::monthNamePossessive(
int month,
int year,
355 bool shortName)
const
363 return locale()->translate(
"of Muharram");
365 return locale()->translate(
"of Safar");
367 return locale()->translate(
"of R. Awal");
369 return locale()->translate(
"of R. Thaani");
371 return locale()->translate(
"of J. Awal");
373 return locale()->translate(
"of J. Thaani");
375 return locale()->translate(
"of Rajab");
377 return locale()->translate(
"of Sha`ban");
379 return locale()->translate(
"of Ramadan");
381 return locale()->translate(
"of Shawwal");
383 return locale()->translate(
"of Qi`dah");
385 return locale()->translate(
"of Hijjah");
391 return locale()->translate(
"of Muharram");
393 return locale()->translate(
"of Safar");
395 return locale()->translate(
"of Rabi` al-Awal");
397 return locale()->translate(
"of Rabi` al-Thaani");
399 return locale()->translate(
"of Jumaada al-Awal");
401 return locale()->translate(
"of Jumaada al-Thaani");
403 return locale()->translate(
"of Rajab");
405 return locale()->translate(
"of Sha`ban");
407 return locale()->translate(
"of Ramadan");
409 return locale()->translate(
"of Shawwal");
411 return locale()->translate(
"of Thu al-Qi`dah");
413 return locale()->translate(
"of Thu al-Hijjah");
416 return TQString::null;
419 bool KCalendarSystemHijri::setYMD(TQDate & date,
int y,
int m,
int d)
const
422 if ( y < minValidYear() || y > maxValidYear() )
425 if ( m < 1 || m > 12 )
428 if ( d < 1 || d > lastDayOfIslamicMonth(m, y) )
431 IslamicDate islamic (m, d, y);
432 int absolute = islamic;
433 GregorianDate gregorian(absolute);
435 return date.setYMD(gregorian.getYear(), gregorian.getMonth(),
439 TQString KCalendarSystemHijri::weekDayName(
int day,
bool shortName)
const
445 return locale()->translate(
"Ith");
447 return locale()->translate(
"Thl");
449 return locale()->translate(
"Arb");
451 return locale()->translate(
"Kha");
453 return locale()->translate(
"Jum");
455 return locale()->translate(
"Sab");
457 return locale()->translate(
"Ahd");
463 return locale()->translate(
"Yaum al-Ithnain");
465 return locale()->translate(
"Yau al-Thulatha");
467 return locale()->translate(
"Yaum al-Arbi'a");
469 return locale()->translate(
"Yaum al-Khamees");
471 return locale()->translate(
"Yaum al-Jumma");
473 return locale()->translate(
"Yaum al-Sabt");
475 return locale()->translate(
"Yaum al-Ahad");
478 return TQString::null;
481 TQString KCalendarSystemHijri::weekDayName(
const TQDate& date,
482 bool shortName)
const
484 return weekDayName(dayOfWeek(date), shortName);
487 int KCalendarSystemHijri::dayOfWeek(
const TQDate& date)
const
489 return date.dayOfWeek();
492 int KCalendarSystemHijri::dayOfYear(
const TQDate & date)
const
495 setYMD(first, year(date), 1, 1);
497 return first.daysTo(date) + 1;
502 int KCalendarSystemHijri::daysInMonth(
const TQDate& date)
const
505 gregorianToHijri(date, &y, &m, 0);
507 return lastDayOfIslamicMonth(m, y);
511 int KCalendarSystemHijri::minValidYear()
const
513 TQDate date(1753, 1, 1);
519 int KCalendarSystemHijri::maxValidYear()
const
521 TQDate date(8000, 1, 1);
526 int KCalendarSystemHijri::daysInYear(
const TQDate & date)
const
529 setYMD(first, year(date), 1, 1);
530 setYMD(last, year(date) + 1, 1, 1);
532 return first.daysTo(last);
535 int KCalendarSystemHijri::weekDayOfPray()
const
540 TQDate KCalendarSystemHijri::addDays(
const TQDate & date,
int ndays )
const
542 return date.addDays( ndays );
545 TQDate KCalendarSystemHijri::addMonths(
const TQDate & date,
int nmonths )
const
547 TQDate result = date;
563 setYMD( result, y, m, day(date) );
568 TQDate KCalendarSystemHijri::addYears(
const TQDate & date,
int nyears )
const
570 TQDate result = date;
571 int y = year(date) + nyears;
573 setYMD( result, y, month(date), day(date) );
578 TQString KCalendarSystemHijri::calendarName()
const
580 return TQString::fromLatin1(
"hijri");
583 bool KCalendarSystemHijri::isLunar()
const
588 bool KCalendarSystemHijri::isLunisolar()
const
593 bool KCalendarSystemHijri::isSolar()
const
CalendarSystem abstract class, default derived kde gregorian class and factory class.
TDELocale provides support for country specific stuff like the national language.