Class ThaiSolarCalendar
- All Implemented Interfaces:
Serializable
,Comparable<ThaiSolarCalendar>
,CalendarDate
,ChronoDisplay
,Temporal<CalendarDate>
,LocalizedPatternSupport
The Thai solar calendar calendar used in Thailand uses as only difference to western gregorian calendar a different year numbering with the Buddhist era mainly.
Following elements which are declared as constants are registered by this class
Furthermore, all elements defined in EpochDays
and CommonElements
are supported.
Anomaly in year 1940
This class supports the calendar reform of 1940/41 after that the begin of year moved from 1st of April to 1st of January. See also: Wikipedia.
The date arithmetic uses the ISO-compatible class CalendarUnit
and always delegate to
the ISO-equivalent PlainDate
due to the fact that this calendar has always been a derivate
of the western gregorian calendar (years are intended as approximate solar years). However, if
applied on dates around the year 1940 where the begin of year was moved from 1st of April to 1st of
January users might observe some changes of buddhist year numbering which appear strange on first
glance. Example: ThaiSolarCalendar.ofBuddhist(2482, FEBRUARY, 1).plus(2, CalendarUnit.YEARS)
results in ThaiSolarCalendar.ofBuddhist(2485, FEBRUARY, 1)
. The addition of two (solar) years
corresponds to the addition of apparently three buddhist years in this edge case. If translated to
its ISO-equivalent the reason is clear: [1940-02-01] + 2 years = [1942-02-01].
Support for unicode ca-extensions
Locale locale = Locale.forLanguageTag("en-u-ca-buddhist"); ChronoFormatter<CalendarDate> f = ChronoFormatter.ofGenericCalendarStyle(DisplayMode.FULL, locale); assertThat( f.format(PlainDate.of(2017, 10, 1)), is("Sunday, October 1, 2560 BE"));
- Since:
- 3.19/4.15
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptionstatic StdCalendarElement<Integer,ThaiSolarCalendar>
Represents the day of month.static StdCalendarElement<Weekday,ThaiSolarCalendar>
Represents the day of week.static StdCalendarElement<Integer,ThaiSolarCalendar>
Represents the day of year.static ChronoElement<ThaiSolarEra>
Represents the Thai era.static StdCalendarElement<Month,ThaiSolarCalendar>
Represents the month.Element with the ordinal day-of-week within given calendar month.static StdCalendarElement<Integer,ThaiSolarCalendar>
Represents the Thai year, usually in buddhist counting. -
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<CalendarUnit,ThaiSolarCalendar>
axis()
Returns the associated time axis.boolean
Based on the epoch day number and the calendar system.int
Yields the day of month.Determines the day of week.int
Yields the day of year.static Weekmodel
Obtains the standard week model of this calendar.getEra()
Yields the buddhist era.getMonth()
Yields the (gregorian) month.int
getYear()
Yields the buddhist Thai year.int
hashCode()
Based on the epoch day number.boolean
Is the year of this date a leap year?static boolean
isValid(ThaiSolarEra era, int yearOfEra, int month, int dayOfMonth)
Queries if given parameter values form a well defined calendar date.int
Yields the length of current month in days.int
Yields the length of current year in days.static ThaiSolarCalendar
Obtains the current calendar date in system time.static ThaiSolarCalendar
of(ThaiSolarEra era, int yearOfEra, int month, int dayOfMonth)
Creates a new instance of a Thai solar calendar date.static ThaiSolarCalendar
ofBuddhist(int yearOfEra, int month, int dayOfMonth)
Creates a new instance of a Thai solar calendar date.static ThaiSolarCalendar
ofBuddhist(int yearOfEra, Month month, int dayOfMonth)
Creates a new instance of a Thai solar 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 Thai era.
-
YEAR_OF_ERA
@FormattableElement(format="y") public static final StdCalendarElement<Integer,ThaiSolarCalendar> YEAR_OF_ERARepresents the Thai year, usually in buddhist counting.
-
MONTH_OF_YEAR
@FormattableElement(format="M", alt="L") public static final StdCalendarElement<Month,ThaiSolarCalendar> MONTH_OF_YEARRepresents the month.
-
DAY_OF_MONTH
@FormattableElement(format="d") public static final StdCalendarElement<Integer,ThaiSolarCalendar> DAY_OF_MONTHRepresents the day of month.
-
DAY_OF_YEAR
@FormattableElement(format="D") public static final StdCalendarElement<Integer,ThaiSolarCalendar> DAY_OF_YEARRepresents the day of year.
-
DAY_OF_WEEK
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,ThaiSolarCalendar> DAY_OF_WEEKRepresents the day of week.
If the day-of-week is set to a new value then Time4J handles the calendar week as starting on Sunday.
-
WEEKDAY_IN_MONTH
@FormattableElement(format="F") public static final OrdinalWeekdayElement<ThaiSolarCalendar> WEEKDAY_IN_MONTHElement with the ordinal day-of-week within given calendar month.
-
-
Method Details
-
ofBuddhist
Creates a new instance of a Thai solar calendar date.
- Parameters:
yearOfEra
- buddhist year of era>= 1
month
- gregorian monthdayOfMonth
- day of month- Returns:
- new instance of
ThaiSolarCalendar
- Throws:
IllegalArgumentException
- in case of any inconsistencies- Since:
- 3.19/4.15
-
ofBuddhist
Creates a new instance of a Thai solar calendar date.
- Parameters:
yearOfEra
- buddhist year of era>= 1
month
- gregorian month (1-12)dayOfMonth
- day of month- Returns:
- new instance of
ThaiSolarCalendar
- Throws:
IllegalArgumentException
- in case of any inconsistencies- Since:
- 3.19/4.15
-
of
Creates a new instance of a Thai solar calendar date.
- Parameters:
era
- Thai erayearOfEra
- Thai year of era>= 1
month
- gregorian month (1-12)dayOfMonth
- day of month- Returns:
- new instance of
ThaiSolarCalendar
- Throws:
IllegalArgumentException
- in case of any inconsistencies- Since:
- 3.19/4.15
-
nowInSystemTime
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(ThaiSolarCalendar.axis())
.- Returns:
- current calendar date in system time zone using the system clock
- Since:
- 3.23/4.19
- See Also:
SystemClock.inLocalView()
,ZonalClock.now(net.time4j.engine.Chronology)
-
getEra
Yields the buddhist era.
- Returns:
ThaiSolarEra.BUDDHIST
- Since:
- 3.19/4.15
-
getYear
public int getYear()Yields the buddhist Thai year.
- Returns:
- int
- Since:
- 3.19/4.15
- See Also:
ThaiSolarEra.BUDDHIST
-
getMonth
Yields the (gregorian) month.
- Returns:
- enum
- Since:
- 3.19/4.15
-
getDayOfMonth
public int getDayOfMonth()Yields the day of month.
- Returns:
- int
- Since:
- 3.19/4.15
-
getDayOfWeek
Determines the day of week.
- Returns:
- Weekday
- Since:
- 3.19/4.15
-
getDayOfYear
public int getDayOfYear()Yields the day of year.
- Returns:
- int
- Since:
- 3.19/4.15
-
lengthOfMonth
public int lengthOfMonth()Yields the length of current month in days.
- Returns:
- int
- Since:
- 3.19/4.15
-
lengthOfYear
public int lengthOfYear()Yields the length of current year in days.
- Returns:
- int
- Since:
- 3.19/4.15
-
isLeapYear
public boolean isLeapYear()Is the year of this date a leap year?
- Returns:
- boolean
- Since:
- 3.19/4.15
-
isValid
Queries if given parameter values form a well defined calendar date.
- Parameters:
era
- the era to be checkedyearOfEra
- 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(ThaiSolarEra, 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
- Since:
- 3.19/4.15
-
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- Since:
- 3.19/4.15
-
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<CalendarUnit,ThaiSolarCalendar>
- See Also:
Chronology.getChronoType()
-
hashCode
public int hashCode()Description copied from class:Calendrical
Based on the epoch day number.
- Overrides:
hashCode
in classCalendrical<CalendarUnit,ThaiSolarCalendar>
-
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<CalendarUnit,ThaiSolarCalendar>
-
getDefaultWeekmodel
Obtains the standard week model of this calendar.
The thai calendar usually starts on Sunday.
- Returns:
- Weekmodel
- Since:
- 3.24/4.20
-
axis
Returns the associated time axis.
- Returns:
- chronology
- Since:
- 3.19/4.15
-