-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathHebrewDateFormatter.java
More file actions
1106 lines (1047 loc) · 58.6 KB
/
HebrewDateFormatter.java
File metadata and controls
1106 lines (1047 loc) · 58.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Zmanim Java API
* Copyright (C) 2011 - 2024 Eliyahu Hershfeld
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA,
* or connect to: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
*/
package com.kosherjava.zmanim.hebrewcalendar;
import java.text.SimpleDateFormat;
import java.util.EnumMap;
/**
* The HebrewDateFormatter class formats a {@link JewishDate}.
*
* The class formats Jewish dates, numbers, <em>Daf Yomi</em> (<em>Bavli</em> and <em>Yerushalmi</em>), the <em>Omer</em>,
* <em>Parshas Hashavua</em> (including the special <em>parshiyos</em> of <em>Shekalim</em>, <em>Zachor</em>, <em>Parah</em>
* and <em>Hachodesh</em>), Yomim Tovim and the Molad (experimental) in Hebrew or Latin chars, and has various settings.
* Sample full date output includes (using various options):
* <ul>
* <li>21 Shevat, 5729</li>
* <li>כא שבט תשכט</li>
* <li>כ״א שבט ה׳תשכ״ט</li>
* <li>כ״א שבט תש״פ or
* כ״א שבט תש״ף</li>
* <li>כ׳ שבט ו׳ אלפים</li>
* </ul>
*
* @see JewishDate
* @see JewishCalendar
*
* @author © Eliyahu Hershfeld 2011 - 2024
*/
public class HebrewDateFormatter {
/**
* See {@link #isHebrewFormat()} and {@link #setHebrewFormat(boolean)}.
*/
private boolean hebrewFormat = false;
/**
* See {@link #isUseLongHebrewYears()} and {@link #setUseLongHebrewYears(boolean)}.
*/
private boolean useLonghebrewYears = false;
/**
* See {@link #isUseGershGershayim()} and {@link #setUseGershGershayim(boolean)}.
*/
private boolean useGershGershayim = true;
/**
* See {@link #isLongWeekFormat()} and {@link #setLongWeekFormat(boolean)}.
*/
private boolean longWeekFormat = true;
/**
* See {@link #isUseFinalFormLetters()} and {@link #setUseFinalFormLetters(boolean)}.
*/
private boolean useFinalFormLetters = false;
/**
* The internal DateFormat. See {@link #isLongWeekFormat()} and {@link #setLongWeekFormat(boolean)}.
*/
private SimpleDateFormat weekFormat = null;
/**
* List of transliterated parshiyos using the default <em>Ashkenazi</em> pronunciation. The formatParsha method
* uses this for transliterated <em>parsha</em> formatting. This list can be overridden (for <em>Sephardi</em>
* English transliteration for example) by setting the {@link #setTransliteratedParshiosList(EnumMap)}. The list
* includes double and special <em>parshiyos</em> is set as "<em>Bereshis, Noach, Lech Lecha, Vayera, Chayei Sara,
* Toldos, Vayetzei, Vayishlach, Vayeshev, Miketz, Vayigash, Vayechi, Shemos, Vaera, Bo, Beshalach, Yisro, Mishpatim,
* Terumah, Tetzaveh, Ki Sisa, Vayakhel, Pekudei, Vayikra, Tzav, Shmini, Tazria, Metzora, Achrei Mos, Kedoshim, Emor,
* Behar, Bechukosai, Bamidbar, Nasso, Beha'aloscha, Sh'lach, Korach, Chukas, Balak, Pinchas, Matos, Masei, Devarim,
* Vaeschanan, Eikev, Re'eh, Shoftim, Ki Seitzei, Ki Savo, Nitzavim, Vayeilech, Ha'Azinu, Vezos Habracha,
* Vayakhel Pekudei, Tazria Metzora, Achrei Mos Kedoshim, Behar Bechukosai, Chukas Balak, Matos Masei, Nitzavim Vayeilech,
* Shekalim, Zachor, Parah, Hachodesh,Shuva, Shira, Hagadol, Chazon, Nachamu</em>".
*
* @see #formatParsha(JewishCalendar)
*/
private EnumMap<JewishCalendar.Parsha, String> transliteratedParshaMap;
/**
* Unicode {@link EnumMap} of Hebrew <em>parshiyos</em>. The list includes double and special <em>parshiyos</em> and
* contains <code>"בראשית, נח, לך לך,
* וירא, חיי שרה,
* תולדות, ויצא, וישלח,
* וישב, מקץ, ויגש, ויחי,
* שמות, וארא, בא, בשלח,
* יתרו, משפטים, תרומה,
* תצוה, כי תשא, ויקהל,
* פקודי, ויקרא, צו,
* שמיני, תזריע, מצרע,
* אחרי מות, קדושים,
* אמור, בהר, בחקתי,
* במדבר, נשא, בהעלתך,
* שלח לך, קרח, חוקת, בלק,
* פינחס, מטות, מסעי,
* דברים, ואתחנן, עקב,
* ראה, שופטים, כי תצא,
* כי תבוא, נצבים, וילך,
* האזינו, וזאת הברכה,
* ויקהל פקודי, תזריע
* מצרע, אחרי מות
* קדושים, בהר בחקתי,
* חוקת בלק, מטות מסעי,
* נצבים וילך, שקלים,
* זכור, פרה, החדש,
* שובה,שירה,הגדול,
* חזון,נחמו"</code>
*/
private final EnumMap<JewishCalendar.Parsha, String> hebrewParshaMap;
/**
* Default constructor sets the {@link EnumMap}s of Hebrew and default transliterated parshiyos.
*/
public HebrewDateFormatter() {
weekFormat = new SimpleDateFormat("EEEE");
transliteratedParshaMap = new EnumMap<>(JewishCalendar.Parsha.class);
transliteratedParshaMap.put(JewishCalendar.Parsha.NONE, "");
transliteratedParshaMap.put(JewishCalendar.Parsha.BERESHIS, "Bereshis");
transliteratedParshaMap.put(JewishCalendar.Parsha.NOACH, "Noach");
transliteratedParshaMap.put(JewishCalendar.Parsha.LECH_LECHA, "Lech Lecha");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYERA, "Vayera");
transliteratedParshaMap.put(JewishCalendar.Parsha.CHAYEI_SARA, "Chayei Sara");
transliteratedParshaMap.put(JewishCalendar.Parsha.TOLDOS, "Toldos");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYETZEI, "Vayetzei");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYISHLACH, "Vayishlach");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYESHEV, "Vayeshev");
transliteratedParshaMap.put(JewishCalendar.Parsha.MIKETZ, "Miketz");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYIGASH, "Vayigash");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYECHI, "Vayechi");
transliteratedParshaMap.put(JewishCalendar.Parsha.SHEMOS, "Shemos");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAERA, "Vaera");
transliteratedParshaMap.put(JewishCalendar.Parsha.BO, "Bo");
transliteratedParshaMap.put(JewishCalendar.Parsha.BESHALACH, "Beshalach");
transliteratedParshaMap.put(JewishCalendar.Parsha.YISRO, "Yisro");
transliteratedParshaMap.put(JewishCalendar.Parsha.MISHPATIM, "Mishpatim");
transliteratedParshaMap.put(JewishCalendar.Parsha.TERUMAH, "Terumah");
transliteratedParshaMap.put(JewishCalendar.Parsha.TETZAVEH, "Tetzaveh");
transliteratedParshaMap.put(JewishCalendar.Parsha.KI_SISA, "Ki Sisa");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYAKHEL, "Vayakhel");
transliteratedParshaMap.put(JewishCalendar.Parsha.PEKUDEI, "Pekudei");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYIKRA, "Vayikra");
transliteratedParshaMap.put(JewishCalendar.Parsha.TZAV, "Tzav");
transliteratedParshaMap.put(JewishCalendar.Parsha.SHMINI, "Shmini");
transliteratedParshaMap.put(JewishCalendar.Parsha.TAZRIA, "Tazria");
transliteratedParshaMap.put(JewishCalendar.Parsha.METZORA, "Metzora");
transliteratedParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS, "Achrei Mos");
transliteratedParshaMap.put(JewishCalendar.Parsha.KEDOSHIM, "Kedoshim");
transliteratedParshaMap.put(JewishCalendar.Parsha.EMOR, "Emor");
transliteratedParshaMap.put(JewishCalendar.Parsha.BEHAR, "Behar");
transliteratedParshaMap.put(JewishCalendar.Parsha.BECHUKOSAI, "Bechukosai");
transliteratedParshaMap.put(JewishCalendar.Parsha.BAMIDBAR, "Bamidbar");
transliteratedParshaMap.put(JewishCalendar.Parsha.NASSO, "Nasso");
transliteratedParshaMap.put(JewishCalendar.Parsha.BEHAALOSCHA, "Beha'aloscha");
transliteratedParshaMap.put(JewishCalendar.Parsha.SHLACH, "Sh'lach");
transliteratedParshaMap.put(JewishCalendar.Parsha.KORACH, "Korach");
transliteratedParshaMap.put(JewishCalendar.Parsha.CHUKAS, "Chukas");
transliteratedParshaMap.put(JewishCalendar.Parsha.BALAK, "Balak");
transliteratedParshaMap.put(JewishCalendar.Parsha.PINCHAS, "Pinchas");
transliteratedParshaMap.put(JewishCalendar.Parsha.MATOS, "Matos");
transliteratedParshaMap.put(JewishCalendar.Parsha.MASEI, "Masei");
transliteratedParshaMap.put(JewishCalendar.Parsha.DEVARIM, "Devarim");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAESCHANAN, "Vaeschanan");
transliteratedParshaMap.put(JewishCalendar.Parsha.EIKEV, "Eikev");
transliteratedParshaMap.put(JewishCalendar.Parsha.REEH, "Re'eh");
transliteratedParshaMap.put(JewishCalendar.Parsha.SHOFTIM, "Shoftim");
transliteratedParshaMap.put(JewishCalendar.Parsha.KI_SEITZEI, "Ki Seitzei");
transliteratedParshaMap.put(JewishCalendar.Parsha.KI_SAVO, "Ki Savo");
transliteratedParshaMap.put(JewishCalendar.Parsha.NITZAVIM, "Nitzavim");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYEILECH, "Vayeilech");
transliteratedParshaMap.put(JewishCalendar.Parsha.HAAZINU, "Ha'Azinu");
transliteratedParshaMap.put(JewishCalendar.Parsha.VZOS_HABERACHA, "Vezos Habracha");
transliteratedParshaMap.put(JewishCalendar.Parsha.VAYAKHEL_PEKUDEI, "Vayakhel Pekudei");
transliteratedParshaMap.put(JewishCalendar.Parsha.TAZRIA_METZORA, "Tazria Metzora");
transliteratedParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS_KEDOSHIM, "Achrei Mos Kedoshim");
transliteratedParshaMap.put(JewishCalendar.Parsha.BEHAR_BECHUKOSAI, "Behar Bechukosai");
transliteratedParshaMap.put(JewishCalendar.Parsha.CHUKAS_BALAK, "Chukas Balak");
transliteratedParshaMap.put(JewishCalendar.Parsha.MATOS_MASEI, "Matos Masei");
transliteratedParshaMap.put(JewishCalendar.Parsha.NITZAVIM_VAYEILECH, "Nitzavim Vayeilech");
transliteratedParshaMap.put(JewishCalendar.Parsha.SHKALIM, "Shekalim");
transliteratedParshaMap.put(JewishCalendar.Parsha.ZACHOR, "Zachor");
transliteratedParshaMap.put(JewishCalendar.Parsha.PARA, "Parah");
transliteratedParshaMap.put(JewishCalendar.Parsha.HACHODESH, "Hachodesh");
transliteratedParshaMap.put(JewishCalendar.Parsha.SHUVA, "Shuva");
transliteratedParshaMap.put(JewishCalendar.Parsha.SHIRA, "Shira");
transliteratedParshaMap.put(JewishCalendar.Parsha.HAGADOL, "Hagadol");
transliteratedParshaMap.put(JewishCalendar.Parsha.CHAZON, "Chazon");
transliteratedParshaMap.put(JewishCalendar.Parsha.NACHAMU, "Nachamu");
hebrewParshaMap = new EnumMap<>(JewishCalendar.Parsha.class);
hebrewParshaMap.put(JewishCalendar.Parsha.NONE, "");
hebrewParshaMap.put(JewishCalendar.Parsha.BERESHIS, "\u05D1\u05E8\u05D0\u05E9\u05D9\u05EA");
hebrewParshaMap.put(JewishCalendar.Parsha.NOACH, "\u05E0\u05D7");
hebrewParshaMap.put(JewishCalendar.Parsha.LECH_LECHA, "\u05DC\u05DA \u05DC\u05DA");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYERA, "\u05D5\u05D9\u05E8\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.CHAYEI_SARA, "\u05D7\u05D9\u05D9 \u05E9\u05E8\u05D4");
hebrewParshaMap.put(JewishCalendar.Parsha.TOLDOS, "\u05EA\u05D5\u05DC\u05D3\u05D5\u05EA");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYETZEI, "\u05D5\u05D9\u05E6\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYISHLACH, "\u05D5\u05D9\u05E9\u05DC\u05D7");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYESHEV, "\u05D5\u05D9\u05E9\u05D1");
hebrewParshaMap.put(JewishCalendar.Parsha.MIKETZ, "\u05DE\u05E7\u05E5");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYIGASH, "\u05D5\u05D9\u05D2\u05E9");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYECHI, "\u05D5\u05D9\u05D7\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.SHEMOS, "\u05E9\u05DE\u05D5\u05EA");
hebrewParshaMap.put(JewishCalendar.Parsha.VAERA, "\u05D5\u05D0\u05E8\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.BO, "\u05D1\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.BESHALACH, "\u05D1\u05E9\u05DC\u05D7");
hebrewParshaMap.put(JewishCalendar.Parsha.YISRO, "\u05D9\u05EA\u05E8\u05D5");
hebrewParshaMap.put(JewishCalendar.Parsha.MISHPATIM, "\u05DE\u05E9\u05E4\u05D8\u05D9\u05DD");
hebrewParshaMap.put(JewishCalendar.Parsha.TERUMAH, "\u05EA\u05E8\u05D5\u05DE\u05D4");
hebrewParshaMap.put(JewishCalendar.Parsha.TETZAVEH, "\u05EA\u05E6\u05D5\u05D4");
hebrewParshaMap.put(JewishCalendar.Parsha.KI_SISA, "\u05DB\u05D9 \u05EA\u05E9\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYAKHEL, "\u05D5\u05D9\u05E7\u05D4\u05DC");
hebrewParshaMap.put(JewishCalendar.Parsha.PEKUDEI, "\u05E4\u05E7\u05D5\u05D3\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYIKRA, "\u05D5\u05D9\u05E7\u05E8\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.TZAV, "\u05E6\u05D5");
hebrewParshaMap.put(JewishCalendar.Parsha.SHMINI, "\u05E9\u05DE\u05D9\u05E0\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.TAZRIA, "\u05EA\u05D6\u05E8\u05D9\u05E2");
hebrewParshaMap.put(JewishCalendar.Parsha.METZORA, "\u05DE\u05E6\u05E8\u05E2");
hebrewParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS, "\u05D0\u05D7\u05E8\u05D9 \u05DE\u05D5\u05EA");
hebrewParshaMap.put(JewishCalendar.Parsha.KEDOSHIM, "\u05E7\u05D3\u05D5\u05E9\u05D9\u05DD");
hebrewParshaMap.put(JewishCalendar.Parsha.EMOR, "\u05D0\u05DE\u05D5\u05E8");
hebrewParshaMap.put(JewishCalendar.Parsha.BEHAR, "\u05D1\u05D4\u05E8");
hebrewParshaMap.put(JewishCalendar.Parsha.BECHUKOSAI, "\u05D1\u05D7\u05E7\u05EA\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.BAMIDBAR, "\u05D1\u05DE\u05D3\u05D1\u05E8");
hebrewParshaMap.put(JewishCalendar.Parsha.NASSO, "\u05E0\u05E9\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.BEHAALOSCHA, "\u05D1\u05D4\u05E2\u05DC\u05EA\u05DA");
hebrewParshaMap.put(JewishCalendar.Parsha.SHLACH, "\u05E9\u05DC\u05D7 \u05DC\u05DA");
hebrewParshaMap.put(JewishCalendar.Parsha.KORACH, "\u05E7\u05E8\u05D7");
hebrewParshaMap.put(JewishCalendar.Parsha.CHUKAS, "\u05D7\u05D5\u05E7\u05EA");
hebrewParshaMap.put(JewishCalendar.Parsha.BALAK, "\u05D1\u05DC\u05E7");
hebrewParshaMap.put(JewishCalendar.Parsha.PINCHAS, "\u05E4\u05D9\u05E0\u05D7\u05E1");
hebrewParshaMap.put(JewishCalendar.Parsha.MATOS, "\u05DE\u05D8\u05D5\u05EA");
hebrewParshaMap.put(JewishCalendar.Parsha.MASEI, "\u05DE\u05E1\u05E2\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.DEVARIM, "\u05D3\u05D1\u05E8\u05D9\u05DD");
hebrewParshaMap.put(JewishCalendar.Parsha.VAESCHANAN, "\u05D5\u05D0\u05EA\u05D7\u05E0\u05DF");
hebrewParshaMap.put(JewishCalendar.Parsha.EIKEV, "\u05E2\u05E7\u05D1");
hebrewParshaMap.put(JewishCalendar.Parsha.REEH, "\u05E8\u05D0\u05D4");
hebrewParshaMap.put(JewishCalendar.Parsha.SHOFTIM, "\u05E9\u05D5\u05E4\u05D8\u05D9\u05DD");
hebrewParshaMap.put(JewishCalendar.Parsha.KI_SEITZEI, "\u05DB\u05D9 \u05EA\u05E6\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.KI_SAVO, "\u05DB\u05D9 \u05EA\u05D1\u05D5\u05D0");
hebrewParshaMap.put(JewishCalendar.Parsha.NITZAVIM, "\u05E0\u05E6\u05D1\u05D9\u05DD");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYEILECH, "\u05D5\u05D9\u05DC\u05DA");
hebrewParshaMap.put(JewishCalendar.Parsha.HAAZINU, "\u05D4\u05D0\u05D6\u05D9\u05E0\u05D5");
hebrewParshaMap.put(JewishCalendar.Parsha.VZOS_HABERACHA, "\u05D5\u05D6\u05D0\u05EA \u05D4\u05D1\u05E8\u05DB\u05D4 ");
hebrewParshaMap.put(JewishCalendar.Parsha.VAYAKHEL_PEKUDEI, "\u05D5\u05D9\u05E7\u05D4\u05DC \u05E4\u05E7\u05D5\u05D3\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.TAZRIA_METZORA, "\u05EA\u05D6\u05E8\u05D9\u05E2 \u05DE\u05E6\u05E8\u05E2");
hebrewParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS_KEDOSHIM, "\u05D0\u05D7\u05E8\u05D9 \u05DE\u05D5\u05EA \u05E7\u05D3\u05D5\u05E9\u05D9\u05DD");
hebrewParshaMap.put(JewishCalendar.Parsha.BEHAR_BECHUKOSAI, "\u05D1\u05D4\u05E8 \u05D1\u05D7\u05E7\u05EA\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.CHUKAS_BALAK, "\u05D7\u05D5\u05E7\u05EA \u05D1\u05DC\u05E7");
hebrewParshaMap.put(JewishCalendar.Parsha.MATOS_MASEI, "\u05DE\u05D8\u05D5\u05EA \u05DE\u05E1\u05E2\u05D9");
hebrewParshaMap.put(JewishCalendar.Parsha.NITZAVIM_VAYEILECH, "\u05E0\u05E6\u05D1\u05D9\u05DD \u05D5\u05D9\u05DC\u05DA");
hebrewParshaMap.put(JewishCalendar.Parsha.SHKALIM, "\u05E9\u05E7\u05DC\u05D9\u05DD");
hebrewParshaMap.put(JewishCalendar.Parsha.ZACHOR, "\u05D6\u05DB\u05D5\u05E8");
hebrewParshaMap.put(JewishCalendar.Parsha.PARA, "\u05E4\u05E8\u05D4");
hebrewParshaMap.put(JewishCalendar.Parsha.HACHODESH, "\u05D4\u05D7\u05D3\u05E9");
hebrewParshaMap.put(JewishCalendar.Parsha.SHUVA, "\u05E9\u05D5\u05D1\u05D4");
hebrewParshaMap.put(JewishCalendar.Parsha.SHIRA, "\u05E9\u05D9\u05E8\u05D4");
hebrewParshaMap.put(JewishCalendar.Parsha.HAGADOL, "\u05D4\u05D2\u05D3\u05D5\u05DC");
hebrewParshaMap.put(JewishCalendar.Parsha.CHAZON, "\u05D7\u05D6\u05D5\u05DF");
hebrewParshaMap.put(JewishCalendar.Parsha.NACHAMU, "\u05E0\u05D7\u05DE\u05D5");
}
/**
* Returns if the {@link #formatDayOfWeek(JewishDate)} will use the long format such as
* ראשון or short such as א when formatting the day of week in
* {@link #isHebrewFormat() Hebrew}.
*
* @return the longWeekFormat
* @see #setLongWeekFormat(boolean)
* @see #formatDayOfWeek(JewishDate)
*/
public boolean isLongWeekFormat() {
return longWeekFormat;
}
/**
* Setting to control if the {@link #formatDayOfWeek(JewishDate)} will use the long format such as
* ראשון or short such as א when formatting the day of week in
* {@link #isHebrewFormat() Hebrew}.
*
* @param longWeekFormat
* the longWeekFormat to set
*/
public void setLongWeekFormat(boolean longWeekFormat) {
this.longWeekFormat = longWeekFormat;
if (longWeekFormat) {
weekFormat = new SimpleDateFormat("EEEE");
} else {
weekFormat = new SimpleDateFormat("EEE");
}
}
/**
* The <a href="https://en.wikipedia.org/wiki/Geresh#Punctuation_mark">gersh</a> character is the ׳ char
* that is similar to a single quote and is used in formatting Hebrew numbers.
*/
private static final String GERESH = "\u05F3";
/**
* The <a href="https://en.wikipedia.org/wiki/Gershayim#Punctuation_mark">gershyim</a> character is the ״ char
* that is similar to a double quote and is used in formatting Hebrew numbers.
*/
private static final String GERSHAYIM = "\u05F4";
/**
* Transliterated month names. Defaults to ["Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Marcheshvan",
* "Kislev", "Teves", "Shevat", "Adar", "Adar II", "Adar I" ].
* @see #getTransliteratedMonthList()
* @see #setTransliteratedMonthList(String[])
*/
private String[] transliteratedMonths = { "Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Marcheshvan",
"Kislev", "Teves", "Shevat", "Adar", "Adar II", "Adar I" };
/**
* The Hebrew omer prefix charachter. It defaults to ב producing בעומר,
* but can be set to ל to produce לעומר (or any other prefix).
* @see #getHebrewOmerPrefix()
* @see #setHebrewOmerPrefix(String)
*/
private String hebrewOmerPrefix = "\u05D1";
/**
* The default value for formatting Shabbos (Saturday). Defaults to Shabbos.
* @see #getTransliteratedShabbosDayOfWeek()
* @see #setTransliteratedShabbosDayOfWeek(String)
*/
private String transliteratedShabbosDayOfWeek = "Shabbos";
/**
* Returns the day of Shabbos transliterated into Latin chars. The default uses Ashkenazi pronunciation "Shabbos".
* This can be overwritten using the {@link #setTransliteratedShabbosDayOfWeek(String)}
*
* @return the transliteratedShabbos. The default list of months uses Ashkenazi pronunciation "Shabbos".
* @see #setTransliteratedShabbosDayOfWeek(String)
* @see #formatDayOfWeek(JewishDate)
*/
public String getTransliteratedShabbosDayOfWeek() {
return transliteratedShabbosDayOfWeek;
}
/**
* Setter to override the default transliterated name of "Shabbos" to alternate spelling such as "Shabbat" used by
* the {@link #formatDayOfWeek(JewishDate)}
*
* @param transliteratedShabbos
* the transliteratedShabbos to set
*
* @see #getTransliteratedShabbosDayOfWeek()
* @see #formatDayOfWeek(JewishDate)
*/
public void setTransliteratedShabbosDayOfWeek(String transliteratedShabbos) {
this.transliteratedShabbosDayOfWeek = transliteratedShabbos;
}
/**
* See {@link #getTransliteratedHolidayList()} and {@link #setTransliteratedHolidayList(String[])}.
*/
private String[] transliteratedHolidays = {"Erev Pesach", "Pesach", "Chol Hamoed Pesach", "Pesach Sheni",
"Erev Shavuos", "Shavuos", "Seventeenth of Tammuz", "Tishah B'Av", "Tu B'Av", "Erev Rosh Hashana",
"Rosh Hashana", "Fast of Gedalyah", "Erev Yom Kippur", "Yom Kippur", "Erev Succos", "Succos",
"Chol Hamoed Succos", "Hoshana Rabbah", "Shemini Atzeres", "Simchas Torah", "Erev Chanukah", "Chanukah",
"Tenth of Teves", "Tu B'Shvat", "Fast of Esther", "Purim", "Shushan Purim", "Purim Katan", "Rosh Chodesh",
"Yom HaShoah", "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim", "Lag B'Omer","Shushan Purim Katan",
"Isru Chag"};
/**
* Returns the array of holidays transliterated into Latin chars. This is used by the
* {@link #formatYomTov(JewishCalendar)} when formatting the Yom Tov String. The default list of months uses
* Ashkenazi pronunciation in typical American English spelling.
*
* @return the array of transliterated holidays. The default list is currently ["Erev Pesach", "Pesach",
* "Chol Hamoed Pesach", "Pesach Sheni", "Erev Shavuos", "Shavuos", "Seventeenth of Tammuz", "Tishah B'Av",
* "Tu B'Av", "Erev Rosh Hashana", "Rosh Hashana", "Fast of Gedalyah", "Erev Yom Kippur", "Yom Kippur",
* "Erev Succos", "Succos", "Chol Hamoed Succos", "Hoshana Rabbah", "Shemini Atzeres", "Simchas Torah",
* "Erev Chanukah", "Chanukah", "Tenth of Teves", "Tu B'Shvat", "Fast of Esther", "Purim", "Shushan Purim",
* "Purim Katan", "Rosh Chodesh", "Yom HaShoah", "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim",
* "Lag B'Omer","Shushan Purim Katan","Isru Chag"].
*
* @see #setTransliteratedMonthList(String[])
* @see #formatYomTov(JewishCalendar)
* @see #isHebrewFormat()
*/
public String[] getTransliteratedHolidayList() {
return transliteratedHolidays;
}
/**
* Sets the array of holidays transliterated into Latin chars. This is used by the
* {@link #formatYomTov(JewishCalendar)} when formatting the Yom Tov String.
*
* @param transliteratedHolidays
* the transliteratedHolidays to set. Ensure that the sequence exactly matches the list returned by the
* default
*/
public void setTransliteratedHolidayList(String[] transliteratedHolidays) {
this.transliteratedHolidays = transliteratedHolidays;
}
/**
* Hebrew holiday array in the following format.<br><code>["ערב פסח",
* "פסח", "חול המועד
* פסח", "פסח שני", "ערב
* שבועות", "שבועות",
* "שבעה עשר בתמוז",
* "תשעה באב",
* "ט״ו באב",
* "ערב ראש השנה",
* "ראש השנה",
* "צום גדליה",
* "ערב יום כיפור",
* "יום כיפור",
* "ערב סוכות",
* "סוכות",
* "חול המועד סוכות",
* "הושענא רבה",
* "שמיני עצרת",
* "שמחת תורה",
* "ערב חנוכה",
* "חנוכה", "עשרה בטבת",
* "ט״ו בשבט",
* "תענית אסתר",
* "פורים",
* "שושן פורים",
* "פורים קטן",
* "ראש חודש",
* "יום השואה",
* "יום הזיכרון",
* "יום העצמאות",
* "יום ירושלים",
* "ל״ג בעומר",
* "שושן פורים קטן"]</code>
*/
private final String[] hebrewHolidays = { "\u05E2\u05E8\u05D1 \u05E4\u05E1\u05D7", "\u05E4\u05E1\u05D7",
"\u05D7\u05D5\u05DC \u05D4\u05DE\u05D5\u05E2\u05D3 \u05E4\u05E1\u05D7",
"\u05E4\u05E1\u05D7 \u05E9\u05E0\u05D9", "\u05E2\u05E8\u05D1 \u05E9\u05D1\u05D5\u05E2\u05D5\u05EA",
"\u05E9\u05D1\u05D5\u05E2\u05D5\u05EA",
"\u05E9\u05D1\u05E2\u05D4 \u05E2\u05E9\u05E8 \u05D1\u05EA\u05DE\u05D5\u05D6",
"\u05EA\u05E9\u05E2\u05D4 \u05D1\u05D0\u05D1", "\u05D8\u05F4\u05D5 \u05D1\u05D0\u05D1",
"\u05E2\u05E8\u05D1 \u05E8\u05D0\u05E9 \u05D4\u05E9\u05E0\u05D4",
"\u05E8\u05D0\u05E9 \u05D4\u05E9\u05E0\u05D4", "\u05E6\u05D5\u05DD \u05D2\u05D3\u05DC\u05D9\u05D4",
"\u05E2\u05E8\u05D1 \u05D9\u05D5\u05DD \u05DB\u05D9\u05E4\u05D5\u05E8",
"\u05D9\u05D5\u05DD \u05DB\u05D9\u05E4\u05D5\u05E8", "\u05E2\u05E8\u05D1 \u05E1\u05D5\u05DB\u05D5\u05EA",
"\u05E1\u05D5\u05DB\u05D5\u05EA",
"\u05D7\u05D5\u05DC \u05D4\u05DE\u05D5\u05E2\u05D3 \u05E1\u05D5\u05DB\u05D5\u05EA",
"\u05D4\u05D5\u05E9\u05E2\u05E0\u05D0 \u05E8\u05D1\u05D4",
"\u05E9\u05DE\u05D9\u05E0\u05D9 \u05E2\u05E6\u05E8\u05EA",
"\u05E9\u05DE\u05D7\u05EA \u05EA\u05D5\u05E8\u05D4", "\u05E2\u05E8\u05D1 \u05D7\u05E0\u05D5\u05DB\u05D4",
"\u05D7\u05E0\u05D5\u05DB\u05D4", "\u05E2\u05E9\u05E8\u05D4 \u05D1\u05D8\u05D1\u05EA",
"\u05D8\u05F4\u05D5 \u05D1\u05E9\u05D1\u05D8", "\u05EA\u05E2\u05E0\u05D9\u05EA \u05D0\u05E1\u05EA\u05E8",
"\u05E4\u05D5\u05E8\u05D9\u05DD", "\u05E9\u05D5\u05E9\u05DF \u05E4\u05D5\u05E8\u05D9\u05DD",
"\u05E4\u05D5\u05E8\u05D9\u05DD \u05E7\u05D8\u05DF", "\u05E8\u05D0\u05E9 \u05D7\u05D5\u05D3\u05E9",
"\u05D9\u05D5\u05DD \u05D4\u05E9\u05D5\u05D0\u05D4",
"\u05D9\u05D5\u05DD \u05D4\u05D6\u05D9\u05DB\u05E8\u05D5\u05DF",
"\u05D9\u05D5\u05DD \u05D4\u05E2\u05E6\u05DE\u05D0\u05D5\u05EA",
"\u05D9\u05D5\u05DD \u05D9\u05E8\u05D5\u05E9\u05DC\u05D9\u05DD",
"\u05DC\u05F4\u05D2 \u05D1\u05E2\u05D5\u05DE\u05E8",
"\u05E9\u05D5\u05E9\u05DF \u05E4\u05D5\u05E8\u05D9\u05DD \u05E7\u05D8\u05DF",
"\u05D0\u05E1\u05E8\u05D5 \u05D7\u05D2"};
/**
* Formats the Yom Tov (holiday) in Hebrew or transliterated Latin characters.
*
* @param jewishCalendar the JewishCalendar
* @return the formatted holiday or an empty String if the day is not a holiday.
* @see #isHebrewFormat()
*/
public String formatYomTov(JewishCalendar jewishCalendar) {
int index = jewishCalendar.getYomTovIndex();
if (index == JewishCalendar.CHANUKAH) {
int dayOfChanukah = jewishCalendar.getDayOfChanukah();
return hebrewFormat ? (formatHebrewNumber(dayOfChanukah) + " " + hebrewHolidays[index])
: (transliteratedHolidays[index] + " " + dayOfChanukah);
}
return index == -1 ? "" : hebrewFormat ? hebrewHolidays[index] : transliteratedHolidays[index];
}
/**
* Formats a day as Rosh Chodesh in the format of in the format of ראש
* חודש שבט or Rosh Chodesh Shevat. If it
* is not Rosh Chodesh, an empty <code>String</code> will be returned.
* @param jewishCalendar the JewishCalendar
* @return The formatted <code>String</code> in the format of ראש
* חודש שבט or Rosh Chodesh Shevat. If it
* is not Rosh Chodesh, an empty <code>String</code> will be returned.
*/
public String formatRoshChodesh(JewishCalendar jewishCalendar) {
if (!jewishCalendar.isRoshChodesh()) {
return "";
}
int month = jewishCalendar.getJewishMonth();
if (jewishCalendar.getJewishDayOfMonth() == 30) {
if (month < JewishCalendar.ADAR || (month == JewishCalendar.ADAR && jewishCalendar.isJewishLeapYear())) {
month++;
} else { // roll to Nissan
month = JewishCalendar.NISSAN;
}
}
// This method is only about formatting, so we shouldn't make any changes to the params passed in...
jewishCalendar = (JewishCalendar) jewishCalendar.clone();
jewishCalendar.setJewishMonth(month);
String formattedRoshChodesh = hebrewFormat ? hebrewHolidays[JewishCalendar.ROSH_CHODESH]
: transliteratedHolidays[JewishCalendar.ROSH_CHODESH];
formattedRoshChodesh += " " + formatMonth(jewishCalendar);
return formattedRoshChodesh;
}
/**
* Returns if the formatter is set to use Hebrew formatting in the various formatting methods.
*
* @return the hebrewFormat
* @see #setHebrewFormat(boolean)
* @see #format(JewishDate)
* @see #formatDayOfWeek(JewishDate)
* @see #formatMonth(JewishDate)
* @see #formatOmer(JewishCalendar)
* @see #formatYomTov(JewishCalendar)
*/
public boolean isHebrewFormat() {
return hebrewFormat;
}
/**
* Sets the formatter to format in Hebrew in the various formatting methods.
*
* @param hebrewFormat
* the hebrewFormat to set
* @see #isHebrewFormat()
* @see #format(JewishDate)
* @see #formatDayOfWeek(JewishDate)
* @see #formatMonth(JewishDate)
* @see #formatOmer(JewishCalendar)
* @see #formatYomTov(JewishCalendar)
*/
public void setHebrewFormat(boolean hebrewFormat) {
this.hebrewFormat = hebrewFormat;
}
/**
* Returns the Hebrew Omer prefix. By default it is the letter ב producing
* בעומר, but it can be set to ל to produce
* לעומר (or any other prefix) using the {@link #setHebrewOmerPrefix(String)}.
*
* @return the hebrewOmerPrefix
*
* @see #hebrewOmerPrefix
* @see #setHebrewOmerPrefix(String)
* @see #formatOmer(JewishCalendar)
*/
public String getHebrewOmerPrefix() {
return hebrewOmerPrefix;
}
/**
* Method to set the Hebrew Omer prefix. By default it is the letter ב producing
* בעומר, but it can be set to ל to produce
* לעומר (or any other prefix)
* @param hebrewOmerPrefix
* the hebrewOmerPrefix to set. You can use the Unicode \u05DC to set it to ל.
* @see #hebrewOmerPrefix
* @see #getHebrewOmerPrefix()
* @see #formatOmer(JewishCalendar)
*/
public void setHebrewOmerPrefix(String hebrewOmerPrefix) {
this.hebrewOmerPrefix = hebrewOmerPrefix;
}
/**
* Returns the array of months transliterated into Latin chars. The default list of months uses Ashkenazi
* pronunciation in typical American English spelling. This list has a length of 14 with 3 variations for Adar -
* "Adar", "Adar II", "Adar I"
*
* @return the array of months beginning in Nissan and ending in "Adar", "Adar II", "Adar I". The default list is
* currently ["Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Marcheshvan", "Kislev", "Teves",
* "Shevat", "Adar", "Adar II", "Adar I"].
* @see #setTransliteratedMonthList(String[])
*/
public String[] getTransliteratedMonthList() {
return transliteratedMonths;
}
/**
* Setter method to allow overriding of the default list of months transliterated into Latin chars. The default
* uses Ashkenazi American English transliteration.
*
* @param transliteratedMonths
* an array of 14 month names that defaults to ["Nissan", "Iyar", "Sivan", "Tamuz", "Av", "Elul", "Tishrei",
* "Marheshvan", "Kislev", "Tevet", "Shevat", "Adar", "Adar II", "Adar I"].
* @see #getTransliteratedMonthList()
*/
public void setTransliteratedMonthList(String[] transliteratedMonths) {
this.transliteratedMonths = transliteratedMonths;
}
/**
* Unicode list of Hebrew months in the following format <code>["\u05E0\u05D9\u05E1\u05DF","\u05D0\u05D9\u05D9\u05E8",
* "\u05E1\u05D9\u05D5\u05DF","\u05EA\u05DE\u05D5\u05D6","\u05D0\u05D1","\u05D0\u05DC\u05D5\u05DC",
* "\u05EA\u05E9\u05E8\u05D9","\u05DE\u05E8\u05D7\u05E9\u05D5\u05DF","\u05DB\u05E1\u05DC\u05D5","\u05D8\u05D1\u05EA",
* "\u05E9\u05D1\u05D8","\u05D0\u05D3\u05E8","\u05D0\u05D3\u05E8 \u05D1","\u05D0\u05D3\u05E8 \u05D0"]</code>
*
* @see #formatMonth(JewishDate)
*/
private static final String[] hebrewMonths = { "\u05E0\u05D9\u05E1\u05DF", "\u05D0\u05D9\u05D9\u05E8",
"\u05E1\u05D9\u05D5\u05DF", "\u05EA\u05DE\u05D5\u05D6", "\u05D0\u05D1", "\u05D0\u05DC\u05D5\u05DC",
"\u05EA\u05E9\u05E8\u05D9", "\u05DE\u05E8\u05D7\u05E9\u05D5\u05DF", "\u05DB\u05E1\u05DC\u05D5",
"\u05D8\u05D1\u05EA", "\u05E9\u05D1\u05D8", "\u05D0\u05D3\u05E8", "\u05D0\u05D3\u05E8 \u05D1",
"\u05D0\u05D3\u05E8 \u05D0" };
/**
* Unicode list of Hebrew days of week in the format of <code>["ראשון",
* "שני","שלישי","רביעי",
* "חמישי","ששי","שבת"]</code>
*/
private static final String[] hebrewDaysOfWeek = { "\u05E8\u05D0\u05E9\u05D5\u05DF", "\u05E9\u05E0\u05D9",
"\u05E9\u05DC\u05D9\u05E9\u05D9", "\u05E8\u05D1\u05D9\u05E2\u05D9", "\u05D7\u05DE\u05D9\u05E9\u05D9",
"\u05E9\u05E9\u05D9", "\u05E9\u05D1\u05EA" };
/**
* Formats the day of week. If {@link #isHebrewFormat() Hebrew formatting} is set, it will display in the format
* ראשון etc. If Hebrew formatting is not in use it will return it in the format
* of Sunday etc. There are various formatting options that will affect the output.
*
* @param jewishDate the JewishDate Object
* @return the formatted day of week
* @see #isHebrewFormat()
* @see #isLongWeekFormat()
*/
public String formatDayOfWeek(JewishDate jewishDate) {
if (hebrewFormat) {
if (isLongWeekFormat()) {
return hebrewDaysOfWeek[jewishDate.getDayOfWeek() - 1];
} else {
if (jewishDate.getDayOfWeek() == 7) {
return formatHebrewNumber(300);
} else {
return formatHebrewNumber(jewishDate.getDayOfWeek());
}
}
} else {
if (jewishDate.getDayOfWeek() == 7) {
if (isLongWeekFormat()) {
return getTransliteratedShabbosDayOfWeek();
} else {
return getTransliteratedShabbosDayOfWeek().substring(0,3);
}
} else {
return weekFormat.format(jewishDate.getGregorianCalendar().getTime());
}
}
}
/**
* Returns whether the class is set to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and
* numbers. When true and output would look like כ״א שבט תש״כ
* (or כ״א שבט תש״ך). When set to false, this output
* would display as כא שבט תשכ.
*
* @return true if set to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers.
*/
public boolean isUseGershGershayim() {
return useGershGershayim;
}
/**
* Sets whether to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers. The default
* value is true and output would look like כ״א שבט תש״כ
* (or כ״א שבט תש״ך). When set to false, this output would
* display as כא שבט תשכ (or
* כא שבט תשך). Single digit days or month or years such as כ׳
* שבט ו׳ אלפים show the use of the Geresh.
*
* @param useGershGershayim
* set this to false to omit the Geresh ׳ and Gershayim ״ in formatting
*/
public void setUseGershGershayim(boolean useGershGershayim) {
this.useGershGershayim = useGershGershayim;
}
/**
* Returns whether the class is set to use the מנצפ״ך letters when
* formatting years ending in 20, 40, 50, 80 and 90 to produce תש״פ if false or
* תש״ף if true. Traditionally non-final form letters are used, so the year
* 5780 would be formatted as תש״פ if the default false is used here. If this returns
* true, the format תש״ף would be used.
*
* @return true if set to use final form letters when formatting Hebrew years. The default value is false.
*/
public boolean isUseFinalFormLetters() {
return useFinalFormLetters;
}
/**
* When formatting a Hebrew Year, traditionally years ending in 20, 40, 50, 80 and 90 are formatted using non-final
* form letters for example תש״פ for the year 5780. Setting this to true (the default
* is false) will use the final form letters for מנצפ״ך and will format
* the year 5780 as תש״ף.
*
* @param useFinalFormLetters
* Set this to true to use final form letters when formatting Hebrew years.
*/
public void setUseFinalFormLetters(boolean useFinalFormLetters) {
this.useFinalFormLetters = useFinalFormLetters;
}
/**
* Returns whether the class is set to use the thousands digit when formatting. When formatting a Hebrew Year,
* traditionally the thousands digit is omitted and output for a year such as 5729 (1969 Gregorian) would be
* calculated for 729 and format as תשכ״ט. When set to true the long format year such
* as ה׳ תשכ״ט for 5729/1969 is returned.
*
* @return true if set to use the thousands digit when formatting Hebrew dates and numbers.
*/
public boolean isUseLongHebrewYears() {
return useLonghebrewYears;
}
/**
* When formatting a Hebrew Year, traditionally the thousands digit is omitted and output for a year such as 5729
* (1969 Gregorian) would be calculated for 729 and format as תשכ״ט. This method
* allows setting this to true to return the long format year such as ה׳
* תשכ״ט for 5729/1969.
*
* @param useLongHebrewYears
* Set this to true to use the long formatting
*/
public void setUseLongHebrewYears(boolean useLongHebrewYears) {
this.useLonghebrewYears = useLongHebrewYears;
}
/**
* Formats the Jewish date. If the formatter is set to Hebrew, it will format in the form, "day Month year" for
* example כ״א שבט תשכ״ט, and the format
* "21 Shevat, 5729" if not.
*
* @param jewishDate
* the JewishDate to be formatted
* @return the formatted date. If the formatter is set to Hebrew, it will format in the form, "day Month year" for
* example כ״א שבט תשכ״ט, and the format
* "21 Shevat, 5729" if not.
*/
public String format(JewishDate jewishDate) {
if (isHebrewFormat()) {
return formatHebrewNumber(jewishDate.getJewishDayOfMonth()) + " " + formatMonth(jewishDate) + " "
+ formatHebrewNumber(jewishDate.getJewishYear());
} else {
return jewishDate.getJewishDayOfMonth() + " " + formatMonth(jewishDate) + ", " + jewishDate.getJewishYear();
}
}
/**
* Returns a string of the current Hebrew month such as "Tishrei". Returns a string of the current Hebrew month such
* as "אדר ב׳".
*
* @param jewishDate
* the JewishDate to format
* @return the formatted month name
* @see #isHebrewFormat()
* @see #setHebrewFormat(boolean)
* @see #getTransliteratedMonthList()
* @see #setTransliteratedMonthList(String[])
*/
public String formatMonth(JewishDate jewishDate) {
final int month = jewishDate.getJewishMonth();
if (isHebrewFormat()) {
if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR) {
return hebrewMonths[13] + (useGershGershayim ? GERESH : ""); // return Adar I, not Adar in a leap year
} else if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR_II) {
return hebrewMonths[12] + (useGershGershayim ? GERESH : "");
} else {
return hebrewMonths[month - 1];
}
} else {
if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR) {
return transliteratedMonths[13]; // return Adar I, not Adar in a leap year
} else {
return transliteratedMonths[month - 1];
}
}
}
/**
* Returns a String of the Omer day in the form ל״ג בעומר if
* Hebrew Format is set, or "Omer X" or "Lag B'Omer" if not. An empty string if there is no Omer this day.
*
* @param jewishCalendar
* the JewishCalendar to be formatted
*
* @return a String of the Omer day in the form or an empty string if there is no Omer this day. The default
* formatting has a ב׳ prefix that would output בעומר, but this
* can be set via the {@link #setHebrewOmerPrefix(String)} method to use a ל and output
* ל״ג לעומר.
* @see #isHebrewFormat()
* @see #getHebrewOmerPrefix()
* @see #setHebrewOmerPrefix(String)
*/
public String formatOmer(JewishCalendar jewishCalendar) {
int omer = jewishCalendar.getDayOfOmer();
if (omer == -1) {
return "";
}
if (hebrewFormat) {
return formatHebrewNumber(omer) + " " + hebrewOmerPrefix + "\u05E2\u05D5\u05DE\u05E8";
} else {
if (omer == 33) { // if Lag B'Omer
return transliteratedHolidays[33];
} else {
return "Omer " + omer;
}
}
}
/**
* Formats a molad.
* @todo Experimental and incomplete.
*
* @param moladChalakim the chalakim of the molad
* @return the formatted molad. FIXME: define proper format in English and Hebrew.
*/
private static String formatMolad(long moladChalakim) {
long adjustedChalakim = moladChalakim;
int MINUTE_CHALAKIM = 18;
int HOUR_CHALAKIM = 1080;
int DAY_CHALAKIM = 24 * HOUR_CHALAKIM;
long days = adjustedChalakim / DAY_CHALAKIM;
adjustedChalakim = adjustedChalakim - (days * DAY_CHALAKIM);
int hours = (int) ((adjustedChalakim / HOUR_CHALAKIM));
if (hours >= 6) {
days += 1;
}
adjustedChalakim = adjustedChalakim - (hours * (long) HOUR_CHALAKIM);
int minutes = (int) (adjustedChalakim / MINUTE_CHALAKIM);
adjustedChalakim = adjustedChalakim - minutes * (long) MINUTE_CHALAKIM;
return "Day: " + days % 7 + " hours: " + hours + ", minutes " + minutes + ", chalakim: " + adjustedChalakim;
}
/**
* Returns the kviah in the traditional 3 letter Hebrew format where the first letter represents the day of week of
* Rosh Hashana, the second letter represents the lengths of Marcheshvan and Kislev ({@link JewishDate#SHELAIMIM
* Shelaimim} , {@link JewishDate#KESIDRAN Kesidran} or {@link JewishDate#CHASERIM Chaserim}) and the 3rd letter
* represents the day of week of Pesach. For example 5729 (1969) would return בשה (Rosh Hashana on
* Monday, Shelaimim, and Pesach on Thursday), while 5771 (2011) would return השג (Rosh Hashana on
* Thursday, Shelaimim, and Pesach on Tuesday).
*
* @param jewishYear
* the Jewish year
* @return the Hebrew String such as בשה for 5729 (1969) and השג for 5771
* (2011).
*/
public String getFormattedKviah(int jewishYear) {
JewishDate jewishDate = new JewishDate(jewishYear, JewishDate.TISHREI, 1); // set date to Rosh Hashana
int kviah = jewishDate.getMarcheshvanKislevKviah();
int roshHashanaDayOfWeek = jewishDate.getDayOfWeek();
String returnValue = formatHebrewNumber(roshHashanaDayOfWeek);
returnValue += (kviah == JewishDate.CHASERIM ? "\u05D7" : kviah == JewishDate.SHELAIMIM ? "\u05E9" : "\u05DB");
jewishDate.setJewishDate(jewishYear, JewishDate.NISSAN, 15); // set to Pesach of the given year
int pesachDayOfWeek = jewishDate.getDayOfWeek();
returnValue += formatHebrewNumber(pesachDayOfWeek);
returnValue = returnValue.replaceAll(GERESH, "");// geresh is never used in the kviah format
// boolean isLeapYear = JewishDate.isJewishLeapYear(jewishYear);
// for efficiency we can avoid the expensive recalculation of the pesach day of week by adding 1 day to Rosh
// Hashana for a 353-day year, 2 for a 354-day year, 3 for a 355 or 383-day year, 4 for a 384-day year and 5 for
// a 385-day year
return returnValue;
}
/**
* Formats the <a href="https://en.wikipedia.org/wiki/Daf_Yomi">Daf Yomi</a> Bavli in the format of
* "עירובין נ״ב" in {@link #isHebrewFormat() Hebrew},
* or the transliterated format of "Eruvin 52".
* @param daf the Daf to be formatted.
* @return the formatted daf.
*/
public String formatDafYomiBavli(Daf daf) {
if (hebrewFormat) {
return daf.getMasechta() + " " + formatHebrewNumber(daf.getDaf());
} else {
return daf.getMasechtaTransliterated() + " " + daf.getDaf();
}
}
/**
* Formats the <a href="https://en.wikipedia.org/wiki/Jerusalem_Talmud#Daf_Yomi_Yerushalmi">Daf Yomi Yerushalmi</a> in the format
* of "עירובין נ״ב" in {@link #isHebrewFormat() Hebrew}, or
* the transliterated format of "Eruvin 52".
*
* @param daf the Daf to be formatted.
* @return the formatted daf.
*/
public String formatDafYomiYerushalmi(Daf daf) {
if (daf == null) {
if (hebrewFormat) {
return Daf.getYerushalmiMasechtos()[39];
} else {
return Daf.getYerushalmiMasechtosTransliterated()[39];
}
}
if (hebrewFormat) {
return daf.getYerushalmiMasechta() + " " + formatHebrewNumber(daf.getDaf());
} else {
return daf.getYerushalmiMasechtaTransliterated() + " " + daf.getDaf();
}
}
/**
* Returns a Hebrew formatted string of a number. The method can calculate from 0 to 9999.
* <ul>
* <li>Single digit numbers such as 3, 30 and 100 will be returned with a ׳ (<a
* href="http://en.wikipedia.org/wiki/Geresh">Geresh</a>) appended as at the end. For example ג׳,
* ל׳ and ק׳</li>
* <li>multi digit numbers such as 21 and 769 will be returned with a ״ (<a
* href="http://en.wikipedia.org/wiki/Gershayim">Gershayim</a>) between the second to last and last letters. For
* example כ״א, תשכ״ט</li>
* <li>15 and 16 will be returned as ט״ו and ט״ז</li>
* <li>Single digit numbers (years assumed) such as 6000 (%1000=0) will be returned as ו׳
* אלפים</li>
* <li>0 will return אפס</li>
* </ul>
*
* @param number
* the number to be formatted. It will trow an IllegalArgumentException if the number is < 0 or > 9999.
* @return the Hebrew formatted number such as תשכ״ט
* @see #isUseFinalFormLetters()
* @see #isUseGershGershayim()
* @see #isHebrewFormat()
*
*/
public String formatHebrewNumber(int number) {
if (number < 0) {
throw new IllegalArgumentException("negative numbers can't be formatted");
} else if (number > 9999) {
throw new IllegalArgumentException("numbers > 9999 can't be formatted");
}
String ALAFIM = "\u05D0\u05DC\u05E4\u05D9\u05DD";
String EFES = "\u05D0\u05E4\u05E1";
String[] jHundreds = new String[] { "", "\u05E7", "\u05E8", "\u05E9", "\u05EA", "\u05EA\u05E7", "\u05EA\u05E8",
"\u05EA\u05E9", "\u05EA\u05EA", "\u05EA\u05EA\u05E7" };
String[] jTens = new String[] { "", "\u05D9", "\u05DB", "\u05DC", "\u05DE", "\u05E0", "\u05E1", "\u05E2",
"\u05E4", "\u05E6" };
String[] jTenEnds = new String[] { "", "\u05D9", "\u05DA", "\u05DC", "\u05DD", "\u05DF", "\u05E1", "\u05E2",
"\u05E3", "\u05E5" };
String[] tavTaz = new String[] { "\u05D8\u05D5", "\u05D8\u05D6" };
String[] jOnes = new String[] { "", "\u05D0", "\u05D1", "\u05D2", "\u05D3", "\u05D4", "\u05D5", "\u05D6",
"\u05D7", "\u05D8" };
if (number == 0) { // do we really need this? Should it be applicable to a date?
return EFES;
}
int shortNumber = number % 1000; // discard thousands
// next check for all possible single Hebrew digit years
boolean singleDigitNumber = (shortNumber < 11 || (shortNumber < 100 && shortNumber % 10 == 0) || (shortNumber <= 400 && shortNumber % 100 == 0));
int thousands = number / 1000; // get # thousands
StringBuilder sb = new StringBuilder();
// append thousands to String
if (number % 1000 == 0) { // in year is 5000, 4000 etc
sb.append(jOnes[thousands]);
if (isUseGershGershayim()) {
sb.append(GERESH);
}
sb.append(" ");
sb.append(ALAFIM); // add # of thousands plus the word "thousand" (override alafim boolean)
return sb.toString();
} else if (useLonghebrewYears && number >= 1000) { // if alafim boolean display thousands
sb.append(jOnes[thousands]);
if (isUseGershGershayim()) {
sb.append(GERESH); // append thousands quote
}
sb.append(" ");
}
number = number % 1000; // remove 1000s
int hundreds = number / 100; // # of hundreds
sb.append(jHundreds[hundreds]); // add hundreds to String
number = number % 100; // remove 100s
if (number == 15) { // special case 15
sb.append(tavTaz[0]);
} else if (number == 16) { // special case 16
sb.append(tavTaz[1]);
} else {
int tens = number / 10;
if (number % 10 == 0) { // if evenly divisible by 10
if (!singleDigitNumber) {
if (isUseFinalFormLetters()) {
sb.append(jTenEnds[tens]); // years like 5780 will end with a final form ף
} else {
sb.append(jTens[tens]); // years like 5780 will end with a regular פ
}
} else {
sb.append(jTens[tens]); // standard letters so years like 5050 will end with a regular nun
}