Class ChineseCalendar
- java.lang.Object
-
- com.ibm.icu.util.Calendar
-
- com.ibm.icu.util.ChineseCalendar
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<Calendar>
- Direct Known Subclasses:
DangiCalendar
public class ChineseCalendar extends Calendar
ChineseCalendar
is a concrete subclass ofCalendar
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. TheERA
field contains the cycle number, and theYEAR
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 theERA
field 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 aULocale
with the tag"@calendar=chinese"
.- See Also:
Calendar
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.ibm.icu.util.Calendar
Calendar.FormatConfiguration, Calendar.PatternData, Calendar.WeekData
-
-
Field Summary
Fields Modifier and Type Field Description private static TimeZone
CHINA_ZONE
The time zone used for performing astronomical computations.(package private) static int[][][]
CHINESE_DATE_PRECEDENCE
Field resolution table that incorporates IS_LEAP_MONTH.private static int
CHINESE_EPOCH_YEAR
The start year of the Chinese calendar, the 61st year of the reign of Huang Di.private int
epochYear
The start year of this Chinese calendar instance.private static java.lang.String[]
gTemporalLeapMonthCodes
private boolean
hasLeapMonthBetweenWinterSolstices
True if there is a leap month between the Winter Solstice before and after the current date.This is different from leap year because in some year, such as 1813 and 2033, the leap month is after the Winter Solstice of that year.private static int[][]
LIMITS
Array defining the limits of field values for this class.private CalendarCache
newYearCache
Cache that maps Gregorian year to local days of Chinese new year.private static long
serialVersionUID
private static int
SYNODIC_GAP
Value to be added or subtracted from the local days of a new moon to get close to the next or prior new moon, but not cross it.private CalendarCache
winterSolsticeCache
Cache that maps Gregorian year to local days of winter solstice.private TimeZone
zoneAstro
The zone used for the astronomical calculation of this Chinese calendar instance.-
Fields inherited from class com.ibm.icu.util.Calendar
AM, AM_PM, APRIL, AUGUST, BASE_FIELD_COUNT, DATE, DATE_PRECEDENCE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DOW_LOCAL, DOW_PRECEDENCE, 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, MONTH_PRECEDENCE, 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 aChineseCalendar
with the default time zone and locale.ChineseCalendar(int year, int month, int isLeapMonth, int date)
Constructs aChineseCalendar
with the given date set in the default time zone with the defaultFORMAT
locale.ChineseCalendar(int era, int year, int month, int isLeapMonth, int date)
Constructs aChineseCalendar
with the given date set in the default time zone with the defaultFORMAT
locale.ChineseCalendar(int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
Constructs aChineseCalendar
with the given date and time set for the default time zone with the defaultFORMAT
locale.ChineseCalendar(int era, int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
Constructs aChineseCalendar
with the given date and time set for the default time zone with the defaultFORMAT
locale.ChineseCalendar(TimeZone zone)
Construct aChineseCalendar
based on the current time in the given time zone with the defaultFORMAT
locale.ChineseCalendar(TimeZone zone, ULocale locale)
Construct aChineseCalendar
based on the current time with the given time zone with the given locale.protected
ChineseCalendar(TimeZone zone, ULocale locale, int epochYear, TimeZone zoneAstroCalc)
Deprecated.This API is ICU internal only.ChineseCalendar(TimeZone zone, java.util.Locale aLocale)
Construct aChineseCalendar
based on the current time in the given time zone with the given locale.ChineseCalendar(ULocale locale)
Constructs aChineseCalendar
based on the current time in the default time zone with the given locale.ChineseCalendar(java.util.Date date)
Construct aChineseCalendar
with the give date set in the default time zone with the default locale.ChineseCalendar(java.util.Locale aLocale)
Constructs aChineseCalendar
based 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 void
add(int field, int amount)
Override Calendar to handle leap months properly.private void
computeChineseFields(int days, int gyear, int gmonth, boolean setAllFields)
Compute fields for the Chinese calendar system.private long
daysToMillis(int days)
Convert local days to UTC epoch milliseconds.protected int[][][]
getFieldResolutionTable()
Override Calendar to add IS_LEAP_MONTH to the field resolution table.java.lang.String
getTemporalMonthCode()
Gets The Temporal monthCode value corresponding to the month for the date.java.lang.String
getType()
Returns the calendar type name string for this Calendar object.protected void
handleComputeFields(int julianDay)
Override Calendar to compute several fields specific to the Chinese calendar system.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.protected DateFormat
handleGetDateFormat(java.lang.String pattern, java.lang.String override, ULocale locale)
Creates aDateFormat
appropriate to this calendar.protected int
handleGetExtendedYear()
Implement abstract Calendar method to return the extended year defined by the current fields.protected int
handleGetLimit(int field, int limitType)
Override Calendar to return the limit value for the given field.protected int
handleGetMonthLength(int extendedYear, int month)
Override Calendar method to return the number of days in the given extended year and month.private boolean
hasNoMajorSolarTerm(int newMoon)
Return true if the given month lacks a major solar term.boolean
haveDefaultCentury()
Deprecated.This API is ICU internal only.boolean
inTemporalLeapYear()
Returns true if the date is in a leap year.protected int
internalGetMonth()
Deprecated.This API is ICU internal only.protected int
internalGetMonth(int defaultValue)
Deprecated.This API is ICU internal only.private boolean
isLeapMonthBetween(int newMoon1, int newMoon2)
Return true if there is a leap month on or after month newMoon1 and at or before month newMoon2.private int
majorSolarTerm(int days)
Return the major solar term on or before a given date.private int
millisToDays(long millis)
Convert UTC epoch milliseconds to local days.private int
newMoonNear(int days, boolean after)
Return the closest new moon to the given date, searching either forward or backward in time.private int
newYear(int gyear)
Return the Chinese new year of the given Gregorian year.private void
offsetMonth(int newMoon, int dom, int delta)
Adjust this calendar to be delta months before or after a given start position, pinning the day of month if necessary.private void
readObject(java.io.ObjectInputStream stream)
Override readObject.void
roll(int field, int amount)
Override Calendar to handle leap months properly.void
setTemporalMonthCode(java.lang.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.private int
synodicMonthsBetween(int day1, int day2)
Return the nearest integer number of synodic months between two dates.private int
winterSolstice(int gyear)
Return the major solar term on or after December 15 of the given Gregorian year, that is, the winter solstice of the given year.-
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, getActualMaximum, 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, 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, setLocale, setMinimalDaysInFirstWeek, setRelatedYear, setRepeatedWallTimeOption, setSkippedWallTimeOption, setTime, setTimeInMillis, setTimeZone, setWeekData, toString, validateField, validateField, validateFields, weekNumber, weekNumber
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
epochYear
private int epochYear
The start year of this Chinese calendar instance.
-
zoneAstro
private TimeZone zoneAstro
The zone used for the astronomical calculation of this Chinese calendar instance.
-
winterSolsticeCache
private transient CalendarCache winterSolsticeCache
Cache that maps Gregorian year to local days of winter solstice.- See Also:
winterSolstice(int)
-
newYearCache
private transient CalendarCache newYearCache
Cache that maps Gregorian year to local days of Chinese new year.- See Also:
newYear(int)
-
hasLeapMonthBetweenWinterSolstices
private transient boolean hasLeapMonthBetweenWinterSolstices
True if there is a leap month between the Winter Solstice before and after the current date.This is different from leap year because in some year, such as 1813 and 2033, the leap month is after the Winter Solstice of that year. So this value could be false for a date prior to the Winter Solstice of that year but that year still has a leap month and therefor is a leap year.
-
LIMITS
private static final int[][] LIMITS
Array defining the limits of field values for this class. Field limits which are invariant with respect to calendar system and defined by Calendar are left blank. Notes: ERA 5000000 / 60 = 83333. MONTH There are 12 or 13 lunar months in a year. However, we always number them 0..11, with an intercalated, identically numbered leap month, when necessary. DAY_OF_YEAR In a non-leap year there are 353, 354, or 355 days. In a leap year there are 383, 384, or 385 days. WEEK_OF_YEAR The least maximum occurs if there are 353 days in the year, and the first 6 are the last week of the previous year. Then we have 49 full weeks and 4 days in the last week: 6 + 49*7 + 4 = 353. So the least maximum is 50. The maximum occurs if there are 385 days in the year, and WOY 1 extends 6 days into the prior year. Then there are 54 full weeks, and 6 days in the last week: 1 + 54*7 + 6 = 385. The 6 days of the last week will fall into WOY 1 of the next year. Maximum is 55. WEEK_OF_MONTH In a 29 day month, if the first 7 days make up week 1 that leaves 3 full weeks and 1 day at the end. The least maximum is thus 5. In a 30 days month, if the previous 6 days belong WOM 1 of this month, we have 4 full weeks and 1 days at the end (which technically will be WOM 1 of the next month, but will be reported by time->fields and hence by getActualMaximum as WOM 6 of this month). Maximum is 6. DAY_OF_WEEK_IN_MONTH In a 29 or 30 day month, there are 4 full weeks plus 1 or 2 days at the end, so the maximum is always 5.
-
CHINESE_DATE_PRECEDENCE
static final int[][][] CHINESE_DATE_PRECEDENCE
Field resolution table that incorporates IS_LEAP_MONTH.
-
CHINESE_EPOCH_YEAR
private static final int CHINESE_EPOCH_YEAR
The start year of the Chinese calendar, the 61st year of the reign of Huang Di. Some sources use the first year of his reign, resulting in EXTENDED_YEAR values 60 years greater and ERA (cycle) values one greater.- See Also:
- Constant Field Values
-
CHINA_ZONE
private static final TimeZone CHINA_ZONE
The time zone used for performing astronomical computations. Some sources use a different historically accurate offset of GMT+7:45:40 for years before 1929; we do not do this.
-
SYNODIC_GAP
private static final int SYNODIC_GAP
Value to be added or subtracted from the local days of a new moon to get close to the next or prior new moon, but not cross it. Must be >= 1 and < CalendarAstronomer.SYNODIC_MONTH.- See Also:
- Constant Field Values
-
gTemporalLeapMonthCodes
private static java.lang.String[] gTemporalLeapMonthCodes
-
-
Constructor Detail
-
ChineseCalendar
public ChineseCalendar()
Construct aChineseCalendar
with the default time zone and locale.
-
ChineseCalendar
public ChineseCalendar(java.util.Date date)
Construct aChineseCalendar
with the give date set in the default time zone with the default locale.- Parameters:
date
- The date to which the new calendar is set.
-
ChineseCalendar
public ChineseCalendar(int year, int month, int isLeapMonth, int date)
Constructs aChineseCalendar
with the given date set in the default time zone with the defaultFORMAT
locale.- Parameters:
year
- The value used to set the calendar'sYEAR
time field.month
- The value used to set the calendar'sMONTH
time field. The value is 0-based. e.g., 0 for January.isLeapMonth
- The value used to set the Chinese calendar'sCalendar.IS_LEAP_MONTH
time field.date
- The value used to set the calendar'sDATE
time field.- See Also:
ULocale.Category.FORMAT
-
ChineseCalendar
public ChineseCalendar(int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
Constructs aChineseCalendar
with the given date and time set for the default time zone with the defaultFORMAT
locale.- Parameters:
year
- the value used to set theYEAR
time field in the calendar.month
- the value used to set theMONTH
time 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_MONTH
time field in the calendar.date
- the value used to set theDATE
time field in the calendar.hour
- the value used to set theHOUR_OF_DAY
time field in the calendar.minute
- the value used to set theMINUTE
time field in the calendar.second
- the value used to set theSECOND
time field in the calendar.- See Also:
ULocale.Category.FORMAT
-
ChineseCalendar
public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date)
Constructs aChineseCalendar
with the given date set in the default time zone with the defaultFORMAT
locale.- Parameters:
era
- The value used to set the calendar'sERA
time field.year
- The value used to set the calendar'sYEAR
time field.month
- The value used to set the calendar'sMONTH
time field. The value is 0-based. e.g., 0 for January.isLeapMonth
- The value used to set the Chinese calendar'sCalendar.IS_LEAP_MONTH
time field.date
- The value used to set the calendar'sDATE
time field.- See Also:
ULocale.Category.FORMAT
-
ChineseCalendar
public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date, int hour, int minute, int second)
Constructs aChineseCalendar
with the given date and time set for the default time zone with the defaultFORMAT
locale.- Parameters:
era
- the value used to set the calendar'sERA
time field.year
- the value used to set theYEAR
time field in the calendar.month
- the value used to set theMONTH
time 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_MONTH
time field in the calendar.date
- the value used to set theDATE
time field in the calendar.hour
- the value used to set theHOUR_OF_DAY
time field in the calendar.minute
- the value used to set theMINUTE
time field in the calendar.second
- the value used to set theSECOND
time field in the calendar.- See Also:
ULocale.Category.FORMAT
-
ChineseCalendar
public ChineseCalendar(java.util.Locale aLocale)
Constructs aChineseCalendar
based on the current time in the default time zone with the given locale.- Parameters:
aLocale
- The given locale
-
ChineseCalendar
public ChineseCalendar(TimeZone zone)
Construct aChineseCalendar
based on the current time in the given time zone with the defaultFORMAT
locale.- Parameters:
zone
- the given time zone- See Also:
ULocale.Category.FORMAT
-
ChineseCalendar
public ChineseCalendar(TimeZone zone, java.util.Locale aLocale)
Construct aChineseCalendar
based on the current time in the given time zone with the given locale.- Parameters:
zone
- the given time zoneaLocale
- the given locale
-
ChineseCalendar
public ChineseCalendar(ULocale locale)
Constructs aChineseCalendar
based on the current time in the default time zone with the given locale.- Parameters:
locale
- the given ulocale
-
ChineseCalendar
public ChineseCalendar(TimeZone zone, ULocale locale)
Construct aChineseCalendar
based on the current time with the given time zone with the given locale.- Parameters:
zone
- the given time zonelocale
- the given ulocale
-
ChineseCalendar
@Deprecated protected ChineseCalendar(TimeZone zone, ULocale locale, int epochYear, TimeZone zoneAstroCalc)
Deprecated.This API is ICU internal only.Construct aChineseCalenar
based on the current time with the given time zone, the locale, the epoch year and the time zone used for astronomical calculation.
-
-
Method Detail
-
handleGetLimit
protected int handleGetLimit(int field, int limitType)
Override Calendar to return the limit value for the given field.- Specified by:
handleGetLimit
in classCalendar
- Parameters:
field
- one of the above field numberslimitType
- one ofMINIMUM
,GREATEST_MINIMUM
,LEAST_MAXIMUM
, orMAXIMUM
-
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:
handleGetExtendedYear
in classCalendar
- Returns:
- the extended year
-
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:
handleGetMonthLength
in classCalendar
-
handleGetDateFormat
protected DateFormat handleGetDateFormat(java.lang.String pattern, java.lang.String override, ULocale locale)
Creates aDateFormat
appropriate 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:
handleGetDateFormat
in classCalendar
- Parameters:
pattern
- the pattern, specific to theDateFormat
subclasslocale
- the locale for which the symbols should be drawn- Returns:
- a
DateFormat
appropriate to this calendar
-
getFieldResolutionTable
protected int[][][] getFieldResolutionTable()
Override Calendar to add IS_LEAP_MONTH to the field resolution table.- Overrides:
getFieldResolutionTable
in classCalendar
- See Also:
Calendar.resolveFields(int[][][])
-
offsetMonth
private void offsetMonth(int newMoon, int dom, int delta)
Adjust this calendar to be delta months before or after a given start position, pinning the day of month if necessary. The start position is given as a local days number for the start of the month and a day-of-month. Used by add() and roll().- Parameters:
newMoon
- the local days of the first day of the month of the start position (days after January 1, 1970 0:00 Asia/Shanghai)dom
- the 1-based day-of-month of the start positiondelta
- the number of months to move forward or backward from the start position
-
add
public void add(int field, int amount)
Override Calendar to handle leap months properly.- Overrides:
add
in classCalendar
- Parameters:
field
- the time field.amount
- the amount to add to the field.- See Also:
Calendar.roll(int, int)
-
roll
public void roll(int field, int amount)
Override Calendar to handle leap months properly.- Overrides:
roll
in 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)
-
daysToMillis
private final long daysToMillis(int days)
Convert local days to UTC epoch milliseconds. This is not an accurate conversion in terms that getTimezoneOffset takes the milliseconds in GMT (not local time). In theory, more accurate algorithm can be implemented but practically we do not need to go through that complication as long as the historically timezone changes did not happen around the 'tricky' new moon (new moon around the midnight).- Parameters:
days
- days after January 1, 1970 0:00 in the astronomical base zone- Returns:
- milliseconds after January 1, 1970 0:00 GMT
-
millisToDays
private final int millisToDays(long millis)
Convert UTC epoch milliseconds to local days.- Parameters:
millis
- milliseconds after January 1, 1970 0:00 GMT- Returns:
- days days after January 1, 1970 0:00 in the astronomical base zone
-
winterSolstice
private int winterSolstice(int gyear)
Return the major solar term on or after December 15 of the given Gregorian year, that is, the winter solstice of the given year. Computations are relative to Asia/Shanghai time zone.- Parameters:
gyear
- a Gregorian year- Returns:
- days after January 1, 1970 0:00 Asia/Shanghai of the winter solstice of the given year
-
newMoonNear
private int newMoonNear(int days, boolean after)
Return the closest new moon to the given date, searching either forward or backward in time.- Parameters:
days
- days after January 1, 1970 0:00 Asia/Shanghaiafter
- if true, search for a new moon on or after the given date; otherwise, search for a new moon before it- Returns:
- days after January 1, 1970 0:00 Asia/Shanghai of the nearest
new moon after or before
days
-
synodicMonthsBetween
private int synodicMonthsBetween(int day1, int day2)
Return the nearest integer number of synodic months between two dates.- Parameters:
day1
- days after January 1, 1970 0:00 Asia/Shanghaiday2
- days after January 1, 1970 0:00 Asia/Shanghai- Returns:
- the nearest integer number of months between day1 and day2
-
majorSolarTerm
private int majorSolarTerm(int days)
Return the major solar term on or before a given date. This will be an integer from 1..12, with 1 corresponding to 330 degrees, 2 to 0 degrees, 3 to 30 degrees,..., and 12 to 300 degrees.- Parameters:
days
- days after January 1, 1970 0:00 Asia/Shanghai
-
hasNoMajorSolarTerm
private boolean hasNoMajorSolarTerm(int newMoon)
Return true if the given month lacks a major solar term.- Parameters:
newMoon
- days after January 1, 1970 0:00 Asia/Shanghai of a new moon
-
isLeapMonthBetween
private boolean isLeapMonthBetween(int newMoon1, int newMoon2)
Return true if there is a leap month on or after month newMoon1 and at or before month newMoon2.- Parameters:
newMoon1
- days after January 1, 1970 0:00 astronomical base zone of a new moonnewMoon2
- days after January 1, 1970 0:00 astronomical base zone of a new moon
-
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:
handleComputeFields
in classCalendar
-
computeChineseFields
private void computeChineseFields(int days, int gyear, int gmonth, boolean setAllFields)
Compute fields for the Chinese calendar system. This method can either set all relevant fields, as required byhandleComputeFields()
, or it can just set the MONTH and IS_LEAP_MONTH fields, as required byhandleComputeMonthStart()
.As a side effect, this method sets
hasLeapMonthBetweenWinterSolstices
.- Parameters:
days
- days after January 1, 1970 0:00 astronomical base zone of the date to compute fields forgyear
- the Gregorian year of the given dategmonth
- the Gregorian month of the given datesetAllFields
- if true, set the EXTENDED_YEAR, ERA, YEAR, DAY_OF_MONTH, and DAY_OF_YEAR fields. In either case set the MONTH and IS_LEAP_MONTH fields.
-
newYear
private int newYear(int gyear)
Return the Chinese new year of the given Gregorian year.- Parameters:
gyear
- a Gregorian year- Returns:
- days after January 1, 1970 0:00 astronomical base zone of the Chinese new year of the given year (this will be a new moon)
-
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:
handleComputeMonthStart
in 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
-
getType
public java.lang.String getType()
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 returnfalse
if such practice is not applicable (for example, Chinese calendar and Japanese calendar).- Overrides:
haveDefaultCentury
in classCalendar
- Returns:
true
if this calendar has a default century.
-
readObject
private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
Override readObject.- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
inTemporalLeapYear
public boolean inTemporalLeapYear()
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:
inTemporalLeapYear
in classCalendar
- Returns:
- true if the date in the fields is in a Temporal proposal defined leap year. False otherwise.
-
getTemporalMonthCode
public java.lang.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:
getTemporalMonthCode
in classCalendar
- Returns:
- One of 24 possible strings in {"M01".."M12", "M01L".."M12L"}.
-
setTemporalMonthCode
public void setTemporalMonthCode(java.lang.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:
setTemporalMonthCode
in classCalendar
- Parameters:
temporalMonth
- One of 25 possible strings in {"M01".. "M12", "M13", "M01L", "M12L"}.
-
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:
internalGetMonth
in classCalendar
- Returns:
- the value for the given time field.
-
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:
internalGetMonth
in classCalendar
- Parameters:
defaultValue
- a default value used if the MONTH and ORDINAL_MONTH are both unset.- Returns:
- the value for the MONTH.
-
-