Class IndianCalendar
- All Implemented Interfaces:
Serializable
,Comparable<IndianCalendar>
,CalendarDate
,ChronoDisplay
,Temporal<CalendarDate>
,LocalizedPatternSupport
Represents the national calendar of India.
Introduction
It is a reform calendar synchronized with the gregorian calendar and was introduced in year 1957 as an attempt to unify the various local calendars used in India. A special leap year rule was introduced as follows: First add to the year of Saka era the number 78, then determine if the sum is a gregorian leap year. See also Wikipedia. Note that the Indian national calendar is not widely used despite of its official status. Most Indian people prefer the gregorian calendar. The calendar day starts at midnight, like in gregorian calendar but in contrast to the old Hinduist tradition.
Following elements which are declared as constants are registered by this class
Furthermore, all elements defined in EpochDays
and CommonElements
are supported.
Example of usage
ChronoFormatter<IndianCalendar> formatter = ChronoFormatter.ofPattern( "EEE, d. MMMM yyyy", PatternType.CLDR_DATE, Locale.ENGLISH, IndianCalendar.axis()); PlainDate today = SystemClock.inLocalView().today(); IndianCalendar indianDate = today.transform(IndianCalendar.class); System.out.println(formatter.format(indianDate));
Support for unicode ca-extensions
Locale locale = Locale.forLanguageTag("en-u-ca-indian"); ChronoFormatter<CalendarDate> f = ChronoFormatter.ofGenericCalendarStyle(DisplayMode.FULL, locale); assertThat( f.format(PlainDate.of(2017, 10, 1)), is("Sunday, Asvina 9, 1939 Saka"));
- Since:
- 3.32/4.27
- Author:
- Meno Hochschild
- See Also:
IndianEra
,IndianMonth
,NumberSystem.BENGALI
,NumberSystem.DEVANAGARI
,NumberSystem.GUJARATI
,NumberSystem.TELUGU
, Serialized Form
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Defines some calendar units for the Indian calendar. -
Field Summary
Modifier and TypeFieldDescriptionstatic StdCalendarElement<Integer,IndianCalendar>
Represents the Indian day of month.static StdCalendarElement<Weekday,IndianCalendar>
Represents the Indian day of week.static StdCalendarElement<Integer,IndianCalendar>
Represents the Indian day of year.static ChronoElement<IndianEra>
Represents the Indian era.static StdCalendarElement<IndianMonth,IndianCalendar>
Represents the Indian month.static OrdinalWeekdayElement<IndianCalendar>
Element with the ordinal day-of-week within given calendar month.static StdCalendarElement<Integer,IndianCalendar>
Represents the Indian year. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new local timestamp with this date and given wall time.atTime(int hour, int minute)
Is equivalent toat(PlainTime.of(hour, minute))
.static TimeAxis<IndianCalendar.Unit,IndianCalendar>
axis()
Returns the associated time axis.boolean
Based on the epoch day number and the calendar system.int
Yields the Indian day of month.Determines the day of week.int
Yields the Indian day of year.static Weekmodel
Obtains the standard week model of this calendar.getEra()
Yields the Indian era.getMonth()
Yields the Indian month.int
getYear()
Yields the Indian year.int
hashCode()
Based on the epoch day number.boolean
Is the year of this date a leap year?static boolean
isValid(int yearOfEra, int month, int dayOfMonth)
Queries if given parameter values form a well defined calendar date.int
Yields the length of current Indian month in days.int
Yields the length of current Indian year in days.static IndianCalendar
Obtains the current calendar date in system time.static IndianCalendar
of(int iyear, int imonth, int idom)
Creates a new instance of an Indian calendar date.static IndianCalendar
of(int iyear, IndianMonth imonth, int idom)
Creates a new instance of an Indian calendar date.toString()
Provides a complete textual representation of the state of this time point.Methods inherited from class net.time4j.engine.Calendrical
compareTo, getDaysSinceEpochUTC, isAfter, isBefore, isSimultaneous, minus, plus
Methods inherited from class net.time4j.engine.TimePoint
max, min, minus, minus, plus, plus, until, until
Methods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with
Methods inherited from interface net.time4j.engine.CalendarDate
transform, transform, transform, transform, transform, transform
Methods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, getFormatPattern, useDynamicFormatPattern
Methods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual
-
Field Details
-
ERA
Represents the Indian era.
-
YEAR_OF_ERA
@FormattableElement(format="y") public static final StdCalendarElement<Integer,IndianCalendar> YEAR_OF_ERARepresents the Indian year.
-
MONTH_OF_YEAR
@FormattableElement(format="M", alt="L") public static final StdCalendarElement<IndianMonth,IndianCalendar> MONTH_OF_YEARRepresents the Indian month.
-
DAY_OF_MONTH
@FormattableElement(format="d") public static final StdCalendarElement<Integer,IndianCalendar> DAY_OF_MONTHRepresents the Indian day of month.
-
DAY_OF_YEAR
@FormattableElement(format="D") public static final StdCalendarElement<Integer,IndianCalendar> DAY_OF_YEARRepresents the Indian day of year.
-
DAY_OF_WEEK
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,IndianCalendar> DAY_OF_WEEKRepresents the Indian day of week.
If the day-of-week is set to a new value then Time4J handles the Indian calendar week as starting on Sunday.
-
WEEKDAY_IN_MONTH
@FormattableElement(format="F") public static final OrdinalWeekdayElement<IndianCalendar> WEEKDAY_IN_MONTHElement with the ordinal day-of-week within given calendar month.
-
-
Method Details
-
of
Creates a new instance of an Indian calendar date.
- Parameters:
iyear
- Indian year in the range 1-999999921imonth
- Indian monthidom
- Indian day of month in range 1-31- Returns:
- new instance of
IndianCalendar
- Throws:
IllegalArgumentException
- in case of any inconsistencies
-
of
Creates a new instance of an Indian calendar date.
- Parameters:
iyear
- Indian year in the range 1-999999921imonth
- Indian month in range 1-12idom
- Indian day of month in range 1-31- Returns:
- new instance of
IndianCalendar
- Throws:
IllegalArgumentException
- in case of any inconsistencies
-
nowInSystemTime
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(IndianCalendar.axis())
.- Returns:
- current calendar date in system time zone using the system clock
- See Also:
SystemClock.inLocalView()
,ZonalClock.now(Chronology)
-
getEra
Yields the Indian era.
- Returns:
IndianEra.SAKA
-
getYear
public int getYear()Yields the Indian year.
- Returns:
- int
-
getMonth
Yields the Indian month.
- Returns:
- enum
-
getDayOfMonth
public int getDayOfMonth()Yields the Indian day of month.
- Returns:
- int
-
getDayOfWeek
Determines the day of week.
The Indian calendar also uses a 7-day-week.
- Returns:
- Weekday
-
getDayOfYear
public int getDayOfYear()Yields the Indian day of year.
- Returns:
- int
-
lengthOfMonth
public int lengthOfMonth()Yields the length of current Indian month in days.
- Returns:
- int
-
lengthOfYear
public int lengthOfYear()Yields the length of current Indian year in days.
- Returns:
- int
-
isLeapYear
public boolean isLeapYear()Is the year of this date a leap year?
- Returns:
- boolean
-
isValid
public static boolean isValid(int yearOfEra, int month, int dayOfMonth)Queries if given parameter values form a well defined calendar date.
- Parameters:
yearOfEra
- the year of era to be checkedmonth
- the month to be checkeddayOfMonth
- the day of month to be checked- Returns:
true
if valid elsefalse
- Since:
- 3.34/4.29
- See Also:
of(int, int, int)
-
at
Creates a new local timestamp with this date and given wall 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
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
-
equals
Description copied from class:Calendrical
Based on the epoch day number and the calendar system.
In other words: Two date object are equal if they have the same temporal position on the local timeline and have the same calendrical type. Subclasses which define further state attributes must override this method.
If an only temporal comparison is required then the method
Calendrical.isSimultaneous(CalendarDate)
is to be used.- Overrides:
equals
in classCalendrical<IndianCalendar.Unit,IndianCalendar>
- See Also:
Chronology.getChronoType()
-
hashCode
public int hashCode()Description copied from class:Calendrical
Based on the epoch day number.
- Overrides:
hashCode
in classCalendrical<IndianCalendar.Unit,IndianCalendar>
-
toString
Description copied from class:TimePoint
Provides a complete textual representation of the state of this time point.
The textual description often follows the conventions of ISO-8601. Usually the description starts with the chronological informations which are coarse-grained and ends with those ones which are fine-grained (for example the ISO-notation YYYY-MM-DD).
- Specified by:
toString
in classTimePoint<IndianCalendar.Unit,IndianCalendar>
-
getDefaultWeekmodel
Obtains the standard week model of this calendar.
The Indian calendar usually starts on Sunday.
- Returns:
- Weekmodel
-
axis
Returns the associated time axis.
- Returns:
- chronology
-