ChineseCalendar
open class ChineseCalendar : Calendar
kotlin.Any | ||
↳ | android.icu.util.Calendar | |
↳ | android.icu.util.ChineseCalendar |
ChineseCalendar
is a concrete subclass of Calendar
that implements a traditional Chinese calendar. The traditional Chinese calendar is a lunisolar calendar: Each month starts on a new moon, and the months are numbered according to solar events, specifically, to guarantee that month 11 always contains the winter solstice. In order to accomplish this, leap months are inserted in certain years. Leap months are numbered the same as the month they follow. The decision of which month is a leap month depends on the relative movements of the sun and moon.
All astronomical computations are performed with respect to a time zone of GMT+8:00 and a longitude of 120 degrees east. Although some calendars implement a historically more accurate convention of using Beijing's local longitude (116 degrees 25 minutes east) and time zone (GMT+7:45:40) for dates before 1929, we do not implement this here.
Years are counted in two different ways in the Chinese calendar. The first method is by sequential numbering from the 61st year of the reign of Huang Di, 2637 BCE, which is designated year 1 on the Chinese calendar. The second method uses 60-year cycles from the same starting point, which is designated year 1 of cycle 1. In this class, the EXTENDED_YEAR
field contains the sequential year count. The ERA
field contains the cycle number, and the YEAR
field contains the year of the cycle, a value between 1 and 60.
There is some variation in what is considered the starting point of the calendar, with some sources starting in the first year of the reign of Huang Di, rather than the 61st. This gives continuous year numbers 60 years greater and cycle numbers one greater than what this class implements.
Because ChineseCalendar
defines an additional field and redefines the way the ERA
field is used, it requires a new format class, ChineseDateFormat
. As always, use the methods DateFormat.getXxxInstance(Calendar cal,...)
to obtain a formatter for this calendar.
References:
- Dershowitz and Reingold, Calendrical Calculations, Cambridge University Press, 1997
- The Calendar FAQ
This class should not be subclassed.
ChineseCalendar usually should be instantiated using android.icu.util.Calendar#getInstance(ULocale)
passing in a ULocale
with the tag "@calendar=chinese"
.
Summary
Inherited constants | |
---|---|
Public constructors | |
---|---|
Construct a |
|
ChineseCalendar(zone: TimeZone!) Construct a |
|
ChineseCalendar(zone: TimeZone!, locale: ULocale!) Construct a |
|
ChineseCalendar(zone: TimeZone!, aLocale: Locale!) Construct a |
|
ChineseCalendar(locale: ULocale!) Constructs a |
|
ChineseCalendar(year: Int, month: Int, isLeapMonth: Int, date: Int) Constructs a |
|
Constructs a |
|
ChineseCalendar(year: Int, month: Int, isLeapMonth: Int, date: Int, hour: Int, minute: Int, second: Int) Constructs a |
|
ChineseCalendar(era: Int, year: Int, month: Int, isLeapMonth: Int, date: Int, hour: Int, minute: Int, second: Int) Constructs a |
|
ChineseCalendar(date: Date!) Construct a |
|
ChineseCalendar(aLocale: Locale!) Constructs a |
Public methods | |
---|---|
open Unit |
Override Calendar to handle leap months properly. |
open String! |
Gets The Temporal monthCode value corresponding to the month for the date. |
open String! |
getType() [icu] Returns the calendar type name string for this Calendar object. |
open Boolean |
[icu] Returns true if the date is in a leap year. |
open Unit |
Override Calendar to handle leap months properly. |
open Unit |
setTemporalMonthCode(temporalMonth: String!) Sets The Temporal monthCode which is a string identifier that starts with the literal grapheme "M" followed by two graphemes representing the zero-padded month number of the current month in a normal (non-leap) year and suffixed by an optional literal grapheme "L" if this is a leap month in a lunisolar calendar. |
Protected methods | |
---|---|
open Array<Array<IntArray!>!>! |
Override Calendar to add IS_LEAP_MONTH to the field resolution table. |
open Unit |
handleComputeFields(julianDay: Int) Override Calendar to compute several fields specific to the Chinese calendar system. |
open Int |
handleComputeMonthStart(eyear: Int, month: Int, useMonth: Boolean) Return the Julian day number of day before the first day of the given month in the given extended year. |
open DateFormat! |
handleGetDateFormat(pattern: String!, override: String!, locale: ULocale!) |
open Int |
Implement abstract Calendar method to return the extended year defined by the current fields. |
open Int |
handleGetLimit(field: Int, limitType: Int) Override Calendar to return the limit value for the given field. |
open Int |
handleGetMonthLength(extendedYear: Int, month: Int) Override Calendar method to return the number of days in the given extended year and month. |
Inherited functions | |
---|---|
Inherited properties | |
---|---|
Public constructors
ChineseCalendar
ChineseCalendar()
Construct a ChineseCalendar
with the default time zone and locale.
ChineseCalendar
ChineseCalendar(zone: TimeZone!)
Construct a ChineseCalendar
based on the current time in the given time zone with the default FORMAT
locale.
Parameters | |
---|---|
zone |
TimeZone!: the given time zone |
ChineseCalendar
ChineseCalendar(
zone: TimeZone!,
locale: ULocale!)
Construct a ChineseCalendar
based on the current time with the given time zone with the given locale.
Parameters | |
---|---|
zone |
TimeZone!: the given time zone |
locale |
ULocale!: the given ulocale |
ChineseCalendar
ChineseCalendar(
zone: TimeZone!,
aLocale: Locale!)
Construct a ChineseCalendar
based on the current time in the given time zone with the given locale.
Parameters | |
---|---|
zone |
TimeZone!: the given time zone |
aLocale |
Locale!: the given locale |
ChineseCalendar
ChineseCalendar(locale: ULocale!)
Constructs a ChineseCalendar
based on the current time in the default time zone with the given locale.
Parameters | |
---|---|
locale |
ULocale!: the given ulocale |
ChineseCalendar
ChineseCalendar(
year: Int,
month: Int,
isLeapMonth: Int,
date: Int)
Constructs a ChineseCalendar
with the given date set in the default time zone with the default FORMAT
locale.
Parameters | |
---|---|
year |
Int: The value used to set the calendar's YEAR time field. |
month |
Int: The value used to set the calendar's MONTH time field. The value is 0-based. e.g., 0 for January. |
isLeapMonth |
Int: The value used to set the Chinese calendar's IS_LEAP_MONTH time field. |
date |
Int: The value used to set the calendar's DATE time field. |
ChineseCalendar
ChineseCalendar(
era: Int,
year: Int,
month: Int,
isLeapMonth: Int,
date: Int)
Constructs a ChineseCalendar
with the given date set in the default time zone with the default FORMAT
locale.
Parameters | |
---|---|
era |
Int: The value used to set the calendar's ERA time field. |
year |
Int: The value used to set the calendar's YEAR time field. |
month |
Int: The value used to set the calendar's MONTH time field. The value is 0-based. e.g., 0 for January. |
isLeapMonth |
Int: The value used to set the Chinese calendar's IS_LEAP_MONTH time field. |
date |
Int: The value used to set the calendar's DATE time field. |
ChineseCalendar
ChineseCalendar(
year: Int,
month: Int,
isLeapMonth: Int,
date: Int,
hour: Int,
minute: Int,
second: Int)
Constructs a ChineseCalendar
with the given date and time set for the default time zone with the default FORMAT
locale.
Parameters | |
---|---|
year |
Int: the value used to set the YEAR time field in the calendar. |
month |
Int: the value used to set the MONTH time field in the calendar. Note that the month value is 0-based. e.g., 0 for January. |
isLeapMonth |
Int: the value used to set the IS_LEAP_MONTH time field in the calendar. |
date |
Int: the value used to set the DATE time field in the calendar. |
hour |
Int: the value used to set the HOUR_OF_DAY time field in the calendar. |
minute |
Int: the value used to set the MINUTE time field in the calendar. |
second |
Int: the value used to set the SECOND time field in the calendar. |
ChineseCalendar
ChineseCalendar(
era: Int,
year: Int,
month: Int,
isLeapMonth: Int,
date: Int,
hour: Int,
minute: Int,
second: Int)
Constructs a ChineseCalendar
with the given date and time set for the default time zone with the default FORMAT
locale.
Parameters | |
---|---|
era |
Int: the value used to set the calendar's ERA time field. |
year |
Int: the value used to set the YEAR time field in the calendar. |
month |
Int: the value used to set the MONTH time field in the calendar. Note that the month value is 0-based. e.g., 0 for January. |
isLeapMonth |
Int: the value used to set the IS_LEAP_MONTH time field in the calendar. |
date |
Int: the value used to set the DATE time field in the calendar. |
hour |
Int: the value used to set the HOUR_OF_DAY time field in the calendar. |
minute |
Int: the value used to set the MINUTE time field in the calendar. |
second |
Int: the value used to set the SECOND time field in the calendar. |
ChineseCalendar
ChineseCalendar(date: Date!)
Construct a ChineseCalendar
with the give date set in the default time zone with the default locale.
Parameters | |
---|---|
date |
Date!: The date to which the new calendar is set. |
ChineseCalendar
ChineseCalendar(aLocale: Locale!)
Constructs a ChineseCalendar
based on the current time in the default time zone with the given locale.
Parameters | |
---|---|
aLocale |
Locale!: The given locale |
Public methods
add
open fun add(
field: Int,
amount: Int
): Unit
Override Calendar to handle leap months properly.
Parameters | |
---|---|
field |
Int: the time field. |
amount |
Int: the amount to add to the field. |
getTemporalMonthCode
open fun getTemporalMonthCode(): String!
Gets The Temporal monthCode value corresponding to the month for the date. The value is a string identifier that starts with the literal grapheme "M" followed by two graphemes representing the zero-padded month number of the current month in a normal (non-leap) year and suffixed by an optional literal grapheme "L" if this is a leap month in a lunisolar calendar. For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and * in leap year with another monthCode in "M01L" .. "M12L".
Return | |
---|---|
String! |
One of 24 possible strings in {"M01".."M12", "M01L".."M12L"}. |
getType
open fun getType(): String!
[icu] Returns the calendar type name string for this Calendar object. The returned string is the legacy ICU calendar attribute value, for example, "gregorian" or "japanese".
See type="old type name" for the calendar attribute of locale IDs at http://www.unicode.org/reports/tr35/#Key_Type_Definitions
Return | |
---|---|
String! |
legacy calendar type name string |
inTemporalLeapYear
open fun inTemporalLeapYear(): Boolean
[icu] Returns true if the date is in a leap year. Recalculate the current time field values if the time value has been changed by a call to setTime(). This method is semantically const, but may alter the object in memory. A "leap year" is a year that contains more days than other years (for solar or lunar calendars) or more months than other years (for lunisolar calendars like Hebrew or Chinese), as defined in the ECMAScript Temporal proposal.
Return | |
---|---|
Boolean |
true if the date in the fields is in a Temporal proposal defined leap year. False otherwise. |
roll
open fun roll(
field: Int,
amount: Int
): Unit
Override Calendar to handle leap months properly.
Parameters | |
---|---|
field |
Int: the calendar field to roll. |
amount |
Int: the amount by which the field should be rolled. |
setTemporalMonthCode
open fun setTemporalMonthCode(temporalMonth: String!): Unit
Sets The Temporal monthCode which is a string identifier that starts with the literal grapheme "M" followed by two graphemes representing the zero-padded month number of the current month in a normal (non-leap) year and suffixed by an optional literal grapheme "L" if this is a leap month in a lunisolar calendar. For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and in leap year with another monthCode in "M01L" .. "M12L".
Parameters | |
---|---|
temporalMonth |
String!: One of 25 possible strings in {"M01".. "M12", "M13", "M01L", "M12L"}. |
Protected methods
getFieldResolutionTable
protected open fun getFieldResolutionTable(): Array<Array<IntArray!>!>!
Override Calendar to add IS_LEAP_MONTH to the field resolution table.
handleComputeFields
protected open fun handleComputeFields(julianDay: Int): Unit
Override Calendar to compute several fields specific to the Chinese calendar system. These are:
- ERA
- YEAR
- MONTH
- DAY_OF_MONTH
- DAY_OF_YEAR
- EXTENDED_YEAR
Compute the ChineseCalendar-specific field IS_LEAP_MONTH.
handleComputeMonthStart
protected open fun handleComputeMonthStart(
eyear: Int,
month: Int,
useMonth: Boolean
): Int
Return the Julian day number of day before the first day of the given month in the given extended year.
Note: This method reads the IS_LEAP_MONTH field to determine whether the given month is a leap month.
Parameters | |
---|---|
eyear |
Int: the extended year |
month |
Int: the zero-based month. The month is also determined by reading the IS_LEAP_MONTH field. |
useMonth |
Boolean: if false, compute the day before the first day of the given year, otherwise, compute the day before the first day of the given month |
Return | |
---|---|
Int |
the Julian day number of the day before the first day of the given month and year |
handleGetDateFormat
protected open fun handleGetDateFormat(
pattern: String!,
override: String!,
locale: ULocale!
): DateFormat!
handleGetExtendedYear
protected open fun handleGetExtendedYear(): Int
Implement abstract Calendar method to return the extended year defined by the current fields. This will use either the ERA and YEAR field as the cycle and year-of-cycle, or the EXTENDED_YEAR field as the continuous year count, depending on which is newer.
Return | |
---|---|
Int |
the extended year |
handleGetLimit
protected open fun handleGetLimit(
field: Int,
limitType: Int
): Int
Override Calendar to return the limit value for the given field.
Parameters | |
---|---|
field |
Int: one of the above field numbers |
limitType |
Int: one of MINIMUM , GREATEST_MINIMUM , LEAST_MAXIMUM , or MAXIMUM |
handleGetMonthLength
protected open fun handleGetMonthLength(
extendedYear: Int,
month: Int
): Int
Override Calendar method to return the number of days in the given extended year and month.
Note: This method also reads the IS_LEAP_MONTH field to determine whether or not the given month is a leap month.