• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
  • plugins
  • hebrew
parsha.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2003 Jonathan Singer <jsinger@leeta.net>
5  Copyright (C) 2007 Loïc Corbasson <loic.corbasson@gmail.com>
6 
7  Calendar routines from Hebrew Calendar by Frank Yellin.
8  Based on some GNU Emacs code (lisp/calendar/cal-hebrew.el),
9  copyright (C) 1995, 1997 Free Software Foundation, Inc.,
10  authors: Nachum Dershowitz <nachum@cs.uiuc.edu>
11  Edward M. Reingold <reingold@cs.uiuc.edu>
12 
13  This program is free software; you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License along
24  with this program; if not, write to the Free Software Foundation, Inc.,
25  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 #include "parsha.h"
29 
30 #include <KDebug>
31 #include <KLocale>
32 
33 QString Parsha::findParshaName( int dayNumber, int kvia, bool isLeapYear,
34  bool useIsraelSettings )
35 {
36  // The names of the Parshiot.
37  static QStringList parshiotNames = QStringList();
38  parshiotNames
39  << i18nc( "These are weekly readings and do not have translations. "
40  "They may have different spellings in your language; "
41  "otherwise, just translate the sound to your characters", "Bereshit" )
42  << i18n( "Noach" )
43  << i18n( "Lech L'cha" )
44  << i18n( "Vayera" )
45  << i18n( "Chaye Sarah" )
46  << i18n( "Toldot" )
47  << i18n( "Vayetze" )
48  << i18n( "Vayishlach" )
49  << i18n( "Vayeshev" )
50  << i18n( "Miketz" )
51  << i18n( "Vayigash" )
52  << i18n( "Vayechi" )
53  << i18n( "Shemot" )
54  << i18n( "Vaera" )
55  << i18n( "Bo" )
56  << i18n( "Beshalach" )
57  << i18n( "Yitro" )
58  << i18n( "Mishpatim" )
59  << i18n( "Terumah" )
60  << i18n( "Tetzaveh" )
61  << i18n( "Ki Tisa" )
62  << i18n( "Vayakhel" )
63  << i18n( "Pekudei" )
64  << i18n( "Vayikra" )
65  << i18n( "Tzav" )
66  << i18n( "Shemini" )
67  << i18n( "Tazria" )
68  << i18n( "Metzora" )
69  << i18n( "Acharei Mot" )
70  << i18n( "Kedoshim" )
71  << i18n( "Emor" )
72  << i18n( "Behar" )
73  << i18n( "Bechukotai" )
74  << i18n( "Bemidbar" )
75  << i18n( "Naso" )
76  << i18n( "Behaalotcha" )
77  << i18n( "Shelach" )
78  << i18n( "Korach" )
79  << i18n( "Chukat" )
80  << i18n( "Balak" )
81  << i18n( "Pinchas" )
82  << i18n( "Matot" )
83  << i18n( "Masei" )
84  << i18n( "Devarim" )
85  << i18n( "Vaetchanan" )
86  << i18n( "Ekev" )
87  << i18n( "Reeh" )
88  << i18n( "Shoftim" )
89  << i18n( "Ki Tetze" )
90  << i18n( "Ki Tavo" )
91  << i18n( "Nitzavim" )
92  << i18n( "Vayelech" )
93  << i18n( "Haazinu" );
94 
95  /*
96  Tables for each of the year types. XX indicates that it is a Holiday, and a
97  special parsha is read that week. For some year types among the 14, Israel
98  is different from the diaspora.
99 
100  The names indicate the day of the week on which Rosh Hashanah fell, whether
101  it is a short/normal/long year (kvia=0,1,2), and whether it is a leap year.
102  As said earlier, some year types also have an _Israel version.
103 
104  The numbers are indices in the list above for a given week.
105  Numbers > 100 indicate a double parsha, e.g. 150 means read both table
106  entries 150 - 100 = 50 and 150 - 99 = 51.
107 
108  These tables were stolen (with some massaging) from the Gnu code.
109  */
110 
111  static const quint8 XX = 255;
112 
113  /* Non-leap years */
114  static const quint8 SatShort[] =
115  { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
116  11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25,
117  126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
118  45, 46, 47, 48, 49, 50,
119  };
120  static const quint8 SatLong[] =
121  { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
122  11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25,
123  126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
124  45, 46, 47, 48, 49, 150,
125  };
126 
127  static const quint8 MonShort[] =
128  { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
129  12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25, 126,
130  128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44, 45,
131  46, 47, 48, 49, 150,
132  };
133  static const quint8 MonLong[] = /* split */
134  { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
135  12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25, 126,
136  128, 30, 131, 33, XX, 34, 35, 36, 37, 138, 40, 141, 43, 44, 45,
137  46, 47, 48, 49, 150,
138  };
139  #define MonLong_Israel MonShort
140 
141  #define TueNormal MonLong
142  #define TueNormal_Israel MonShort
143 
144  static const quint8 ThuNormal[] =
145  { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
146  12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, XX, 25,
147  126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
148  45, 46, 47, 48, 49, 50,
149  };
150  static const quint8 ThuNormal_Israel[] =
151  { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
152  12, 13, 14, 15, 16, 17, 18, 19, 20, 121, 23, 24, XX, 25, 126,
153  128, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
154  45, 46, 47, 48, 49, 50,
155  };
156  static const quint8 ThuLong[] =
157  { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
158  12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, XX, 25,
159  126, 128, 30, 131, 33, 34, 35, 36, 37, 38, 39, 40, 141, 43, 44,
160  45, 46, 47, 48, 49, 50,
161  };
162 
163  /* Leap years */
164  static const quint8 SatShortLeap[] =
165  { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
166  11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
167  26, 27, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
168  40, 141, 43, 44, 45, 46, 47, 48, 49, 150,
169  };
170  static const quint8 SatLongLeap[] =
171  { XX, 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
172  11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
173  26, 27, XX, 28, 29, 30, 31, 32, 33, XX, 34, 35, 36, 37, 138,
174  40, 141, 43, 44, 45, 46, 47, 48, 49, 150,
175  };
176  #define SatLongLeap_Israel SatShortLeap
177 
178  static const quint8 MonShortLeap[] =
179  { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
180  12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
181  27, XX, 28, 29, 30, 31, 32, 33, XX, 34, 35, 36, 37, 138, 40,
182  141, 43, 44, 45, 46, 47, 48, 49, 150,
183  };
184  static const quint8 MonShortLeap_Israel[] =
185  { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
186  12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
187  27, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
188  141, 43, 44, 45, 46, 47, 48, 49, 150,
189  };
190  static const quint8 MonLongLeap[] =
191  { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
192  12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
193  27, XX, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
194  40, 141, 43, 44, 45, 46, 47, 48, 49, 50,
195  };
196  static const quint8 MonLongLeap_Israel[] =
197  { 51, 52, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
198  12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
199  27, XX, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
200  41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
201  };
202 
203  #define TueNormalLeap MonLongLeap
204  #define TueNormalLeap_Israel MonLongLeap_Israel
205 
206  static const quint8 ThuShortLeap[] =
207  { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
208  12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
209  27, 28, XX, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
210  41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
211  };
212  static const quint8 ThuLongLeap[] =
213  { 52, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
214  12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
215  27, 28, XX, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
216  41, 42, 43, 44, 45, 46, 47, 48, 49, 150,
217  };
218 
219  /* Make the calculations */
220  int week = dayNumber / 7; // week of the year
221  const quint8 *array = 0;
222  int index;
223 
224  /* Get the appropriate array by exhaustive search into the 14 year types.
225  Since we know it's a Shabbat, we can find out what day Rosh Hashanah was on
226  by looking at dayNumber % 7. */
227  if ( !isLeapYear ) {
228  switch ( dayNumber % 7 ) {
229  case 1: /* Rosh Hashanah was on a Saturday */
230  if ( kvia == 0 ) {
231  array = SatShort;
232  } else if ( kvia == 2 ) {
233  array = SatLong;
234  }
235  break;
236  case 6: /* Rosh Hashanah was on a Monday */
237  if ( kvia == 0 ) {
238  array = MonShort;
239  } else if ( kvia == 2 ) {
240  array = useIsraelSettings ? MonLong_Israel : MonLong;
241  }
242  break;
243  case 5: /* Rosh Hashanah was on a Tuesday */
244  if ( kvia == 1 ) {
245  array = useIsraelSettings ? TueNormal_Israel : TueNormal;
246  }
247  break;
248  case 3: /* Rosh Hashanah was on a Thursday */
249  if ( kvia == 1 ) {
250  array = useIsraelSettings ? ThuNormal_Israel : ThuNormal;
251  } else if ( kvia == 2 ) {
252  array = ThuLong;
253  }
254  break;
255  }
256  } else { /* leap year */
257  switch ( dayNumber % 7 ) {
258  case 1: /* Rosh Hashanah was on a Sat */
259  if ( kvia == 0 ) {
260  array = SatShortLeap;
261  } else if ( kvia == 2 ) {
262  array = useIsraelSettings ? SatLongLeap_Israel : SatLongLeap;
263  }
264  break;
265  case 6: /* Rosh Hashanah was on a Monday */
266  if ( kvia == 0 ) {
267  array = useIsraelSettings ? MonShortLeap_Israel : MonShortLeap;
268  } else if ( kvia == 2 ) {
269  array = useIsraelSettings ? MonLongLeap_Israel : MonLongLeap;
270  }
271  break;
272  case 5: /* Rosh Hashanah was on a Tuesday */
273  if ( kvia == 1 ) {
274  array = useIsraelSettings ? TueNormalLeap_Israel : TueNormalLeap;
275  }
276  break;
277  case 3: /* Rosh Hashanah was on a Thursday */
278  if ( kvia == 0 ) {
279  array = ThuShortLeap;
280  } else if ( kvia == 2 ) {
281  array = ThuLongLeap;
282  }
283  break;
284  }
285  }
286  QString buffer;
287 
288  if ( !array ) { /* Something is terribly wrong! */
289  buffer = QLatin1String("??Parsha??");
290  kWarning() << "Hebrew Plugin: Was not able to determine the Parsha."
291  << "Please report this as a bug.";
292  return buffer;
293  }
294 
295  index = array[week];
296  if ( index == XX ) { // no Parsha this week.
297  buffer.clear();
298  return buffer;
299  } else if ( index < 100 ) {
300  buffer = parshiotNames[index];
301  return buffer;
302  } else { // Create a double parsha
303  buffer = parshiotNames[index - 100] + QLatin1Char('-') + parshiotNames[index - 99];
304  return buffer;
305  }
306 }
TueNormalLeap_Israel
#define TueNormalLeap_Israel
Parsha::findParshaName
static QString findParshaName(int dayNumber, int kvia, bool isLeapYear, bool useIsraelSettings)
Find the parsha for a given day of the year.
Definition: parsha.cpp:33
parsha.h
SatLongLeap_Israel
#define SatLongLeap_Israel
TueNormal_Israel
#define TueNormal_Israel
MonLong_Israel
#define MonLong_Israel
TueNormalLeap
#define TueNormalLeap
TueNormal
#define TueNormal
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal