ChineseCalendar
public
class
ChineseCalendar
extends Calendar
java.lang.Object | ||
↳ | 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
Calendar.getInstance(ULocale)
passing in a ULocale
with the tag "@calendar=chinese"
.
See also:
Summary
Inherited constants |
---|
Inherited fields |
---|
Public constructors | |
---|---|
ChineseCalendar()
Construct a |
|
ChineseCalendar(Date date)
Construct a |
|
ChineseCalendar(int year, int month, int isLeapMonth, int date)
Constructs a |
|
ChineseCalendar(int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
Constructs a |
|
ChineseCalendar(int era, int year, int month, int isLeapMonth, int date)
Constructs a |
|
ChineseCalendar(int era, int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
Constructs a |
|
ChineseCalendar(Locale aLocale)
Constructs a |
|
ChineseCalendar(TimeZone zone)
Construct a |
|
ChineseCalendar(TimeZone zone, Locale aLocale)
Construct a |
|
ChineseCalendar(ULocale locale)
Constructs a |
|
ChineseCalendar(TimeZone zone, ULocale locale)
Construct a |
Public methods | |
---|---|
void
|
add(int field, int amount)
Override Calendar to handle leap months properly. |
String
|
getType()
[icu] Returns the calendar type name string for this Calendar object. |
void
|
roll(int field, int amount)
Override Calendar to handle leap months properly. |
Protected methods | |
---|---|
int[][][]
|
getFieldResolutionTable()
Override Calendar to add IS_LEAP_MONTH to the field resolution table. |
void
|
handleComputeFields(int julianDay)
Override Calendar to compute several fields specific to the Chinese calendar system. |
int
|
handleComputeMonthStart(int eyear, int month, boolean useMonth)
Return the Julian day number of day before the first day of the given month in the given extended year. |
DateFormat
|
handleGetDateFormat(String pattern, String override, ULocale locale)
|
int
|
handleGetExtendedYear()
Implement abstract Calendar method to return the extended year defined by the current fields. |
int
|
handleGetLimit(int field, int limitType)
Override Calendar to return the limit value for the given field. |
int
|
handleGetMonthLength(int extendedYear, int month)
Override Calendar method to return the number of days in the given extended year and month. |
Inherited methods | |
---|---|
Public constructors
ChineseCalendar
public ChineseCalendar ()
Construct a ChineseCalendar
with the default time zone and locale.
ChineseCalendar
public 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
public ChineseCalendar (int year, int month, int isLeapMonth, int date)
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 Calendar.IS_LEAP_MONTH
time field. |
date |
int : The value used to set the calendar's DATE time field. |
See also:
ChineseCalendar
public ChineseCalendar (int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
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 Calendar.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. |
See also:
ChineseCalendar
public ChineseCalendar (int era, int year, int month, int isLeapMonth, int date)
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 Calendar.IS_LEAP_MONTH
time field. |
date |
int : The value used to set the calendar's DATE time field. |
See also:
ChineseCalendar
public ChineseCalendar (int era, int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
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 Calendar.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. |
See also:
ChineseCalendar
public ChineseCalendar (Locale aLocale)
Constructs a ChineseCalendar
based on the current time
in the default time zone with the given locale.
Parameters | |
---|---|
aLocale |
Locale : The given locale |
ChineseCalendar
public ChineseCalendar (TimeZone zone)
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 |
See also:
ChineseCalendar
public ChineseCalendar (TimeZone zone, Locale aLocale)
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
public ChineseCalendar (ULocale locale)
Constructs a ChineseCalendar
based on the current time
in the default time zone with the given locale.
Parameters | |
---|---|
locale |
ULocale : the given ulocale |
ChineseCalendar
public ChineseCalendar (TimeZone zone, ULocale locale)
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 |
Public methods
add
public void add (int field, int amount)
Override Calendar to handle leap months properly.
Parameters | |
---|---|
field |
int : the time field. |
amount |
int : the amount to add to the field. |
getType
public String getType ()
[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
Returns | |
---|---|
String |
legacy calendar type name string |
roll
public void roll (int field, int amount)
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. |
Protected methods
getFieldResolutionTable
protected int[][][] getFieldResolutionTable ()
Override Calendar to add IS_LEAP_MONTH to the field resolution table.
Returns | |
---|---|
int[][][] |
handleComputeFields
protected void handleComputeFields (int julianDay)
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.
Parameters | |
---|---|
julianDay |
int |
handleComputeMonthStart
protected int handleComputeMonthStart (int eyear, int month, boolean useMonth)
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 |
Returns | |
---|---|
int |
the Julian day number of the day before the first day of the given month and year |
handleGetDateFormat
protected DateFormat handleGetDateFormat (String pattern, String override, ULocale locale)
Parameters | |
---|---|
pattern |
String |
override |
String |
locale |
ULocale |
Returns | |
---|---|
DateFormat |
handleGetExtendedYear
protected int handleGetExtendedYear ()
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.
Returns | |
---|---|
int |
the extended year |
handleGetLimit
protected int handleGetLimit (int field, int limitType)
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 |
Returns | |
---|---|
int |
handleGetMonthLength
protected int handleGetMonthLength (int extendedYear, int month)
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.
Parameters | |
---|---|
extendedYear |
int |
month |
int |
Returns | |
---|---|
int |