Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see issue #851
- Loading branch information
Showing
7 changed files
with
350 additions
and
24 deletions.
There are no files selected for viewing
191 changes: 191 additions & 0 deletions
191
base/src/main/java/net/time4j/calendar/hindu/HinduEra.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* ----------------------------------------------------------------------- | ||
* Copyright © 2013-2019 Meno Hochschild, <http://www.menodata.de/> | ||
* ----------------------------------------------------------------------- | ||
* This file (HinduEra.java) is part of project Time4J. | ||
* | ||
* Time4J 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. | ||
* | ||
* Time4J 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 Time4J. If not, see <http://www.gnu.org/licenses/>. | ||
* ----------------------------------------------------------------------- | ||
*/ | ||
|
||
package net.time4j.calendar.hindu; | ||
|
||
import net.time4j.engine.CalendarEra; | ||
import net.time4j.format.CalendarText; | ||
import net.time4j.format.TextWidth; | ||
|
||
import java.util.Locale; | ||
|
||
|
||
/** | ||
* <p>The Hindu calendar supports several eras in different regions of Indian subcontinent. </p> | ||
* | ||
* @author Meno Hochschild | ||
* @since 5.5 | ||
*/ | ||
/*[deutsch] | ||
* <p>Der Hindu-Kalender unterstützt mehrere Äras in verschiedenen Regionen des | ||
* indischen Subkontinents. </p> | ||
* | ||
* @author Meno Hochschild | ||
* @since 5.5 | ||
*/ | ||
public enum HinduEra | ||
implements CalendarEra { | ||
|
||
//~ Statische Felder/Initialisierungen -------------------------------- | ||
|
||
/** | ||
* The onset of this ancient era (iron age) is 3179 years before Saka. | ||
*/ | ||
/*[deutsch] | ||
* Der Beginn dieser historischen Ära (eisernes Zeitalter) liegt 3179 Jahre vor Saka. | ||
*/ | ||
KALI_YUGA, | ||
|
||
/** | ||
* The onset of this era mainly used in Northern India is 135 years before Saka. | ||
*/ | ||
/*[deutsch] | ||
* Der Beginn dieser vorwiegend in Nordindien verwendeten Ära liegt 135 Jahre vor Saka. | ||
*/ | ||
VIKRAMA, | ||
|
||
/** | ||
* The onset of this era is in gregorian year +78. | ||
*/ | ||
/*[deutsch] | ||
* Der Beginn dieser Ära liegt im gregorianischen Jahr +78. | ||
*/ | ||
SAKA, | ||
|
||
/** | ||
* The onset of this era mainly used in West Bengal is 515 years after Saka. | ||
*/ | ||
/*[deutsch] | ||
* Der Beginn dieser vorwiegend in Westbengalen verwendeten Ära liegt 515 Jahre nach Saka. | ||
*/ | ||
BENGAL, | ||
|
||
/** | ||
* The onset of this era mainly used in Kerala (part of Malayalam calendar) is 900 years before Saka. | ||
*/ | ||
/*[deutsch] | ||
* Der Beginn dieser vorwiegend in Kerala verwendeten Ära (Bestandteil des Malayalam-Kalenders) | ||
* liegt 900 Jahre vor Saka. | ||
*/ | ||
KOLLAM, | ||
|
||
/** | ||
* The onset of this era mainly used in Nepal is 955 years before Saka. | ||
*/ | ||
/*[deutsch] | ||
* Der Beginn dieser vorwiegend in Nepal verwendeten Ära liegt 955 Jahre vor Saka. | ||
*/ | ||
NEPALESE; | ||
|
||
private static final int[] SAKA_OFFSETS = {3179, 135, 0, -515, 900, 955}; | ||
|
||
//~ Methoden ---------------------------------------------------------- | ||
|
||
/** | ||
* <p>Equivalent to the expression {@code getDisplayName(locale, TextWidth.WIDE)}. </p> | ||
* | ||
* @param locale language setting | ||
* @return descriptive text (long form, never {@code null}) | ||
* @see #getDisplayName(Locale, TextWidth) | ||
* @since 5.5 | ||
*/ | ||
/*[deutsch] | ||
* <p>Entspricht dem Ausdruck {@code getDisplayName(locale, TextWidth.WIDE)}. </p> | ||
* | ||
* @param locale language setting | ||
* @return descriptive text (long form, never {@code null}) | ||
* @see #getDisplayName(Locale, TextWidth) | ||
* @since 5.5 | ||
*/ | ||
public String getDisplayName(Locale locale) { | ||
|
||
return this.getDisplayName(locale, TextWidth.WIDE); | ||
|
||
} | ||
|
||
/** | ||
* <p>Gets the description text dependent on the locale and style parameters. </p> | ||
* | ||
* <p>The second argument controls the width of description. </p> | ||
* | ||
* @param locale language setting | ||
* @param width text width | ||
* @return descriptive text for given locale and style (never {@code null}) | ||
* @since 5.5 | ||
*/ | ||
/*[deutsch] | ||
* <p>Liefert den sprachabhängigen Beschreibungstext. </p> | ||
* | ||
* <p>Über das zweite Argument kann gesteuert werden, ob eine kurze | ||
* oder eine lange Form des Beschreibungstexts ausgegeben werden soll. Das | ||
* ist besonders sinnvoll in Benutzeroberflächen, wo zwischen der | ||
* Beschriftung und der detaillierten Erläuterung einer graphischen | ||
* Komponente unterschieden wird. </p> | ||
* | ||
* @param locale language setting | ||
* @param width text width | ||
* @return descriptive text for given locale and style (never {@code null}) | ||
* @since 5.5 | ||
*/ | ||
public String getDisplayName( | ||
Locale locale, | ||
TextWidth width | ||
) { | ||
|
||
CalendarText names = CalendarText.getInstance("extra/hindu", locale); | ||
return names.getEras(width).print(this); | ||
|
||
} | ||
|
||
/** | ||
* <p>Scales given year of era to another year related to this era. </p> | ||
* | ||
* @param era era reference of given year | ||
* @param yearOfEra current year reckoned in given era | ||
* @return current year related to this era | ||
* @throws IllegalArgumentException if given year of era is out of range | ||
* @since 5.5 | ||
*/ | ||
/*[deutsch] | ||
* <p>Skaliert das angegebene Jahr der Ära zu einem anderen Jahreswert bezogen auf diese Ära. </p> | ||
* | ||
* @param era era reference of given year | ||
* @param yearOfEra current year reckoned in given era | ||
* @return current year related to this era | ||
* @throws IllegalArgumentException if given year of era is out of range | ||
* @since 5.5 | ||
*/ | ||
public int yearOfEra( | ||
HinduEra era, | ||
int yearOfEra | ||
) { | ||
|
||
try { | ||
return Math.subtractExact( | ||
Math.addExact(yearOfEra, SAKA_OFFSETS[this.ordinal()]), | ||
SAKA_OFFSETS[era.ordinal()]); | ||
} catch (ArithmeticException ex) { | ||
throw new IllegalArgumentException("Out of range: " + yearOfEra); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ------------------------------------------------------------------------- | ||
# Legend: | ||
# | ||
# Short keys: M=MONTH_OF_YEAR, E=ERA | ||
# Format mode: w=WIDE, a=ABBREVIATED, s=SHORT, n=NARROW | ||
# ------------------------------------------------------------------------- | ||
|
||
# supported list of languages | ||
languages= | ||
|
||
# property key format (first letter only if true - relevant for: M, E) | ||
useShortKeys=true | ||
|
||
# eras | ||
E(w)_0=Kali Yuga | ||
E(w)_1=Vikrama Samvat | ||
E(w)_2=Saka | ||
E(w)_3=Bengali Sambat | ||
E(w)_4=Kollam Era | ||
E(w)_5=Nepalese Era | ||
|
||
E(a)_0=K.Y | ||
E(a)_1=V.S. | ||
E(a)_2=Saka | ||
E(a)_3=B.S. | ||
E(a)_4=K.E. | ||
E(a)_5=N.E. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.