001    /*
002     * Zmanim Java API
003     * Copyright (C) 2011 Eliyahu Hershfeld
004     * Copyright (C) September 2002 Avrom Finkelstien 
005     *
006     * This program is free software; you can redistribute it and/or modify it under the terms of the
007     * GNU General Public License as published by the Free Software Foundation; either version 2 of the
008     * License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
011     * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012     * General Public License for more details.
013     *
014     * You should have received a copy of the GNU General Public License along with this program; if
015     * not, write to the Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA
016     * 02111-1307, USA or connect to: http://www.fsf.org/copyleft/gpl.html
017     */
018    package net.sourceforge.zmanim.hebrewcalendar;
019    
020    /**
021     * The HebrewDateFormatter class formats a {@link JewishDate}.
022     * 
023     * This class is part of a refactoring of <a
024     * href="http://www.facebook.com/avromf">Avrom Finkelstien's</a> HebrewDate
025     * class that removes formatting code from the core HebrewDate class.
026     * TODO: add additional formatting options including Hebrew formatting support.
027     * 
028     * @see java.util.Date
029     * @see java.util.Calendar
030     * @author &copy; Avrom Finkelstien 2002
031     * @author &copy; Eliyahu Hershfeld 2011
032     * @version 0.1
033     */
034    public class HebrewDateFormatter {
035            private static final String[] hebrewMonths = { "Nissan", "Iyar", "Sivan",
036                            "Tamuz", "Av", "Elul", "Tishrei", "Cheshvan", "Kislev", "Teves",
037                            "Shevat", "Adar", "Adar II" };
038            
039            // parsha names in both Ashkenazi and Sephardi pronunciation
040            // Somewhat redundant (don't you think?)
041    //      private static final String[][] Prounouncewdparshios = { { "Bereshit", "Bereshis" },
042    //                      { "Noach", "Noach" }, { "Lech-Lecha", "Lech-Lecha" },
043    //                      { "Vayera", "Vayera" }, { "Chayei Sara", "Chayei Sara" },
044    //                      { "Toldot", "Toldos" }, { "Vayetzei", "Vayetzei" },
045    //                      { "Vayishlach", "Vayishlach" }, { "Vayeshev", "Vayeshev" },
046    //                      { "Miketz", "Miketz" }, { "Vayigash", "Vayigash" },
047    //                      { "Vayechi", "Vayechi" }, { "Shemot", "Shemos" },
048    //                      { "Vaera", "Vaera" }, { "Bo", "Bo" }, { "Beshalach", "Beshalach" },
049    //                      { "Yitro", "Yisro" }, { "Mishpatim", "Mishpatim" },
050    //                      { "Terumah", "Terumah" }, { "Tetzaveh", "Tetzaveh" },
051    //                      { "Ki Tisa", "Ki Sisa" }, { "Vayakhel", "Vayakhel" },
052    //                      { "Pekudei", "Pekudei" }, { "Vayikra", "Vayikra" },
053    //                      { "Tzav", "Tzav" }, { "Shmini", "Shmini" }, { "Tazria", "Sazria" },
054    //                      { "Metzora", "Metzora" }, { "Achrei Mot", "Achrei Mos" },
055    //                      { "Kedoshim", "Kedoshim" }, { "Emor", "Emor" },
056    //                      { "Behar", "Behar" }, { "Bechukotai", "Bechukosai" },
057    //                      { "Bamidbar", "Bamidbar" }, { "Nasso", "Nasso" },
058    //                      { "Beha'alotcha", "Beha'aloscha" }, { "Sh'lach", "Sh'lach" },
059    //                      { "Korach", "Korach" }, { "Chukat", "Chukas" },
060    //                      { "Balak", "Balak" }, { "Pinchas", "Pinchas" },
061    //                      { "Matot", "Matos" }, { "Masei", "Masei" },
062    //                      { "Devarim", "Devarim" }, { "Vaetchanan", "Vaeschanan" },
063    //                      { "Eikev", "Eikev" }, { "Re'eh", "Re'eh" },
064    //                      { "Shoftim", "Shoftim" }, { "Ki Teitzei", "Ki Seitzei" },
065    //                      { "Ki Tavo", "Ki Savo" }, { "Nitzavim", "Nitzavim" },
066    //                      { "Vayeilech", "Vayeilech" }, { "Ha'Azinu", "Ha'Azinu" },
067    //                      { "Vayakhel Pekudei", "Vayakhel Pekudei" },
068    //                      { "Tazria Metzora", "Sazria Metzora" },
069    //                      { "Achrei Mot Kedoshim", "Achrei Mos Kedoshim" },
070    //                      { "Behar Bechukotai", "Behar Bechukosai" },
071    //                      { "Chukat Balak", "Chukas Balak" },
072    //                      { "Matot Masei", "Matos Masei" },
073    //                      { "Nitzavim Vayeilech", "Nitzavim Vayeilech" } };
074    
075            /**
076             * Returns a string containing the Hebrew date in the form,
077             * "day Month, year" e.g. "21 Shevat, 5729"
078             */
079            public static String getHebrewDateAsString(JewishDate hd) {
080                    return hd.getJewishDayOfMonth() + " " + getHebrewMonthAsString(hd) + ", " + hd.getJewishYear();
081            }
082    
083            /**
084             * returns a string of the current Hebrew month such as "Tishrei".
085             */
086            public static String getHebrewMonthAsString(JewishDate hd) {
087                    // if it is a leap year and 12th month //
088                    if (JewishDate.isJewishLeapYear(hd.getJewishYear()) && hd.getJewishMonth() == 12) {
089                            return "Adar I";
090                    } else {
091                            return hebrewMonths[hd.getJewishMonth() - 1];
092                    }
093            }
094            
095            /**
096             * returns a String of the Omer day in the form "Omer X" or "Lag B'Omer" or
097             * an empty string if there is no Omer this day.
098             * FIXME - Is this method really required?
099             */
100            public static String getOmerAsString(JewishDate hd) {
101                    int omer = hd.getDayOfOmer();
102    
103                    // if not Omer day //
104                    if (omer == 0) {
105                            return "";
106    
107                    } else if (omer == 33) { // if lag b'omer
108                            return "Lag B'Omer";
109                    } else {
110                            return "Omer " + omer;
111                    }
112            }
113    }