@CalendarType(value="hindu") public final class HinduCalendar extends CalendarVariant<HinduCalendar> implements LocalizedPatternSupport
The traditional Hindu calendar which exists in many regional variants throughout the Indian subcontinent.
This version actually supports all algorithmic variants including the old Hindu calendar.
These variants are described in the book "Calendrical Calculations" by Dershowitz/Reingold. Real
Hindu calendars published on websites can nevertheless deviate in detail. Users who wish to support modern
Hindu calendars can start with the enum HinduRule in order to construct a suitable variant. For example,
it is possible to set the default era for all calendar objects by setting
the desired era on the variant. Users can also configure astronomic calculations to be applied instead of
the traditional ways to calculate Hindu calendar dates.
Following elements which are declared as constants are registered by this class:
Furthermore, all elements defined in EpochDays and CommonElements.RELATED_GREGORIAN_YEAR
are supported.
A date arithmetic using units beyond the class CalendarDays is not offered.
But there are methods like previousMonth() or nextYear(). About years, user can also use
expressions like with(YEAR_OF_ERA, getYear() + amount).
This calendar can deploy the same localized resources like the Indian national calendar. Example:
ChronoFormatter<HinduCalendar> f =
ChronoFormatter.ofPattern(
"G, d. MMMM yyyy",
PatternType.CLDR,
Locale.ENGLISH,
HinduCalendar.family());
HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 19);
assertThat(
f.print(cal),
is("K.Y, 19. Magha 3101"));
Possible leap months or leap days can be printed and parsed, too. If no special format attribute is specified and the text width to be used is wide then the localized word for "adhika" will be printed in front of leap months or days. Example for a short display using format attributes for handling leap indicators and the orientation of leap indicator:
ChronoFormatter<HinduCalendar> f =
ChronoFormatter.ofPattern("M yyyy, d", PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family())
.with(HinduPrimitive.ADHIKA_INDICATOR, '*')
.with(HinduPrimitive.ADHIKA_IS_TRAILING, true);
HinduCalendar cal =
HinduCalendar.of(
HinduRule.AMANTA.variant(),
HinduEra.VIKRAMA,
1549,
HinduMonth.of(IndianMonth.VAISHAKHA).withLeap(),
HinduDay.valueOf(3));
assertThat(
f.print(cal),
is("2* 1549, 3"));
Other number systems can be used in the usual way by obtaining a modified copy of the formatter
with an expression like f.with(Attributes.NUMBER_SYSTEM, NumberSystem.DEVANAGARI).
The Hindu calendar knows lost days and leap days. And the lunisolar variants also know lost months
(rare) and leap months. This is the main reason why days and months are not modelled as integers. So users cannot
rely on simple home grown integer arithmetic to look for example for the next valid day but must use the existing
element queries, element manipulations and expressions based on the available methods like nextDay() or
nextMonth(). Any date input in doubt should also be validated using
isValid(HinduVariant, HinduEra, int, HinduMonth, HinduDay) when creating a calendar date.
IndianCalendar,
HinduVariant,
HinduRule,
AryaSiddhanta,
NumberSystem,
HinduPrimitive.ADHIKA_INDICATOR,
HinduPrimitive.ADHIKA_IS_TRAILING,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static AdjustableTextElement<HinduDay> |
DAY_OF_MONTH
Represents the Hindu day of month.
|
static StdCalendarElement<Weekday,HinduCalendar> |
DAY_OF_WEEK
Represents the Hindu day of week.
|
static StdCalendarElement<Integer,HinduCalendar> |
DAY_OF_YEAR
Represents the Hindu day of year.
|
static ChronoElement<HinduEra> |
ERA
Represents the Hindu era.
|
static AdjustableTextElement<HinduMonth> |
MONTH_OF_YEAR
Represents the Hindu month.
|
static StdCalendarElement<Integer,HinduCalendar> |
YEAR_OF_ERA
Represents the Hindu year.
|
| Modifier and Type | Method and Description |
|---|---|
GeneralTimestamp<HinduCalendar> |
at(PlainTime time)
Creates a new local timestamp with this date and given civil time.
|
GeneralTimestamp<HinduCalendar> |
atTime(int hour,
int minute)
Is equivalent to
at(PlainTime.of(hour, minute)). |
boolean |
equals(Object obj)
Compares the whole state of this instance with given object.
|
static CalendarFamily<HinduCalendar> |
family()
Returns the associated calendar family.
|
HinduDay |
getDayOfMonth()
Obtains the day of month.
|
Weekday |
getDayOfWeek()
Determines the day of week.
|
int |
getDayOfYear()
Obtains the day of year.
|
long |
getDaysSinceEpochUTC()
Counts the elapsed days since UTC epoch.
|
HinduEra |
getEra()
Obtains the era from the current Hindu variant.
|
HinduMonth |
getMonth()
Obtains the month.
|
String |
getVariant()
Yields the variant name of a calendar system.
|
int |
getYear()
Obtains the year according to the current era and according to if the current Hindu variant
uses elapsed years or current years.
|
int |
hashCode()
Subclasses must redefine this method corresponding to the
behaviour of
equals(). |
static boolean |
isValid(HinduVariant variant,
HinduEra era,
int yearOfEra,
HinduMonth month,
HinduDay dayOfMonth)
Queries if given parameter values form a well defined Hindu date before instantiating the date.
|
int |
lengthOfMonth()
Yields the length of current Hindu month in days.
|
int |
lengthOfYear()
Yields the length of current Hindu year in days.
|
HinduCalendar |
nextDay()
Obtains the next day.
|
HinduCalendar |
nextMonth()
Obtains the corresponding date of next month.
|
HinduCalendar |
nextYear()
Obtains the corresponding date of next year.
|
static HinduCalendar |
nowInSystemTime(HinduVariant variant)
Obtains the current calendar date in system time.
|
static HinduCalendar |
nowInSystemTime(HinduVariant variant,
StartOfDay startOfDay)
Obtains the current calendar date in system time.
|
static HinduCalendar |
of(HinduVariant variant,
HinduEra era,
int yearOfEra,
HinduMonth month,
HinduDay dayOfMonth)
Creates an Hindu calendar with given components.
|
static HinduCalendar |
ofOldLunar(int year,
HinduMonth month,
int dayOfMonth)
Creates an old lunisolar Hindu calendar with given components.
|
static HinduCalendar |
ofOldSolar(int year,
int month,
int dayOfMonth)
Creates an old solar Hindu calendar with given components.
|
HinduCalendar |
previousDay()
Obtains the previous day.
|
HinduCalendar |
previousMonth()
Obtains the corresponding date of previous month.
|
HinduCalendar |
previousYear()
Obtains the corresponding date of previous year.
|
String |
toString()
Provides a complete textual representation of the state of this calendar variant.
|
compareTo, isAfter, isBefore, isSimultaneous, minus, plus, withVariant, withVariantcontains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, withgetFormatPattern, getFormatPattern, useDynamicFormatPatternfrom, from, from, transform, transform, transform, transform, transform, transformisAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual@FormattableElement(format="G") public static final ChronoElement<HinduEra> ERA
Represents the Hindu era.
A change of the era by with() will not change the Hindu date in a temporal way
but only the year representation. The changed era is stored in the variant of this calendar
object. Attention: The old Hindu calendar ignores any era change and only supports Kali Yuga.
@FormattableElement(format="y") public static final StdCalendarElement<Integer,HinduCalendar> YEAR_OF_ERA
Represents the Hindu year.
The range is for the era Kali Yuga defined by 0-5999 (elapsed year) resprective 1-6000
(current year) and will be adjusted accordingly for other eras. However, the modern Hindu calendar will
use the year 1200 as minimum elapsed year.
@FormattableElement(format="M") public static final AdjustableTextElement<HinduMonth> MONTH_OF_YEAR
Represents the Hindu month.
The first lunar month should always be determined by with(MONTH_OF_YEAR.minimized())
because the first month in lunisolar context might be in leap state.
@FormattableElement(format="d") public static final AdjustableTextElement<HinduDay> DAY_OF_MONTH
Represents the Hindu day of month.
The first day of lunar month should always be determined by with(DAY_OF_MONTH.minimized())
because the number of the first day of month in lunisolar context is not always 1. Similar thoughts
also for the last day of lunar month.
@FormattableElement(format="D") public static final StdCalendarElement<Integer,HinduCalendar> DAY_OF_YEAR
Represents the Hindu day of year.
New Year can be determined by with(DAY_OF_YEAR, 1) or with(DAY_OF_YEAR.minimized()).
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,HinduCalendar> DAY_OF_WEEK
Represents the Hindu day of week.
If the day-of-week is set to a new value then Time4J handles the Hindu calendar week as starting on Sunday.
public static HinduCalendar nowInSystemTime(HinduVariant variant)
Obtains the current calendar date in system time.
The time of sunrise in the holy city Ujjain is used as start of day.
variant - calendar variantnowInSystemTime(HinduVariant, StartOfDay)public static HinduCalendar nowInSystemTime(HinduVariant variant, StartOfDay startOfDay)
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(HinduCalendar.family(), variant, startOfDay).toDate()).
variant - calendar variantstartOfDay - determines the exact time of day when the calendar date will change (usually at sunrise)SystemClock.inLocalView(),
ZonalClock.now(CalendarFamily, VariantSource, StartOfDay)public static HinduCalendar ofOldSolar(int year, int month, int dayOfMonth)
Creates an old solar Hindu calendar with given components.
The months use rasi numbers and start with VAISAKHA.
year - expired year of era Kali Yugamonth - month number (rasi numbering in range 1-12)dayOfMonth - the day of given month in range 1-31IllegalArgumentException - in case of any inconsistenciesHinduMonth.getRasi(),
AryaSiddhantapublic static HinduCalendar ofOldLunar(int year, HinduMonth month, int dayOfMonth)
Creates an old lunisolar Hindu calendar with given components.
The month CHAITRA is the first month of year.
year - expired year of era Kali Yugamonth - the Hindu month (possibly as leap month)dayOfMonth - the day of given monthIllegalArgumentException - in case of any inconsistenciesAryaSiddhantapublic static HinduCalendar of(HinduVariant variant, HinduEra era, int yearOfEra, HinduMonth month, HinduDay dayOfMonth)
Creates an Hindu calendar with given components.
Note: The modern variants of Hindu calendar use the year 1200 as miminum elapsed year.
variant - the variant of Hindu calendarera - the desired erayearOfEra - the year of given era (expired or current according to variant configuration)month - the Hindu month (in lunisolar case possibly as leap month)dayOfMonth - the day of given month (in lunisolar case possibly in leap state)IllegalArgumentException - in case of any inconsistenciespublic static boolean isValid(HinduVariant variant, HinduEra era, int yearOfEra, HinduMonth month, HinduDay dayOfMonth)
Queries if given parameter values form a well defined Hindu date before instantiating the date.
Example for a non-existing day:
assertThat(
HinduCalendar.isValid(
AryaSiddhanta.LUNAR.variant(),
HinduEra.KALI_YUGA,
0,
HinduMonth.of(IndianMonth.CHAITRA).withLeap(),
HinduDay.valueOf(15)), // expunged day!
is(false));
variant - the variant of Hindu calendarera - the desired erayearOfEra - the year of given era (expired or current according to variant configuration)month - the Hindu month (in lunisolar case possibly as leap month)dayOfMonth - the day of given month (in lunisolar case possibly in leap state)true if valid else falseof(HinduVariant, HinduEra, int, HinduMonth, HinduDay),
HinduRule.variant(),
AryaSiddhanta.variant()public int lengthOfMonth()
Yields the length of current Hindu month in days.
Attention: This method obtains the real length while an expression like
getMaximum(DAY_OF_MONTH).getValue() only shows the number of last day of month
which can be different from the length of month - especially in a lunisolar context.
public int lengthOfYear()
Yields the length of current Hindu year in days.
public String getVariant()
VariantSourceYields the variant name of a calendar system.
getVariant in interface VariantSourcepublic HinduEra getEra()
Obtains the era from the current Hindu variant.
If the associated (elapsed) year becomes negative then the method will fall back to Kali Yuga era.
ERA,
HinduVariant.getDefaultEra()public int getYear()
Obtains the year according to the current era and according to if the current Hindu variant uses elapsed years or current years.
YEAR_OF_ERA,
getEra(),
HinduEra.yearOfEra(HinduEra, int),
HinduVariant.isUsingElapsedYears()public HinduMonth getMonth()
Obtains the month.
MONTH_OF_YEARpublic HinduDay getDayOfMonth()
Obtains the day of month.
DAY_OF_MONTH,
withFirstDayOfMonth()public Weekday getDayOfWeek()
Determines the day of week.
DAY_OF_WEEKpublic int getDayOfYear()
Obtains the day of year.
DAY_OF_YEAR,
withNewYear()public HinduCalendar previousDay()
Obtains the previous day.
IllegalArgumentException - if the adjusted date is out of rangepublic HinduCalendar previousMonth()
Obtains the corresponding date of previous month.
IllegalArgumentException - if the adjusted date is out of rangepublic HinduCalendar previousYear()
Obtains the corresponding date of previous year.
IllegalArgumentException - if the adjusted date is out of rangepublic HinduCalendar nextDay()
Obtains the next day.
IllegalArgumentException - if the adjusted date is out of rangepublic HinduCalendar nextMonth()
Obtains the corresponding date of next month.
IllegalArgumentException - if the adjusted date is out of rangepublic HinduCalendar nextYear()
Obtains the corresponding date of next year.
IllegalArgumentException - if the adjusted date is out of rangepublic GeneralTimestamp<HinduCalendar> at(PlainTime time)
Creates a new local timestamp with this date and given civil time.
If the time T24:00 is used
then the resulting timestamp will automatically be normalized such
that the timestamp will contain the following day instead.
time - wall timepublic GeneralTimestamp<HinduCalendar> atTime(int hour, int minute)
Is equivalent to at(PlainTime.of(hour, minute)).
hour - hour of day in range (0-24)minute - minute of hour in range (0-59)IllegalArgumentException - if any argument is out of rangeat(PlainTime)public boolean equals(Object obj)
CalendarVariantCompares the whole state of this instance with given object.
Implementations will usually define their state based on the temporal position and the variant name. Exceptions from this rule should be explicitly documented and reasoned.
equals in class CalendarVariant<HinduCalendar>CalendarVariant.compareTo(CalendarVariant)public int hashCode()
CalendarVariantSubclasses must redefine this method corresponding to the
behaviour of equals().
hashCode in class CalendarVariant<HinduCalendar>public String toString()
CalendarVariantProvides a complete textual representation of the state of this calendar variant.
toString in class CalendarVariant<HinduCalendar>public long getDaysSinceEpochUTC()
CalendarDateCounts the elapsed days since UTC epoch.
getDaysSinceEpochUTC in interface CalendarDategetDaysSinceEpochUTC in class CalendarVariant<HinduCalendar>EpochDays.UTCpublic static CalendarFamily<HinduCalendar> family()
Returns the associated calendar family.
Copyright © 2014–2021. All rights reserved.