• 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
holiday.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 "holiday.h"
29 #include "parsha.h"
30 
31 #include <KLocale>
32 
33 QStringList Holiday::findHoliday( HebrewDate hd, bool useIsraelSettings,
34  bool showParsha, bool showChol,
35  bool showOmer )
36 {
37  return findHoliday( hd.month(), hd.day(), hd.dayOfWeek() + 1, hd.kvia(),
38  hd.isOnHebrewLeapYear(), useIsraelSettings,
39  hd.hebrewDayNumber(), hd.year(),
40  showParsha, showChol, showOmer );
41 }
42 
43 QStringList Holiday::findHoliday( int month, int day, int weekday, int kvia,
44  bool isLeapYear, bool useIsraelSettings,
45  int dayNumber, int year,
46  bool showParsha, bool showChol,
47  bool showOmer )
48 {
49  enum {
50  Sunday = 1,
51  Monday,
52  Tuesday,
53  Wednesday,
54  Thursday,
55  Friday,
56  Saturday
57  };
58 
59  QStringList holidays;
60  bool isAShabbat = ( weekday == Saturday );
61 
62  // Treat Adar in a non-leap year as if it were Adar II.
63  if ( ( month == Adar ) && !isLeapYear ) {
64  month = AdarII;
65  }
66  switch ( month ) {
67  case Nissan:
68  switch ( day ) {
69  case 1:
70  if ( isAShabbat ) {
71  holidays << i18nc( "These are Jewish holidays and mostly do not "
72  "have translations. They may have different "
73  "spellings in your language; otherwise, just "
74  "translate the sound to your characters.",
75  "Sh. HaHodesh" );
76  }
77  break;
78  case 14:
79  if ( !isAShabbat ) {
80  // If it's Shabbat, we have three pieces of info.
81  // This is the least important, so we skip it on Shabbat as we only
82  // really want the two most important ones.
83  holidays << i18n( "Erev Pesach" );
84  }
85  /* fall through */
86  case 8:
87  case 9:
88  case 10:
89  case 11:
90  case 12:
91  case 13:
92  // The Saturday before Pesach (8th-14th)
93  if ( isAShabbat ) {
94  holidays << i18n( "Sh. HaGadol" );
95  }
96  break;
97  case 15:
98  case 16:
99  case 21:
100  case 22:
101  if ( !useIsraelSettings || ( day == 15 ) || ( day == 21 ) ) {
102  holidays << i18n( "Pesach" );
103  break;
104  } else if ( day == 22 ) {
105  break;
106  }
107  /* else fall through */
108  case 17:
109  case 18:
110  case 19:
111  case 20:
112  if ( showChol ) {
113  holidays << i18n( "Chol Hamoed" );
114  }
115  break;
116  case 26:
117  case 27:
118  case 28:
119  // Yom HaShoah only exists since Israel was established.
120  if ( year > 1948 + 3760 ) {
121  switch( weekday ) {
122  case Thursday:
123  if ( day == 26 || day == 27 ) {
124  holidays << i18n( "Yom HaShoah" );
125  }
126  break;
127  case Monday:
128  if ( day == 28 || day == 27 ) {
129  holidays << i18n( "Yom HaShoah" );
130  }
131  break;
132  case Sunday:
133  case Friday:
134  // These are never either of them.
135  break;
136  default:
137  if ( day == 27 ) {
138  holidays << i18n( "Yom HaShoah" );
139  }
140  break;
141  }
142  }
143  break;
144  }
145  if ( ( day > 15 ) && showOmer ) {
146  // Count the Omer, starting after the first day of Pesach.
147  holidays << sfirah( day - 15 );
148  }
149  break;
150 
151  case Iyar:
152  switch ( day ) {
153  case 2:
154  case 3:
155  case 4:
156  case 5:
157  // Yom HaAtzmaut is on the 5th, unless that's a Saturday, in which
158  // case it is moved back two days to Thursday. Yom HaZikaron is the
159  // day before Yom HaAtzmaut.
160  if ( year >= 1948 + 3760 ) { // only after Israel was established
161  switch ( weekday ) {
162  case Wednesday:
163  if ( day == 5 ) {
164  holidays << i18n( "Yom HaAtzmaut" );
165  } else {
166  holidays << i18n( "Yom HaZikaron" );
167  }
168  break;
169  case Thursday:
170  // This can't be 2 Iyar.
171  holidays << i18n( "Yom HaAtzmaut" );
172  break;
173  case Friday:
174  case Saturday:
175  // These are never either of them.
176  break;
177  default:
178  // All other days follow the normal rules.
179  if ( day == 4 ) {
180  holidays << i18n( "Yom HaZikaron" );
181  } else if ( day == 5 ) {
182  holidays << i18n( "Yom HaAtzmaut" );
183  }
184  }
185  }
186  break;
187  case 28:
188  if ( year > 1967 + 3760 ) {
189  // only since the 1967 war
190  holidays << i18n( "Yom Yerushalayim" );
191  }
192  break;
193  case 18:
194  holidays << i18n( "Lag BaOmer" );
195  break;
196  }
197  if ( ( day != 18 ) && showOmer ) {
198  // Sfirah the whole month, Lag BaOmer is already mentioned.
199  holidays << sfirah( day + 15 );
200  }
201  break;
202 
203  case Sivan:
204  switch ( day ) {
205  case 1:
206  case 2:
207  case 3:
208  case 4:
209  // Sfirah until Shavuot
210  if ( showOmer ) {
211  holidays << sfirah( day + 44 );
212  }
213  break;
214  case 5:
215  // Don't need to mention Sfira(49) if there's already two other and
216  // more important pieces of information.
217  if ( showOmer && !isAShabbat ) {
218  holidays << sfirah( 49 );
219  }
220  holidays << i18n( "Erev Shavuot" );
221  break;
222  case 6:; case 7:
223  if ( !useIsraelSettings || ( day == 6 ) ) {
224  holidays << i18n( "Shavuot" );
225  }
226  break;
227  }
228  break;
229 
230  case Tamuz:
231  // 17th of Tamuz, except Shabbat pushes it to Sunday.
232  if ( ( !isAShabbat && ( day == 17 ) ) ||
233  ( ( weekday == Sunday ) && ( day == 18 ) ) ) {
234  holidays << i18n( "Tzom Tammuz" );
235  }
236  break;
237 
238  case Ab:
239  if ( isAShabbat && ( 3 <= day ) && ( day <= 16 ) ) {
240  // The shabbat before and after Tisha B'Av are special
241  if ( day <= 9 ) {
242  holidays << i18n( "Sh. Hazon" );
243  } else {
244  holidays << i18n( "Sh. Nahamu" );
245  }
246  } else if ( ( !isAShabbat && ( day == 9 ) ) ||
247  ( ( weekday == Sunday ) && ( day == 10 ) ) ) {
248  // 9th of Av, except Shabbat pushes it to Sunday.
249  holidays << i18n( "Tisha B'Av" );
250  }
251  break;
252 
253  case Elul:
254  if ( ( day >= 20 ) && ( day <= 26 ) && isAShabbat ) {
255  holidays << i18n( "S'lichot" );
256  } else if ( day == 29 ) {
257  holidays << i18n( "Erev R.H." );
258  }
259  break;
260 
261  case Tishrei:
262  switch ( day ) {
263  case 1:; case 2:
264  holidays << i18n( "Rosh Hashana" );
265  break;
266  case 3:
267  if ( isAShabbat ) {
268  holidays << i18n( "Sh. Shuvah" );
269  } else {
270  holidays << i18n( "Tzom Gedalia" );
271  }
272  break;
273  case 4:
274  if ( weekday == Sunday ) {
275  holidays << i18n( "Tzom Gedalia" );
276  }
277  /* fall through */
278  case 5:
279  case 6:
280  case 7:
281  case 8:
282  if ( isAShabbat ) {
283  holidays << i18n( "Sh. Shuvah" );
284  }
285  break;
286  case 9:
287  holidays << i18n( "Erev Y.K." );
288  break;
289  case 10:
290  holidays << i18n( "Yom Kippur" );
291  break;
292  case 14:
293  holidays << i18n( "Erev Sukkot" );
294  break;
295  case 15:
296  case 16:
297  if ( !useIsraelSettings || ( day == 15 ) ) {
298  holidays << i18n( "Sukkot" );
299  break;
300  }
301  /* else fall through */
302  case 17:
303  case 18:
304  case 19:
305  case 20:
306  if ( showChol ) {
307  holidays << i18n( "Chol Hamoed" );
308  }
309  break;
310  case 21:
311  holidays << i18n( "Hoshana Rabah" );
312  break;
313  case 22:
314  holidays << i18n( "Shmini Atzeret" );
315  break;
316  case 23:
317  if ( !useIsraelSettings ) {
318  holidays << i18n( "Simchat Torah" );
319  }
320  break;
321  }
322  break;
323 
324  case Cheshvan:
325  break;
326 
327  case Kislev:
328  if ( day == 24 ) {
329  holidays << i18n( "Erev Hanukah" );
330  } else if ( day >= 25 ) {
331  holidays << i18n( "Hanukah" );
332  }
333  break;
334 
335  case Tevet:
336  if ( day <= ( kvia == 0 ? 3 : 2 ) ) {
337  // We need to know the length of Kislev to determine the last day of
338  // Chanukah.
339  holidays << i18n( "Hanukah" );
340  } else if ( ( ( day == 10 ) && !isAShabbat ) ||
341  ( ( day == 11 ) && ( weekday == Sunday ) ) ) {
342  // 10th of Tevet; Shabbat pushes it to Sunday.
343  holidays << i18n( "Tzom Tevet" );
344  }
345  break;
346 
347  case Shvat:
348  switch ( day ) {
349  // The info for figuring out Shabbat Shirah is from the Gnu code. I
350  // assume it's correct.
351  case 10:
352  if ( ( kvia != 0 ) && isAShabbat ) {
353  holidays << i18n( "Sh. Shirah" );
354  }
355  break;
356  case 11:
357  case 12:
358  case 13:
359  case 14:
360  case 16:
361  if ( isAShabbat ) {
362  holidays << i18n( "Sh. Shirah" );
363  }
364  break;
365  case 15:
366  if ( isAShabbat ) {
367  holidays << i18n( "Sh. Shirah" );
368  }
369  holidays << i18n( "Tu B'Shvat" );
370  break;
371  case 17:
372  if ( ( kvia == 0 ) && isAShabbat ) {
373  holidays << i18n( "Sh. Shirah" );
374  }
375  break;
376  case 25:
377  case 26:
378  case 27:
379  case 28:
380  case 29:
381  case 30:
382  // The last shabbat on or before 1 Adar or 1 AdarII
383  if ( isAShabbat && !isLeapYear ) {
384  holidays << i18n( "Sh. Shekalim" );
385  }
386  break;
387  }
388  break;
389 
390  case AdarI:
391  if ( day == 14 ) {
392  // Eat Purim Katan Candy
393  holidays << i18n( "Purim Katan" );
394  } else if ( ( day >= 25 ) && isAShabbat ) {
395  // The last shabbat on or before 1 Adar II.
396  holidays << i18n( "Sh. Shekalim" );
397  }
398  break;
399 
400  case AdarII: /* Adar II or non-leap year Adar */
401  switch (day) {
402  case 1:
403  if ( isAShabbat ) {
404  holidays << i18n( "Sh. Shekalim" );
405  }
406  break;
407  case 11:
408  case 12:
409  // Ta'anit ester is on the 13th. But shabbat moves it back to
410  // Thursday.
411  if ( weekday == Thursday ) {
412  holidays << i18n( "Ta'anit Ester" );
413  }
414  /* fall through */
415  case 7:
416  case 8:
417  case 9:
418  case 10:
419  // The Shabbat before purim is Shabbat Zachor
420  if ( isAShabbat ) {
421  holidays << i18n( "Sh. Zachor" );
422  }
423  break;
424  case 13:
425  if ( isAShabbat ) {
426  holidays << i18n( "Sh. Zachor" );
427  } else {
428  holidays << i18n( "Erev Purim" );
429  }
430  // It's Ta'anit Esther, unless it's a Friday or Saturday
431  if ( weekday < Friday ) {
432  holidays << i18n( "Ta'anit Ester" );
433  }
434  break;
435  case 14:
436  holidays << i18n( "Purim" );
437  break;
438  case 15:
439  if ( !isAShabbat ) {
440  holidays << i18n( "Shushan Purim" );
441  }
442  break;
443  case 16:
444  if ( weekday == Sunday ) {
445  holidays << i18n( "Shushan Purim" );
446  }
447  break;
448  case 17:
449  case 18:
450  case 19:
451  case 20:
452  case 21:
453  case 22:
454  case 23:
455  if ( isAShabbat ) {
456  holidays << i18n( "Sh. Parah" );
457  }
458  break;
459  case 24:
460  case 25:
461  case 26:
462  case 27:
463  case 28:
464  case 29:
465  if ( isAShabbat ) {
466  holidays << i18n( "Sh. HaHodesh" );
467  }
468  break;
469  }
470  break;
471  }
472  if ( isAShabbat && showParsha ) {
473  // Find the Parsha on Shabbat.
474  holidays << Parsha::findParshaName( dayNumber, kvia, isLeapYear,
475  useIsraelSettings );
476  }
477  return holidays;
478 }
479 
480 QString Holiday::sfirah( int day )
481 {
482  QString buffer = QString::number( day );
483  buffer + i18n( " Omer" ); // TODO: Find a way to write 1st instead of 1,
484  // 2nd instead of 2, etc.
485  return buffer;
486 }
Holiday::findHoliday
static QStringList findHoliday(HebrewDate hd, bool useIsraelSettings, bool showParsha, bool showChol, bool showOmer)
Given a day of a Hebrew month, figures out all the interesting holidays that correspond to that date...
Definition: holiday.cpp:33
HebrewDate::month
int month() const
Definition: converter.cpp:59
HebrewDate
This class converts dates between the Hebrew and Gregorian (secular) calendars.
Definition: converter.h:45
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
HebrewDate::year
int year() const
Definition: converter.cpp:54
HebrewDate::hebrewDayNumber
int hebrewDayNumber() const
Definition: converter.cpp:99
HebrewDate::isOnHebrewLeapYear
bool isOnHebrewLeapYear() const
Definition: converter.cpp:84
HebrewDate::day
int day() const
Definition: converter.cpp:64
HebrewDate::kvia
int kvia() const
Definition: converter.cpp:94
holiday.h
HebrewDate::dayOfWeek
int dayOfWeek() const
Definition: converter.cpp:69
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