Class HinduCalendar

All Implemented Interfaces:
Serializable, Comparable<HinduCalendar>, CalendarDate, ChronoDisplay, Temporal<CalendarDate>, VariantSource, LocalizedPatternSupport

@CalendarType("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.

Supported elements

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.

Calendar arithmetic and time units

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).

Formatting and parsing

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).

Oddities

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.

Since:
5.7
Author:
Meno Hochschild
See Also:
IndianCalendar, HinduVariant, HinduRule, AryaSiddhanta, NumberSystem, HinduPrimitive.ADHIKA_INDICATOR, HinduPrimitive.ADHIKA_IS_TRAILING, Serialized Form
  • Field Details

  • Method Details

    • nowInSystemTime

      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.

      Parameters:
      variant - calendar variant
      Returns:
      current calendar date in system time zone using the system clock
      See Also:
      nowInSystemTime(HinduVariant, StartOfDay)
    • nowInSystemTime

      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()).

      Parameters:
      variant - calendar variant
      startOfDay - determines the exact time of day when the calendar date will change (usually at sunrise)
      Returns:
      current calendar date in system time zone using the system clock
      See Also:
      SystemClock.inLocalView(), ZonalClock.now(CalendarFamily, VariantSource, StartOfDay)
    • ofOldSolar

      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.

      Parameters:
      year - expired year of era Kali Yuga
      month - month number (rasi numbering in range 1-12)
      dayOfMonth - the day of given month in range 1-31
      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - in case of any inconsistencies
      See Also:
      HinduMonth.getRasi(), AryaSiddhanta
    • ofOldLunar

      public 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.

      Parameters:
      year - expired year of era Kali Yuga
      month - the Hindu month (possibly as leap month)
      dayOfMonth - the day of given month
      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - in case of any inconsistencies
      See Also:
      AryaSiddhanta
    • of

      public 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.

      Parameters:
      variant - the variant of Hindu calendar
      era - the desired era
      yearOfEra - 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)
      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - in case of any inconsistencies
    • isValid

      public 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));
       
      Parameters:
      variant - the variant of Hindu calendar
      era - the desired era
      yearOfEra - 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)
      Returns:
      true if valid else false
      See Also:
      of(HinduVariant, HinduEra, int, HinduMonth, HinduDay), HinduRule.variant(), AryaSiddhanta.variant()
    • lengthOfMonth

      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.

      Returns:
      int
    • lengthOfYear

      public int lengthOfYear()

      Yields the length of current Hindu year in days.

      Returns:
      int
    • getVariant

      public String getVariant()
      Description copied from interface: VariantSource

      Yields the variant name of a calendar system.

      Specified by:
      getVariant in interface VariantSource
      Returns:
      String which is empty if there are no variants
    • getEra

      public 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.

      Returns:
      HinduEra
      See Also:
      ERA, HinduVariant.getDefaultEra()
    • getYear

      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.

      Returns:
      int
      See Also:
      YEAR_OF_ERA, getEra(), HinduEra.yearOfEra(HinduEra, int), HinduVariant.isUsingElapsedYears()
    • getMonth

      public HinduMonth getMonth()

      Obtains the month.

      Returns:
      HinduMonth
      See Also:
      MONTH_OF_YEAR
    • getDayOfMonth

      public HinduDay getDayOfMonth()

      Obtains the day of month.

      Returns:
      HinduDay
      See Also:
      DAY_OF_MONTH, withFirstDayOfMonth()
    • getDayOfWeek

      public Weekday getDayOfWeek()

      Determines the day of week.

      Returns:
      Weekday
      See Also:
      DAY_OF_WEEK
    • getDayOfYear

      public int getDayOfYear()

      Obtains the day of year.

      Returns:
      int
      See Also:
      DAY_OF_YEAR, withNewYear()
    • previousDay

      public HinduCalendar previousDay()

      Obtains the previous day.

      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - if the adjusted date is out of range
    • previousMonth

      public HinduCalendar previousMonth()

      Obtains the corresponding date of previous month.

      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - if the adjusted date is out of range
    • previousYear

      public HinduCalendar previousYear()

      Obtains the corresponding date of previous year.

      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - if the adjusted date is out of range
    • nextDay

      public HinduCalendar nextDay()

      Obtains the next day.

      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - if the adjusted date is out of range
    • nextMonth

      public HinduCalendar nextMonth()

      Obtains the corresponding date of next month.

      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - if the adjusted date is out of range
    • nextYear

      public HinduCalendar nextYear()

      Obtains the corresponding date of next year.

      Returns:
      HinduCalendar
      Throws:
      IllegalArgumentException - if the adjusted date is out of range
    • at

      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.

      Parameters:
      time - wall time
      Returns:
      general timestamp as composition of this date and given time
    • atTime

      public GeneralTimestamp<HinduCalendar> atTime(int hour, int minute)

      Is equivalent to at(PlainTime.of(hour, minute)).

      Parameters:
      hour - hour of day in range (0-24)
      minute - minute of hour in range (0-59)
      Returns:
      general timestamp as composition of this date and given time
      Throws:
      IllegalArgumentException - if any argument is out of range
      See Also:
      at(PlainTime)
    • equals

      public boolean equals(Object obj)
      Description copied from class: CalendarVariant

      Compares 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.

      Specified by:
      equals in class CalendarVariant<HinduCalendar>
      See Also:
      CalendarVariant.compareTo(CalendarVariant)
    • hashCode

      public int hashCode()
      Description copied from class: CalendarVariant

      Subclasses must redefine this method corresponding to the behaviour of equals().

      Specified by:
      hashCode in class CalendarVariant<HinduCalendar>
    • toString

      public String toString()
      Description copied from class: CalendarVariant

      Provides a complete textual representation of the state of this calendar variant.

      Specified by:
      toString in class CalendarVariant<HinduCalendar>
    • getDaysSinceEpochUTC

      public long getDaysSinceEpochUTC()
      Description copied from interface: CalendarDate

      Counts the elapsed days since UTC epoch.

      Specified by:
      getDaysSinceEpochUTC in interface CalendarDate
      Overrides:
      getDaysSinceEpochUTC in class CalendarVariant<HinduCalendar>
      Returns:
      count of days relative to UTC epoch [1972-01-01]
      See Also:
      EpochDays.UTC
    • family

      public static CalendarFamily<HinduCalendar> family()

      Returns the associated calendar family.

      Returns:
      chronology as calendar family