31 #include <QtCore/QDate>
32 #include <QtCore/QCharRef>
51 static class h_date h;
59 if (s > 365 && m > 6) {
63 d += (59 * (m - 1) + 1) / 2;
65 if (s % 10 > 4 && m > 2) {
68 if (s % 10 < 4 && m > 3) {
76 y = (d + 36525) * 4 / 146097 - 1;
77 d -= y / 4 * 146097 + (y % 4) * 36524;
81 s = (d + 366) * 4 / 1461 - 1;
82 d -= s / 4 * 1461 + (s % 4) * 365;
85 m = (d + 245) * 12 / 367 - 7;
86 d -= m * 367 / 12 - 30;
102 static class h_date h;
110 d += 365 * y + y / 4 + 367 * m / 12 + 5968;
112 d -= y / 100 - y / 400 - 2;
113 h.hd_dw = (d + 1) % 7;
128 h.hd_flg = s % 10 - 4;
134 d -= (m * 59 + 1) / 2;
136 if (s > 365 && m <= 5) {
143 d -= (m * s + 3) / 4;
156 #define M(h,p) ((h)*HOUR+p)
157 #define MONTH (DAY+M(12,793))
170 nm = m *
MONTH +
M(1 + 6, 779);
171 s = m * 28 + nm /
DAY - 2;
178 if ((l < 12 && dw == 3 && nm >=
M(9 + 6, 204)) ||
179 (l < 7 && dw == 2 && nm >=
M(15 + 6, 589))) {
184 if (dw == 1 || dw == 4 || dw == 6) {
200 first.setYMD(gd->hd_year, gd->hd_mon + 1, gd->hd_day + 1);
203 last.setYMD(gd->hd_year, gd->hd_mon + 1, gd->hd_day + 1);
205 return (first.daysTo(last) % 10 == 5);
218 first.setYMD(gd->hd_year, gd->hd_mon + 1, gd->hd_day + 1);
221 last.setYMD(gd->hd_year, gd->hd_mon + 1, gd->hd_day + 1);
223 return (first.daysTo(last) % 10 == 3);
243 virtual ~KCalendarSystemHebrewPrivate();
249 virtual int daysInMonth(
int year,
int month)
const;
266 virtual int monthNumberToMonthIndex(
int year,
int month)
const;
276 KCalendarSystemHebrewPrivate::~KCalendarSystemHebrewPrivate()
285 void KCalendarSystemHebrewPrivate::loadDefaultEraList()
287 QString name, shortName, format;
289 name =
i18nc(
"Calendar Era: Hebrew Era, years > 0, LongFormat",
"Anno Mundi");
290 shortName =
i18nc(
"Calendar Era: Hebrew Era, years > 0, ShortFormat",
"AM");
291 format =
i18nc(
"(kdedt-format) Hebrew, AM, full era year format used for %EY, e.g. 2000 AM",
"%Ey %EC");
292 addEra(
'+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
295 int KCalendarSystemHebrewPrivate::monthsInYear(
int year)
const
297 if (isLeapYear(year)) {
304 int KCalendarSystemHebrewPrivate::daysInMonth(
int year,
int month)
const
306 int mi = monthNumberToMonthIndex(year, month);
323 int KCalendarSystemHebrewPrivate::daysInYear(
int year)
const
328 if (isLeapYear(year)) {
344 int KCalendarSystemHebrewPrivate::daysInWeek()
const
349 bool KCalendarSystemHebrewPrivate::isLeapYear(
int year)
const
351 return ((((7 * year) + 1) % 19) < 7);
354 bool KCalendarSystemHebrewPrivate::hasLeapMonths()
const
359 bool KCalendarSystemHebrewPrivate::hasYearZero()
const
364 int KCalendarSystemHebrewPrivate::maxDaysInWeek()
const
369 int KCalendarSystemHebrewPrivate::maxMonthsInYear()
const
374 int KCalendarSystemHebrewPrivate::earliestValidYear()
const
379 int KCalendarSystemHebrewPrivate::latestValidYear()
const
384 int KCalendarSystemHebrewPrivate::integerFromString(
const QString &inputString,
int maxLength,
int &readLength)
const
386 if (
locale()->language() == QLatin1String(
"he")) {
412 int decadeValues[14] = {10, 20, 20, 30, 40, 40, 50, 50, 60, 70, 80, 80, 90, 90};
414 QChar thisChar, nextChar;
417 int stringLength =
string.length();
423 for (; position < stringLength ; ++position) {
425 thisChar =
string[position];
427 if (position + 1 < stringLength) {
428 nextChar =
string[position + 1];
430 if (nextChar == QLatin1Char(
'\'') || nextChar == QChar(0x05F3) ||
431 nextChar == QLatin1Char(
'\"') || nextChar == QChar(0x05F4)) {
432 string.remove(position + 1, 1);
433 stringLength =
string.length();
434 if (position + 1 < stringLength) {
435 nextChar =
string[position + 1];
439 readLength = readLength + 1;
445 if (thisChar >= QChar(0x05D0) && thisChar <= QChar(0x05D7)) {
453 if (nextChar >= QChar(0x05D0) && nextChar <= QChar(0x05EA)) {
454 value = (thisChar.unicode() - 0x05D0 + 1) * 1000;
456 value = thisChar.unicode() - 0x05D0 + 1;
459 }
else if (thisChar == QChar(0x05D8)) {
468 if (nextChar >= QChar(0x05D0) && nextChar <= QChar(0x05EA) &&
469 nextChar != QChar(0x05D5) && nextChar != QChar(0x05D6)) {
475 }
else if (thisChar >= QChar(0x05D9) && thisChar <= QChar(0x05E6)) {
482 if (nextChar >= QChar(0x05D9)) {
485 value = decadeValues[thisChar.unicode() - 0x05D9];
488 }
else if (thisChar >= QChar(0x05E7) && thisChar <= QChar(0x05EA)) {
492 value = (thisChar.unicode() - 0x05E7 + 1) * 100;
501 result = result + value;
506 readLength += position;
515 QString KCalendarSystemHebrewPrivate::stringFromInteger(
int number,
int padWidth, QChar padChar)
const
520 QString KCalendarSystemHebrewPrivate::stringFromInteger(
int number,
int padWidth, QChar padChar,
KLocale::DigitSet digitSet)
const
522 if (
locale()->language() == QLatin1String(
"he")) {
548 const QChar decade[] = {
551 0x05D8, 0x05D9, 0x05DB, 0x05DC, 0x05DE,
552 0x05E0, 0x05E1, 0x05E2, 0x05E4, 0x05E6
558 if (number < 1 || number > 9999) {
564 if (number >= 1000) {
565 if (number <= 5000 || number >= 6000) {
566 result += QChar(0x05D0 - 1 + number / 1000);
575 while (number >= 500) {
576 result += QChar(0x05EA);
579 result += QChar(0x05E7 - 1 + number / 100);
587 if (number == 15 || number == 16)
589 result += decade[number / 10];
595 result += QChar(0x05D0 - 1 + number);
604 if (result.length() == 1) {
605 result += QLatin1Char(
'\'');
607 result.insert(result.length() - 1, QLatin1Char(
'\"'));
617 int KCalendarSystemHebrewPrivate::monthNumberToMonthIndex(
int year,
int month)
const
619 if (isLeapYear(year)) {
622 }
else if (month == 7) {
624 }
else if (month > 7) {
635 int monthIndex = monthNumberToMonthIndex(year, month);
638 switch (monthIndex) {
673 switch (monthIndex) {
708 switch (monthIndex) {
743 switch (monthIndex) {
745 return ki18nc(
"Hebrew month 1 - KLocale::LongName Possessive",
"of Tishrey").
toString(
locale());
747 return ki18nc(
"Hebrew month 2 - KLocale::LongName Possessive",
"of Heshvan").
toString(
locale());
769 return ki18nc(
"Hebrew month 13 - KLocale::LongName Possessive",
"of Adar I").
toString(
locale());
771 return ki18nc(
"Hebrew month 14 - KLocale::LongName Possessive",
"of Adar II").
toString(
locale());
778 switch (monthIndex) {
886 :
KCalendarSystem(*new KCalendarSystemHebrewPrivate(this), config, locale)
904 return QLatin1String(
"hebrew");
910 return QDate::fromJulianDay(347998);
918 return QDate::fromJulianDay(2299498);
924 return QDate::fromJulianDay(3313431);
940 if (sd->hd_dw == 0) {
984 result = result * 1000;
1022 class h_date * sd =
toHebrew(QDate::fromJulianDay(jd));
1030 }
else if (month == 14 ) {
1032 }
else if (month > 6 && month < 13) {
1046 QDate tempDate(gd->hd_year, gd->hd_mon + 1, gd->hd_day + 1);
1048 jd = tempDate.toJulianDay();