korganizer Library API Documentation

holiday.cpp

00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Jonathan Singer * 00003 * jsinger@leeta.net * 00004 * Calendar routines from Hebrew Calendar by Frank Yellin * 00005 * * 00006 * This program is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 2 of the License, or * 00009 * (at your option) any later version. * 00010 ***************************************************************************/ 00011 #include "holiday.h" 00012 #include <klocale.h> 00013 00014 bool Holiday::CholP; 00015 bool Holiday::OmerP; 00016 bool Holiday::ParshaP; 00017 00018 QStringList Holiday::holidays; 00019 int Holiday::HolidayFlags; 00020 00021 Holiday::Holiday() 00022 { 00023 00024 } 00025 00026 Holiday::~Holiday() 00027 { 00028 } 00029 00030 /* Given a day of the Hebrew month, figuring out all the interesting holidays that 00031 * correspond to that date. ParshaP, OmerP, and CholP determine whether we should 00032 * given info about the Parsha of the week, the Sfira, or Chol Hamoed. 00033 * 00034 * We are also influenced by the IsraelP flag 00035 */ 00036 00037 QStringList 00038 Holiday::FindHoliday(int month, int day, int weekday, int kvia, 00039 bool leap_year_p, bool israel_p, 00040 int day_number, int year) 00041 { 00042 00043 enum 00044 { Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday 00045 }; 00046 00047 holidays.clear(); 00048 bool shabbat_p = (weekday == Saturday); // Is it a Saturday? 00049 00050 // Treat Adar in a non-leap year as if it were Adar II. 00051 if ((month == 12) && !leap_year_p) 00052 month = 13; 00053 switch (month) 00054 { 00055 case 1: /* Nissan */ 00056 switch (day) 00057 { 00058 case 1: 00059 if (shabbat_p) 00060 holidays << 00061 i18n 00062 ("These are Jewish holidays and mostly do not have translations. They may have different spellings in your language; otherwise, just translate the sound to your characters", 00063 "Sh. HaHodesh"); 00064 break; 00065 case 14: 00066 if (!shabbat_p) 00067 // If it's Shabbat, we have three pieces of info. 00068 // This is the least important. 00069 holidays << i18n("Erev Pesach"); 00070 /* Fall thru */ 00071 case 8: 00072 case 9: 00073 case 10: 00074 case 11: 00075 case 12: 00076 case 13: 00077 // The Saturday before Pesach (8th-14th) 00078 if (shabbat_p) 00079 holidays << i18n("Sh. HaGadol"); 00080 break; 00081 case 15: 00082 case 16: 00083 case 21: 00084 case 22: 00085 if (!israel_p || (day == 15) || (day == 21)) 00086 { 00087 holidays << i18n("Pesach"); 00088 break; 00089 } 00090 else if (day == 22) 00091 break; 00092 /* else fall through */ 00093 case 17: 00094 case 18: 00095 case 19: 00096 case 20: 00097 if (CholP) 00098 holidays << i18n("Chol Hamoed"); 00099 break; 00100 case 27: 00101 // Yom HaShoah only exists since Israel was established. 00102 if (year > 1948 + 3760) 00103 holidays << i18n("Yom HaShoah"); 00104 break; 00105 } 00106 if ((day > 15) && OmerP) 00107 // Count the Omer, starting after the first day of Pesach. 00108 holidays << Sfirah(day - 15); 00109 break; 00110 00111 case 2: /* Iyar */ 00112 switch (day) 00113 { 00114 case 2: 00115 case 3: 00116 case 4: 00117 case 5: 00118 // Yom HaAtzmaut is on the 5th, unless that's a Saturday, in which 00119 // case it is moved back two days to Thursday. Yom HaZikaron is 00120 // the day before Yom HaAtzmaut. 00121 if (year >= 1948 + 3760) 00122 { // only after Israel established. 00123 switch (weekday) 00124 { 00125 case Wednesday: 00126 if (day == 5) 00127 holidays << i18n("Yom HaAtzmaut"); 00128 else 00129 holidays << i18n("Yom HaZikaron"); 00130 break; 00131 case Thursday: 00132 // This can't be 2 Iyar. 00133 holidays << i18n("Yom HaAtzmaut"); 00134 break; 00135 case Friday: 00136 case Saturday: 00137 // These are never either of them. 00138 break; 00139 default: 00140 // All other days follow the normal rules. 00141 if (day == 4) 00142 holidays << i18n("Yom HaZikaron"); 00143 else if (day == 5) 00144 holidays << i18n("Yom HaAtzmaut"); 00145 } 00146 } 00147 break; 00148 case 28: 00149 // only since the 1967 war 00150 if (year > 1967 + 3760) 00151 holidays << i18n("Yom Yerushalayim"); 00152 break; 00153 case 18: 00154 holidays << i18n("Lag BaOmer"); 00155 break; 00156 } 00157 if ((day != 18) && OmerP) 00158 // Sfirah the whole month. But Lag BaOmer is already mentioned. 00159 holidays << Sfirah(day + 15); 00160 00161 break; 00162 00163 case 3: /* Sivan */ 00164 switch (day) 00165 { 00166 case 1: 00167 case 2: 00168 case 3: 00169 case 4: 00170 // Sfirah until Shavuot 00171 if (OmerP) 00172 holidays << Sfirah(day + 44); 00173 break; 00174 case 5: 00175 // Don't need to mention Sfira(49) if there's already two other 00176 // pieces of information 00177 if (OmerP && !shabbat_p) 00178 holidays << Sfirah(49); 00179 holidays << i18n("Erev Shavuot"); 00180 break; 00181 case 6: 00182 case 7: 00183 if (!israel_p || (day == 6)) 00184 holidays << i18n("Shavuot"); 00185 break; 00186 } 00187 break; 00188 00189 case 4: /* Tamuz */ 00190 // 17th of Tamuz, except Shabbat pushes it to Sunday. 00191 if ((!shabbat_p && (day == 17)) 00192 || ((weekday == 1) && (day == 18))) 00193 holidays << i18n("Tzom Tammuz"); 00194 break; 00195 00196 case 5: /* Ab */ 00197 if (shabbat_p && (3 <= day) && (day <= 16)) 00198 // The shabbat before and after Tisha B'Av are special 00199 if (day <= 9) 00200 holidays << i18n("Sh. Hazon"); 00201 else 00202 holidays << i18n("Sh. Nahamu"); 00203 else if ((!shabbat_p && (day == 9)) 00204 || ((weekday == 1) && (day == 10))) 00205 // 9th of Av, except Shabbat pushes it to Sunday. 00206 holidays << i18n("Tisha B'Av"); 00207 break; 00208 00209 case 6: /* Elul */ 00210 if ((day >= 20) && (day <= 26) && shabbat_p) 00211 holidays << i18n("S'lichot"); 00212 else if (day == 29) 00213 holidays << i18n("Erev R.H."); 00214 break; 00215 00216 case 7: /* Tishrei */ 00217 switch (day) 00218 { 00219 case 1: 00220 case 2: 00221 holidays << i18n("Rosh Hashana"); 00222 break; 00223 case 3: 00224 if (shabbat_p) 00225 holidays << i18n("Sh. Shuvah"); 00226 else 00227 holidays << i18n("Tzom Gedalia"); 00228 break; 00229 case 4: 00230 if (weekday == 1) 00231 holidays << i18n("Tzom Gedalia"); 00232 /* fall through */ 00233 case 5: 00234 case 6: 00235 case 7: 00236 case 8: 00237 if (shabbat_p) 00238 holidays << i18n("Sh. Shuvah"); 00239 break; 00240 case 9: 00241 holidays << i18n("Erev Y.K."); 00242 break; 00243 case 10: 00244 holidays << i18n("Yom Kippur"); 00245 break; 00246 case 14: 00247 holidays << i18n("Erev Sukkot"); 00248 break; 00249 case 15: 00250 case 16: 00251 if (!israel_p || (day == 15)) 00252 { 00253 holidays << i18n("Sukkot"); 00254 break; 00255 } 00256 /* else fall through */ 00257 case 17: 00258 case 18: 00259 case 19: 00260 case 20: 00261 if (CholP) 00262 holidays << i18n("Chol Hamoed"); 00263 break; 00264 case 21: 00265 holidays << i18n("Hoshana Rabah"); 00266 break; 00267 case 22: 00268 holidays << i18n("Shmini Atzeret"); 00269 break; 00270 case 23: 00271 if (!israel_p) 00272 holidays << i18n("Simchat Torah"); 00273 break; 00274 } 00275 break; 00276 case 8: /* Cheshvan */ 00277 break; 00278 00279 case 9: /* Kislev */ 00280 if (day == 24) 00281 holidays << i18n("Erev Hanukah"); 00282 else if (day >= 25) 00283 holidays << i18n("Hanukah"); 00284 break; 00285 00286 case 10: /* Tevet */ 00287 if (day <= (kvia == 0 ? 3 : 2)) 00288 // Need to know length of Kislev to determine last day of Chanukah 00289 holidays << i18n("Hanukah"); 00290 else if (((day == 10) && !shabbat_p) 00291 || ((day == 11) && (weekday == 1))) 00292 // 10th of Tevet. Shabbat pushes it to Sunday 00293 holidays << i18n("Tzom Tevet"); 00294 break; 00295 00296 case 11: /* Shvat */ 00297 switch (day) 00298 { 00299 // The info for figuring out Shabbat Shirah is from the Gnu code. I 00300 // assume it's correct. 00301 // static char *song = i18n("Sh. Shirah"; 00302 case 10: 00303 if ((kvia != 0) && shabbat_p) 00304 holidays << i18n("Sh. Shirah"); 00305 break; 00306 case 11: 00307 case 12: 00308 case 13: 00309 case 14: 00310 case 16: 00311 if (shabbat_p) 00312 holidays << i18n("Sh. Shirah"); 00313 break; 00314 case 15: 00315 if (shabbat_p) 00316 holidays << i18n("Sh. Shirah"); 00317 holidays << i18n("Tu B'Shvat"); 00318 case 17: 00319 if ((kvia == 0) && shabbat_p) 00320 holidays << i18n("Sh. Shirah"); 00321 break; 00322 case 25: 00323 case 26: 00324 case 27: 00325 case 28: 00326 case 29: 00327 case 30: 00328 // The last shabbat on or before 1 Adar or 1 AdarII 00329 if (shabbat_p && !leap_year_p) 00330 holidays << i18n("Sh. Shekalim"); 00331 break; 00332 } 00333 break; 00334 00335 case 12: /* Adar I */ 00336 if (day == 14) 00337 // Eat Purim Katan Candy 00338 holidays << i18n("Purim Katan"); 00339 else if ((day >= 25) && shabbat_p) 00340 // The last shabbat on or before 1 Adar II. 00341 holidays << i18n("Sh. Shekalim"); 00342 break; 00343 00344 case 13: /* Adar II or Adar */ 00345 switch (day) 00346 { 00347 case 1: 00348 if (shabbat_p) 00349 holidays << i18n("Sh. Shekalim"); 00350 break; 00351 case 11: 00352 case 12: 00353 // Ta'anit ester is on the 13th. But shabbat moves it back to 00354 // Thursday. 00355 if (weekday == Thursday) 00356 holidays << i18n("Ta'anit Ester"); 00357 /* Fall thru */ 00358 case 7: 00359 case 8: 00360 case 9: 00361 case 10: 00362 // The Shabbat before purim is Shabbat Zachor 00363 if (shabbat_p) 00364 holidays << i18n("Sh. Zachor"); 00365 break; 00366 case 13: 00367 if (shabbat_p) 00368 holidays << i18n("Sh. Zachor"); 00369 else 00370 holidays << i18n("Erev Purim"); 00371 // It's Ta'anit Esther, unless it's a Friday or Saturday 00372 if (weekday < Friday) 00373 holidays << i18n("Ta'anit Ester"); 00374 break; 00375 case 14: 00376 holidays << i18n("Purim"); 00377 break; 00378 case 15: 00379 if (!shabbat_p) 00380 holidays << i18n("Shushan Purim"); 00381 break; 00382 case 16: 00383 if (weekday == 1) 00384 holidays << i18n("Shushan Purim"); 00385 break; 00386 case 17: 00387 case 18: 00388 case 19: 00389 case 20: 00390 case 21: 00391 case 22: 00392 case 23: 00393 if (shabbat_p) 00394 holidays << i18n("Sh. Parah"); 00395 break; 00396 case 24: 00397 case 25: 00398 case 26: 00399 case 27: 00400 case 28: 00401 case 29: 00402 if (shabbat_p) 00403 holidays << i18n("Sh. HaHodesh"); 00404 break; 00405 } 00406 break; 00407 } 00408 if (shabbat_p && ParshaP) 00409 // Find the Parsha on Shabbat. 00410 holidays << Parsha::FindParshaName(day_number, kvia, leap_year_p, 00411 israel_p); 00412 return holidays; 00413 } 00414 00415 /* Return a string corresponding to the nth day of the Omer */ 00416 QString Holiday::Sfirah(int day) 00417 { 00418 /*static char buffer[40]; 00419 char *endings[] = {"th", "st", "nd", "rd"}; 00420 int remainder = day % 10; 00421 // 11-19 and anything not ending with 1, 2, or 3 uses -th as suffix. 00422 if ( ((day >= 11) && (day <= 19)) || (remainder > 3)) remainder = 0; 00423 sprintf(buffer, "%d%s day Omer", day, endings[remainder]); 00424 return buffer; */ 00425 QString buffer; 00426 00427 buffer.setNum(day); 00428 buffer + i18n(" Omer"); // Fix this to original function 00429 return buffer; 00430 00431 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:20 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003