korganizer

parsha.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 "parsha.h"
00012 #include <klocale.h>
00013 
00014 QStringList Parsha::parshiot_names;
00015 
00016 Parsha::Parsha()
00017 {
00018 
00019 }
00020 
00021 Parsha::~Parsha()
00022 {
00023 }
00024 
00025 QString
00026   Parsha::FindParshaName(int daynumber, int kvia, bool leap_p,
00027                          bool israel_p)
00028 {
00029 // The names of the Parshiot.
00030   parshiot_names <<
00031     i18n
00032     ("These are weekly readings and do not have translations. They may have different spellings in your language; otherwise, just translate the sound to your characters",
00033      "Bereshit") << i18n("Noach") << i18n("Lech L'cha") <<
00034     i18n("Vayera") << i18n("Chaye Sarah") << i18n("Toldot") <<
00035     i18n("Vayetze") << i18n("Vayishlach") << i18n("Vayeshev") <<
00036     i18n("Miketz") << i18n("Vayigash") << i18n("Vayechi") <<
00037     i18n("Shemot") << i18n("Vaera") << i18n("Bo") << i18n("Beshalach")
00038     << i18n("Yitro") << i18n("Mishpatim") << i18n("Terumah") <<
00039     i18n("Tetzaveh") << i18n("Ki Tisa") << i18n("Vayakhel") <<
00040     i18n("Pekudei") << i18n("Vayikra") << i18n("Tzav") <<
00041     i18n("Shemini") << i18n("Tazria") << i18n("Metzora") <<
00042     i18n("Acharei Mot") << i18n("Kedoshim") << i18n("Emor") <<
00043     i18n("Behar") << i18n("Bechukotai") << i18n("Bemidbar") <<
00044     i18n("Naso") << i18n("Behaalotcha") << i18n("Shelach") <<
00045     i18n("Korach") << i18n("Chukat") << i18n("Balak") <<
00046     i18n("Pinchas") << i18n("Matot") << i18n("Masei") <<
00047     i18n("Devarim") << i18n("Vaetchanan") << i18n("Ekev") <<
00048     i18n("Reeh") << i18n("Shoftim") << i18n("Ki Tetze") <<
00049     i18n("Ki Tavo") << i18n("Nitzavim") << i18n("Vayelech") <<
00050     i18n("Haazinu");
00051 
00052 // Tables for each of the year types.  XX indicates that it is a Holiday, and
00053 // a special parsha is read that week.  For some year types, Israel is different
00054 // than the diaspora.
00055 //
00056 // The names indicate the day of the week on which Rosh Hashanah fell, whether
00057 // it is a short/normal/long year (kvia=0,1,2), and whether it is a leap year.
00058 // Some year types also have an _Israel version.
00059 //
00060 // Numbers are indices into the table above for a given week.  Numbers > 100 indicate
00061 // a double parsha.  E.g. 150 means read both table entries 50 and 51.
00062 //
00063 // These tables were stolen (with some massaging) from the GNU code.
00064 
00065 #define XX 255
00066   static unsigned const char Sat_short[] =
00067     { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
00068     11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25,
00069     126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
00070     45, 46, 47, 48, 49, 50,
00071   };
00072 
00073   static unsigned const char Sat_long[] =
00074     { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
00075     11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25,
00076     126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
00077     45, 46, 47, 48, 49, 150,
00078   };
00079 
00080   static unsigned const char Mon_short[] =
00081     { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00082     12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25, 126,
00083     128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44, 45,
00084     46, 47, 48, 49, 150,
00085   };
00086 
00087   static unsigned const char Mon_long[] =        /* split */
00088   { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00089     12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25, 126,
00090     128, 30, 131, 33, XX, 34, 35, 36, 37, 138, 40, 141, 43, 44, 45,
00091     46, 47, 48, 49, 150,
00092   };
00093 
00094 #define Mon_long_Israel Mon_short
00095 
00096 #define Tue_normal  Mon_long
00097 #define Tue_normal_Israel  Mon_short
00098 
00099   static unsigned const char Thu_normal[] =
00100     { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00101     12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, XX, 25,
00102     126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
00103     45, 46, 47, 48, 49, 50,
00104   };
00105   static unsigned const char Thu_normal_Israel[] =
00106     { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00107     12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25, 126,
00108     128, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
00109     45, 46, 47, 48, 49, 50,
00110   };
00111 
00112   static unsigned const char Thu_long[] =
00113     { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00114     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, XX, 25,
00115     126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
00116     45, 46, 47, 48, 49, 50,
00117   };
00118 
00119   static unsigned const char Sat_short_leap[] =
00120     { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
00121     11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
00122     26, 27, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
00123     40, 141, 43, 44, 45, 46, 47, 48, 49, 150,
00124   };
00125 
00126   static unsigned const char Sat_long_leap[] =
00127     { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
00128     11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
00129     26, 27, XX, 28, 29, 30, 31, 32, 33, XX, 34, 35, 36, 37, 138,
00130     40, 141, 43, 44, 45, 46, 47, 48, 49, 150,
00131   };
00132 
00133 #define Sat_long_leap_Israel  Sat_short_leap
00134 
00135   static unsigned const char Mon_short_leap[] =
00136     { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00137     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
00138     27, XX, 28, 29, 30, 31, 32, 33, XX, 34, 35, 36, 37, 138, 40,
00139     141, 43, 44, 45, 46, 47, 48, 49, 150,
00140   };
00141   static unsigned const char Mon_short_leap_Israel[] =
00142     { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00143     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
00144     27, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
00145     141, 43, 44, 45, 46, 47, 48, 49, 150,
00146   };
00147 
00148   static unsigned const char Mon_long_leap[] =
00149     { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00150     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
00151     27, XX, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
00152     40, 141, 43, 44, 45, 46, 47, 48, 49, 50,
00153   };
00154   static unsigned const char Mon_long_leap_Israel[] =
00155     { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00156     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
00157     27, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
00158     41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
00159   };
00160 
00161 #define Tue_normal_leap  Mon_long_leap
00162 #define Tue_normal_leap_Israel  Mon_long_leap_Israel
00163 
00164   static unsigned const char Thu_short_leap[] =
00165     { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00166     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
00167     27, 28, XX, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
00168     41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
00169   };
00170 
00171   static unsigned const char Thu_long_leap[] =
00172     { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
00173     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
00174     27, 28, XX, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
00175     41, 42, 43, 44, 45, 46, 47, 48, 49, 150,
00176   };
00177 
00178 /* Find the parsha for a given day of the year.  daynumber is the day of the year.
00179  * kvia and leap_p refer to the year type.
00180  */
00181 
00182   int week = daynumber / 7;        // week of the year
00183   unsigned const char *array = NULL;
00184   int index;
00185 
00186   // get the appropriate array by exhaustive search into the 14 year types.  Since we
00187   // know it's a Shabbat, we can find out what day Rosh Hashanah was on by looking
00188   // at daynumber %7.
00189   if (!leap_p)
00190       {
00191         switch (daynumber % 7)
00192             {
00193             case 1:                /* RH was on a Saturday */
00194               if (kvia == 0)
00195                 array = Sat_short;
00196               else if (kvia == 2)
00197                 array = Sat_long;
00198               break;
00199             case 6:                /* RH was on a Monday */
00200               if (kvia == 0)
00201                 array = Mon_short;
00202               else if (kvia == 2)
00203                 array = israel_p ? Mon_long_Israel : Mon_long;
00204               break;
00205             case 5:                /* RH was on a Tueday */
00206               if (kvia == 1)
00207                 array = israel_p ? Tue_normal_Israel : Tue_normal;
00208               break;
00209             case 3:                /* RH was on a Thu */
00210               if (kvia == 1)
00211                 array = israel_p ? Thu_normal_Israel : Thu_normal;
00212               else if (kvia == 2)
00213                 array = Thu_long;
00214               break;
00215             }
00216       }
00217   else                                /* leap year */
00218     switch (daynumber % 7)
00219         {
00220         case 1:                /* RH was on a Sat */
00221           if (kvia == 0)
00222             array = Sat_short_leap;
00223           else if (kvia == 2)
00224             array = israel_p ? Sat_long_leap_Israel : Sat_long_leap;
00225           break;
00226         case 6:                /* RH was on a Mon */
00227           if (kvia == 0)
00228             array = israel_p ? Mon_short_leap_Israel : Mon_short_leap;
00229           else if (kvia == 2)
00230             array = israel_p ? Mon_long_leap_Israel : Mon_long_leap;
00231           break;
00232         case 5:                /* RH was on a Tue */
00233           if (kvia == 1)
00234             array =
00235               israel_p ? Tue_normal_leap_Israel : Tue_normal_leap;
00236           break;
00237         case 3:                /* RH was on a Thu */
00238           if (kvia == 0)
00239             array = Thu_short_leap;
00240           else if (kvia == 2)
00241             array = Thu_long_leap;
00242           break;
00243 
00244         }
00245 
00246   QString buffer;
00247 
00248   if (array == NULL)
00249     /* Something is terribly wrong. */
00250       {
00251         buffer = "??Parsha??";
00252         return buffer;
00253       }
00254   index = array[week];
00255   if (index == XX)                // no Parsha this week.
00256       {
00257         buffer = "";
00258         return buffer;
00259       }
00260   else if (index < 100)
00261       {
00262         buffer = parshiot_names[index];
00263         return buffer;
00264       }
00265   else
00266       {                                // Create a double parsha
00267         buffer =
00268           parshiot_names[index - 100] + "-" + parshiot_names[index -
00269                                                              99];
00270         return buffer;
00271 
00272       }
00273 }
KDE Home | KDE Accessibility Home | Description of Access Keys