Class ChineseCalendar
- java.lang.Object
-
- com.ibm.icu.util.Calendar
-
- com.ibm.icu.util.ChineseCalendar
-
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<Calendar>
- Direct Known Subclasses:
DangiCalendar
public class ChineseCalendar extends Calendar
ChineseCalendaris a concrete subclass ofCalendarthat 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_YEARfield contains the sequential year count. TheERAfield contains the cycle number, and theYEARfield 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
ChineseCalendardefines an additional field and redefines the way theERAfield is used, it requires a new format class,ChineseDateFormat. As always, use the methodsDateFormat.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 aULocalewith the tag"@calendar=chinese".- Author:
- Alan Liu
- See Also:
Calendar, Serialized Form- Status:
- Stable ICU 2.8.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.ibm.icu.util.Calendar
Calendar.FormatConfiguration, Calendar.WeekData
-
-
Field Summary
-
Fields inherited from class com.ibm.icu.util.Calendar
AM, AM_PM, APRIL, AUGUST, BASE_FIELD_COUNT, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DOW_LOCAL, DST_OFFSET, EPOCH_JULIAN_DAY, ERA, EXTENDED_YEAR, FEBRUARY, FRIDAY, GREATEST_MINIMUM, HOUR, HOUR_OF_DAY, INTERNALLY_SET, IS_LEAP_MONTH, JAN_1_1_JULIAN_DAY, JANUARY, JULIAN_DAY, JULY, JUNE, LEAST_MAXIMUM, MARCH, MAX_DATE, MAX_FIELD_COUNT, MAX_JULIAN, MAX_MILLIS, MAXIMUM, MAY, MILLISECOND, MILLISECONDS_IN_DAY, MIN_DATE, MIN_JULIAN, MIN_MILLIS, MINIMUM, MINIMUM_USER_STAMP, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ORDINAL_MONTH, PM, RESOLVE_REMAP, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, TUESDAY, UNDECIMBER, UNSET, WALLTIME_FIRST, WALLTIME_LAST, WALLTIME_NEXT_VALID, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, WEEKDAY, WEEKEND, WEEKEND_CEASE, WEEKEND_ONSET, YEAR, YEAR_WOY, ZONE_OFFSET
-
-
Constructor Summary
Constructors Modifier Constructor Description ChineseCalendar()Construct aChineseCalendarwith the default time zone and locale.ChineseCalendar(int year, int month, int isLeapMonth, int date)Constructs aChineseCalendarwith the given date set in the default time zone with the defaultFORMATlocale.ChineseCalendar(int era, int year, int month, int isLeapMonth, int date)Constructs aChineseCalendarwith the given date set in the default time zone with the defaultFORMATlocale.ChineseCalendar(int year, int month, int isLeapMonth, int date, int hour, int minute, int second)Constructs aChineseCalendarwith the given date and time set for the default time zone with the defaultFORMATlocale.ChineseCalendar(int era, int year, int month, int isLeapMonth, int date, int hour, int minute, int second)Constructs aChineseCalendarwith the given date and time set for the default time zone with the defaultFORMATlocale.ChineseCalendar(TimeZone zone)Construct aChineseCalendarbased on the current time in the given time zone with the defaultFORMATlocale.ChineseCalendar(TimeZone zone, ULocale locale)Construct aChineseCalendarbased on the current time with the given time zone with the given locale.protectedChineseCalendar(TimeZone zone, ULocale locale, TimeZone zoneAstroCalc)Deprecated.This API is ICU internal only.ChineseCalendar(TimeZone zone, Locale aLocale)Construct aChineseCalendarbased on the current time in the given time zone with the given locale.ChineseCalendar(ULocale locale)Constructs aChineseCalendarbased on the current time in the default time zone with the given locale.ChineseCalendar(Date date)Construct aChineseCalendarwith the give date set in the default time zone with the default locale.ChineseCalendar(Locale aLocale)Constructs aChineseCalendarbased on the current time in the default time zone with the given locale.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(int field, int amount)Override Calendar to handle leap months properly.intgetActualMaximum(int field)Returns the maximum value that this field could have, given the current date.protected int[][][]getFieldResolutionTable()Override Calendar to add IS_LEAP_MONTH to the field resolution table.StringgetTemporalMonthCode()Gets The Temporal monthCode value corresponding to the month for the date.StringgetType()[icu] Returns the calendar type name string for this Calendar object.protected voidhandleComputeFields(int julianDay)Override Calendar to compute several fields specific to the Chinese calendar system.protected inthandleComputeMonthStart(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.protected DateFormathandleGetDateFormat(String pattern, String override, ULocale locale)Creates aDateFormatappropriate to this calendar.protected inthandleGetExtendedYear()Implement abstract Calendar method to return the extended year defined by the current fields.protected inthandleGetLimit(int field, int limitType)Override Calendar to return the limit value for the given field.protected inthandleGetMonthLength(int extendedYear, int month)Override Calendar method to return the number of days in the given extended year and month.booleanhaveDefaultCentury()Deprecated.This API is ICU internal only.booleaninTemporalLeapYear()[icu] Returns true if the date is in a leap year.protected intinternalGetMonth()Deprecated.This API is ICU internal only.protected intinternalGetMonth(int defaultValue)Deprecated.This API is ICU internal only.voidroll(int field, int amount)Override Calendar to handle leap months properly.voidsetTemporalMonthCode(String temporalMonth)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.-
Methods inherited from class com.ibm.icu.util.Calendar
after, before, clear, clear, clone, compareTo, complete, computeFields, computeGregorianFields, computeGregorianMonthStart, computeJulianDay, computeMillisInDay, computeMillisInDayLong, computeTime, computeZoneOffset, computeZoneOffset, equals, fieldDifference, fieldName, floorDivide, floorDivide, floorDivide, floorDivide, get, getActualMinimum, getAvailableLocales, getAvailableULocales, getDateAtTimePattern, getDateTimeFormat, getDateTimeFormat, getDateTimePattern, getDayOfWeekType, getDefaultDayInMonth, getDefaultMonthInYear, getDisplayName, getDisplayName, getFieldCount, getFirstDayOfWeek, getGreatestMinimum, getGregorianDayOfMonth, getGregorianDayOfYear, getGregorianMonth, getGregorianYear, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getKeywordValuesForLocale, getLeastMaximum, getLimit, getLocale, getMaximum, getMinimalDaysInFirstWeek, getMinimum, getRelatedYear, getRelatedYearDifference, getRepeatedWallTimeOption, getSkippedWallTimeOption, getStamp, getTime, getTimeInMillis, getTimeZone, getWeekData, getWeekDataForRegion, getWeekendTransition, gregorianMonthLength, gregorianPreviousMonthLength, handleComputeJulianDay, handleCreateFields, handleGetDateFormat, handleGetDateFormat, handleGetDateFormat, handleGetYearLength, hashCode, internalGet, internalGet, internalGetTimeInMillis, internalSet, isEquivalentTo, isEra0CountingBackward, isGregorianLeapYear, isLenient, isSet, isWeekend, isWeekend, julianDayToDayOfWeek, julianDayToMillis, millisToJulianDay, newerField, newestStamp, pinField, prepareGetActual, resolveFields, roll, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setRelatedYear, setRepeatedWallTimeOption, setSkippedWallTimeOption, setTime, setTimeInMillis, setTimeZone, setWeekData, toString, validateField, validateField, validateFields, weekNumber, weekNumber
-
-
-
-
Constructor Detail
-
ChineseCalendar
public ChineseCalendar()
Construct aChineseCalendarwith the default time zone and locale.- Status:
- Stable ICU 2.8.
-
ChineseCalendar
public ChineseCalendar(Date date)
Construct aChineseCalendarwith the give date set in the default time zone with the default locale.- Parameters:
date- The date to which the new calendar is set.- Status:
- Stable ICU 4.0.
-
ChineseCalendar
public ChineseCalendar(int year, int month, int isLeapMonth, int date)Constructs aChineseCalendarwith the given date set in the default time zone with the defaultFORMATlocale.- Parameters:
year- The value used to set the calendar'sYEARtime field.month- The value used to set the calendar'sMONTHtime field. The value is 0-based. e.g., 0 for January.isLeapMonth- The value used to set the Chinese calendar'sCalendar.IS_LEAP_MONTHtime field.date- The value used to set the calendar'sDATEtime field.- See Also:
ULocale.Category.FORMAT- Status:
- Stable ICU 4.0.
-
ChineseCalendar
public ChineseCalendar(int year, int month, int isLeapMonth, int date, int hour, int minute, int second)Constructs aChineseCalendarwith the given date and time set for the default time zone with the defaultFORMATlocale.- Parameters:
year- the value used to set theYEARtime field in the calendar.month- the value used to set theMONTHtime field in the calendar. Note that the month value is 0-based. e.g., 0 for January.isLeapMonth- the value used to set theCalendar.IS_LEAP_MONTHtime field in the calendar.date- the value used to set theDATEtime field in the calendar.hour- the value used to set theHOUR_OF_DAYtime field in the calendar.minute- the value used to set theMINUTEtime field in the calendar.second- the value used to set theSECONDtime field in the calendar.- See Also:
ULocale.Category.FORMAT- Status:
- Stable ICU 4.0.
-
ChineseCalendar
public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date)Constructs aChineseCalendarwith the given date set in the default time zone with the defaultFORMATlocale.- Parameters:
era- The value used to set the calendar'sERAtime field.year- The value used to set the calendar'sYEARtime field.month- The value used to set the calendar'sMONTHtime field. The value is 0-based. e.g., 0 for January.isLeapMonth- The value used to set the Chinese calendar'sCalendar.IS_LEAP_MONTHtime field.date- The value used to set the calendar'sDATEtime field.- See Also:
ULocale.Category.FORMAT- Status:
- Stable ICU 4.6.
-
ChineseCalendar
public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date, int hour, int minute, int second)Constructs aChineseCalendarwith the given date and time set for the default time zone with the defaultFORMATlocale.- Parameters:
era- the value used to set the calendar'sERAtime field.year- the value used to set theYEARtime field in the calendar.month- the value used to set theMONTHtime field in the calendar. Note that the month value is 0-based. e.g., 0 for January.isLeapMonth- the value used to set theCalendar.IS_LEAP_MONTHtime field in the calendar.date- the value used to set theDATEtime field in the calendar.hour- the value used to set theHOUR_OF_DAYtime field in the calendar.minute- the value used to set theMINUTEtime field in the calendar.second- the value used to set theSECONDtime field in the calendar.- See Also:
ULocale.Category.FORMAT- Status:
- Stable ICU 4.6.
-
ChineseCalendar
public ChineseCalendar(Locale aLocale)
Constructs aChineseCalendarbased on the current time in the default time zone with the given locale.- Parameters:
aLocale- The given locale- Status:
- Stable ICU 4.0.
-
ChineseCalendar
public ChineseCalendar(TimeZone zone)
Construct aChineseCalendarbased on the current time in the given time zone with the defaultFORMATlocale.- Parameters:
zone- the given time zone- See Also:
ULocale.Category.FORMAT- Status:
- Stable ICU 4.0.
-
ChineseCalendar
public ChineseCalendar(TimeZone zone, Locale aLocale)
Construct aChineseCalendarbased on the current time in the given time zone with the given locale.- Parameters:
zone- the given time zoneaLocale- the given locale- Status:
- Stable ICU 2.8.
-
ChineseCalendar
public ChineseCalendar(ULocale locale)
Constructs aChineseCalendarbased on the current time in the default time zone with the given locale.- Parameters:
locale- the given ulocale- Status:
- Stable ICU 4.0.
-
ChineseCalendar
public ChineseCalendar(TimeZone zone, ULocale locale)
Construct aChineseCalendarbased on the current time with the given time zone with the given locale.- Parameters:
zone- the given time zonelocale- the given ulocale- Status:
- Stable ICU 3.2.
-
ChineseCalendar
@Deprecated protected ChineseCalendar(TimeZone zone, ULocale locale, TimeZone zoneAstroCalc)
Deprecated.This API is ICU internal only.Construct aChineseCalenarbased on the current time with the given time zone, the locale, the epoch year and the time zone used for astronomical calculation.- Status:
- Internal. This API is ICU internal only.
-
-
Method Detail
-
handleGetLimit
protected int handleGetLimit(int field, int limitType)Override Calendar to return the limit value for the given field.- Specified by:
handleGetLimitin classCalendar- Parameters:
field- one of the above field numberslimitType- one ofMINIMUM,GREATEST_MINIMUM,LEAST_MAXIMUM, orMAXIMUM- Status:
- Stable ICU 2.8.
-
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.- Specified by:
handleGetExtendedYearin classCalendar- Returns:
- the extended year
- Status:
- Stable ICU 2.8.
-
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.
- Overrides:
handleGetMonthLengthin classCalendar- Status:
- Stable ICU 2.8.
-
handleGetDateFormat
protected DateFormat handleGetDateFormat(String pattern, String override, ULocale locale)
Creates aDateFormatappropriate to this calendar. This is a framework method for subclasses to override. This method is responsible for creating the calendar-specific DateFormat and DateFormatSymbols objects as needed.- Overrides:
handleGetDateFormatin classCalendar- Parameters:
pattern- the pattern, specific to theDateFormatsubclasslocale- the locale for which the symbols should be drawn- Returns:
- a
DateFormatappropriate to this calendar - Status:
- Stable ICU 4.2.
-
getFieldResolutionTable
protected int[][][] getFieldResolutionTable()
Override Calendar to add IS_LEAP_MONTH to the field resolution table.- Overrides:
getFieldResolutionTablein classCalendar- See Also:
Calendar.resolveFields(int[][][])- Status:
- Stable ICU 2.8.
-
add
public void add(int field, int amount)Override Calendar to handle leap months properly.- Overrides:
addin classCalendar- Parameters:
field- the time field.amount- the amount to add to the field.- See Also:
Calendar.roll(int, int)- Status:
- Stable ICU 2.8.
-
roll
public void roll(int field, int amount)Override Calendar to handle leap months properly.- Overrides:
rollin classCalendar- Parameters:
field- the calendar field to roll.amount- the amount by which the field should be rolled.- See Also:
Calendar.roll(int, boolean),Calendar.add(int, int)- Status:
- Stable ICU 2.8.
-
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.
- Overrides:
handleComputeFieldsin classCalendar- Status:
- Stable ICU 2.8.
-
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.
- Specified by:
handleComputeMonthStartin classCalendar- Parameters:
eyear- the extended yearmonth- the zero-based month. The month is also determined by reading the IS_LEAP_MONTH field.useMonth- 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:
- the Julian day number of the day before the first day of the given month and year
- Status:
- Stable ICU 2.8.
-
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
-
haveDefaultCentury
@Deprecated public boolean haveDefaultCentury()
Deprecated.This API is ICU internal only.Returns if two digit representation of year in this calendar type customarily implies a default century (i.e. 03 -> 2003). The default implementation returnstrue. A subclass may returnfalseif such practice is not applicable (for example, Chinese calendar and Japanese calendar).- Overrides:
haveDefaultCenturyin classCalendar- Returns:
trueif this calendar has a default century.- Status:
- Internal. This API is ICU internal only.
-
inTemporalLeapYear
public boolean inTemporalLeapYear()
[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.- Overrides:
inTemporalLeapYearin classCalendar- Returns:
- true if the date in the fields is in a Temporal proposal defined leap year. False otherwise.
- Status:
- Stable ICU 74.
-
getTemporalMonthCode
public String getTemporalMonthCode()
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".- Overrides:
getTemporalMonthCodein classCalendar- Returns:
- One of 24 possible strings in {"M01".."M12", "M01L".."M12L"}.
- Status:
- Stable ICU 74.
-
setTemporalMonthCode
public void setTemporalMonthCode(String temporalMonth)
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".- Overrides:
setTemporalMonthCodein classCalendar- Parameters:
temporalMonth- One of 25 possible strings in {"M01".. "M12", "M13", "M01L", "M12L"}.- Status:
- Stable ICU 74.
-
internalGetMonth
@Deprecated protected int internalGetMonth()
Deprecated.This API is ICU internal only.Use this function instead of internalGet(MONTH). The implementation check the timestamp of MONTH and ORDINAL_MONTH and use the one set later. The subclass should override it to conver the value of ORDINAL_MONTH to MONTH correctly if ORDINAL_MONTH has higher priority.- Overrides:
internalGetMonthin classCalendar- Returns:
- the value for the given time field.
- Status:
- Internal. This API is ICU internal only.
-
internalGetMonth
@Deprecated protected int internalGetMonth(int defaultValue)
Deprecated.This API is ICU internal only.Use this function instead of internalGet(MONTH, defaultValue). The implementation check the timestamp of MONTH and ORDINAL_MONTH and use the one set later. The subclass should override it to conver the value of ORDINAL_MONTH to MONTH correctly if ORDINAL_MONTH has higher priority.- Overrides:
internalGetMonthin classCalendar- Parameters:
defaultValue- a default value used if the MONTH and ORDINAL_MONTH are both unset.- Returns:
- the value for the MONTH.
- Status:
- Internal. This API is ICU internal only.
-
getActualMaximum
public int getActualMaximum(int field)
Returns the maximum value that this field could have, given the current date. For example, with the Gregorian date February 3, 1997 and theDAY_OF_MONTHfield, the actual maximum is 28; for February 3, 1996 it is 29.The actual maximum computation ignores smaller fields and the current value of like-sized fields. For example, the actual maximum of the DAY_OF_YEAR or MONTH depends only on the year and supra-year fields. The actual maximum of the DAY_OF_MONTH depends, in addition, on the MONTH field and any other fields at that granularity (such as IS_LEAP_MONTH). The DAY_OF_WEEK_IN_MONTH field does not depend on the current DAY_OF_WEEK; it returns the maximum for any day of week in the current month. Likewise for the WEEK_OF_MONTH and WEEK_OF_YEAR fields.
- Overrides:
getActualMaximumin classCalendar- Parameters:
field- the field whose maximum is desired- Returns:
- the maximum of the given field for the current date of this calendar
- See Also:
Calendar.getMaximum(int),Calendar.getLeastMaximum(int)- Status:
- Stable ICU 2.8.
-
-