Package org.joda.time.chrono
Class BasicChronology
- java.lang.Object
-
- org.joda.time.Chronology
-
- org.joda.time.chrono.BaseChronology
-
- org.joda.time.chrono.AssembledChronology
-
- org.joda.time.chrono.BasicChronology
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
BasicFixedMonthChronology
,BasicGJChronology
,IslamicChronology
abstract class BasicChronology extends AssembledChronology
Abstract implementation for calendar systems that use a typical day/month/year/leapYear model. Most of the utility methods required by subclasses are package-private, reflecting the intention that they be defined in the same package.BasicChronology is thread-safe and immutable, and all subclasses must be as well.
- Since:
- 1.2, renamed from BaseGJChronology
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BasicChronology.HalfdayField
private static class
BasicChronology.YearInfo
-
Nested classes/interfaces inherited from class org.joda.time.chrono.AssembledChronology
AssembledChronology.Fields
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BasicChronology(Chronology base, java.lang.Object param, int minDaysInFirstWeek)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
assemble(AssembledChronology.Fields fields)
Invoked by the constructor and after deserialization to allow subclasses to define all of its supported fields.(package private) abstract long
calculateFirstDayOfYearMillis(int year)
Gets the millisecond value of the first day of the year.boolean
equals(java.lang.Object obj)
Checks if this chronology instance equals another.(package private) abstract long
getApproxMillisAtEpochDividedByTwo()
Returns a constant representing the approximate number of milliseconds elapsed from year 0 of this chronology, divided by two.(package private) abstract long
getAverageMillisPerMonth()
Gets an average value for the milliseconds per month.(package private) abstract long
getAverageMillisPerYear()
Gets an average value for the milliseconds per year.(package private) abstract long
getAverageMillisPerYearDividedByTwo()
Gets an average value for the milliseconds per year, divided by two.(package private) long
getDateMidnightMillis(int year, int monthOfYear, int dayOfMonth)
Gets the milliseconds for a date at midnight.long
getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int millisOfDay)
Returns a datetime millisecond instant, formed from the given year, month, day, and millisecond values.long
getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
Returns a datetime millisecond instant, formed from the given year, month, day, hour, minute, second, and millisecond values.private long
getDateTimeMillis0(int year, int monthOfYear, int dayOfMonth, int millisOfDay)
(package private) int
getDayOfMonth(long millis)
(package private) int
getDayOfMonth(long millis, int year)
(package private) int
getDayOfMonth(long millis, int year, int month)
(package private) int
getDayOfWeek(long instant)
(package private) int
getDayOfYear(long instant)
(package private) int
getDayOfYear(long instant, int year)
(package private) int
getDaysInMonthMax()
Gets the maximum number of days in any month.(package private) abstract int
getDaysInMonthMax(int month)
Gets the maximum days in the specified month.(package private) int
getDaysInMonthMax(long instant)
Gets the maximum number of days in the month specified by the instant.(package private) int
getDaysInMonthMaxForSet(long instant, int value)
Gets the maximum number of days in the month specified by the instant.(package private) int
getDaysInYear(int year)
Get the number of days in the year.(package private) int
getDaysInYearMax()
Get the number of days in the year.(package private) abstract int
getDaysInYearMonth(int year, int month)
Gets the number of days in the specified month and year.(package private) long
getFirstWeekOfYearMillis(int year)
Get the millis for the first week of a year.(package private) int
getMaxMonth()
Gets the maximum number of months.(package private) int
getMaxMonth(int year)
Gets the maximum month for the specified year.(package private) abstract int
getMaxYear()
Gets the maximum supported year.(package private) int
getMillisOfDay(long instant)
int
getMinimumDaysInFirstWeek()
(package private) abstract int
getMinYear()
Gets the minimum supported year.(package private) int
getMonthOfYear(long millis)
(package private) abstract int
getMonthOfYear(long millis, int year)
(package private) abstract long
getTotalMillisByYearMonth(int year, int month)
Gets the total number of millis elapsed in this year at the start of the specified month, such as zero for month 1.(package private) int
getWeekOfWeekyear(long instant)
(package private) int
getWeekOfWeekyear(long instant, int year)
(package private) int
getWeeksInYear(int year)
Get the number of weeks in the year.(package private) int
getWeekyear(long instant)
(package private) int
getYear(long instant)
(package private) abstract long
getYearDifference(long minuendInstant, long subtrahendInstant)
Gets the difference between the two instants in years.private BasicChronology.YearInfo
getYearInfo(int year)
(package private) long
getYearMillis(int year)
Get the milliseconds for the start of a year.(package private) long
getYearMonthDayMillis(int year, int month, int dayOfMonth)
Get the milliseconds for a particular date.(package private) long
getYearMonthMillis(int year, int month)
Get the milliseconds for the start of a month.DateTimeZone
getZone()
Returns the DateTimeZone that this Chronology operates in, or null if unspecified.int
hashCode()
A suitable hash code for the chronology.(package private) boolean
isLeapDay(long instant)
Is the specified instant a leap day?(package private) abstract boolean
isLeapYear(int year)
Is the specified year a leap year?(package private) abstract long
setYear(long instant, int year)
Sets the year from an instant and year.java.lang.String
toString()
Gets a debugging toString.-
Methods inherited from class org.joda.time.chrono.AssembledChronology
centuries, centuryOfEra, clockhourOfDay, clockhourOfHalfday, dayOfMonth, dayOfWeek, dayOfYear, days, era, eras, getBase, getDateTimeMillis, getParam, halfdayOfDay, halfdays, hourOfDay, hourOfHalfday, hours, millis, millisOfDay, millisOfSecond, minuteOfDay, minuteOfHour, minutes, monthOfYear, months, secondOfDay, secondOfMinute, seconds, weekOfWeekyear, weeks, weekyear, weekyearOfCentury, weekyears, year, yearOfCentury, yearOfEra, years
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization lock- See Also:
- Constant Field Values
-
cMillisField
private static final DurationField cMillisField
-
cSecondsField
private static final DurationField cSecondsField
-
cMinutesField
private static final DurationField cMinutesField
-
cHoursField
private static final DurationField cHoursField
-
cHalfdaysField
private static final DurationField cHalfdaysField
-
cDaysField
private static final DurationField cDaysField
-
cWeeksField
private static final DurationField cWeeksField
-
cMillisOfSecondField
private static final DateTimeField cMillisOfSecondField
-
cMillisOfDayField
private static final DateTimeField cMillisOfDayField
-
cSecondOfMinuteField
private static final DateTimeField cSecondOfMinuteField
-
cSecondOfDayField
private static final DateTimeField cSecondOfDayField
-
cMinuteOfHourField
private static final DateTimeField cMinuteOfHourField
-
cMinuteOfDayField
private static final DateTimeField cMinuteOfDayField
-
cHourOfDayField
private static final DateTimeField cHourOfDayField
-
cHourOfHalfdayField
private static final DateTimeField cHourOfHalfdayField
-
cClockhourOfDayField
private static final DateTimeField cClockhourOfDayField
-
cClockhourOfHalfdayField
private static final DateTimeField cClockhourOfHalfdayField
-
cHalfdayOfDayField
private static final DateTimeField cHalfdayOfDayField
-
CACHE_SIZE
private static final int CACHE_SIZE
- See Also:
- Constant Field Values
-
CACHE_MASK
private static final int CACHE_MASK
- See Also:
- Constant Field Values
-
iYearInfoCache
private final transient BasicChronology.YearInfo[] iYearInfoCache
-
iMinDaysInFirstWeek
private final int iMinDaysInFirstWeek
-
-
Constructor Detail
-
BasicChronology
BasicChronology(Chronology base, java.lang.Object param, int minDaysInFirstWeek)
-
-
Method Detail
-
getZone
public DateTimeZone getZone()
Description copied from class:BaseChronology
Returns the DateTimeZone that this Chronology operates in, or null if unspecified.- Overrides:
getZone
in classAssembledChronology
- Returns:
- DateTimeZone null if unspecified
-
getDateTimeMillis
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int millisOfDay) throws java.lang.IllegalArgumentException
Description copied from class:BaseChronology
Returns a datetime millisecond instant, formed from the given year, month, day, and millisecond values. The set of given values must refer to a valid datetime, or else an IllegalArgumentException is thrown.The default implementation calls upon separate DateTimeFields to determine the result. Subclasses are encouraged to provide a more efficient implementation.
- Overrides:
getDateTimeMillis
in classAssembledChronology
- Parameters:
year
- year to usemonthOfYear
- month to usedayOfMonth
- day of month to usemillisOfDay
- millisecond to use- Returns:
- millisecond instant from 1970-01-01T00:00:00Z
- Throws:
java.lang.IllegalArgumentException
- if the values are invalid
-
getDateTimeMillis
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) throws java.lang.IllegalArgumentException
Description copied from class:BaseChronology
Returns a datetime millisecond instant, formed from the given year, month, day, hour, minute, second, and millisecond values. The set of given values must refer to a valid datetime, or else an IllegalArgumentException is thrown.The default implementation calls upon separate DateTimeFields to determine the result. Subclasses are encouraged to provide a more efficient implementation.
- Overrides:
getDateTimeMillis
in classAssembledChronology
- Parameters:
year
- year to usemonthOfYear
- month to usedayOfMonth
- day of month to usehourOfDay
- hour to useminuteOfHour
- minute to usesecondOfMinute
- second to usemillisOfSecond
- millisecond to use- Returns:
- millisecond instant from 1970-01-01T00:00:00Z
- Throws:
java.lang.IllegalArgumentException
- if the values are invalid
-
getDateTimeMillis0
private long getDateTimeMillis0(int year, int monthOfYear, int dayOfMonth, int millisOfDay)
-
getMinimumDaysInFirstWeek
public int getMinimumDaysInFirstWeek()
-
equals
public boolean equals(java.lang.Object obj)
Checks if this chronology instance equals another.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare to- Returns:
- true if equal
- Since:
- 1.6
-
hashCode
public int hashCode()
A suitable hash code for the chronology.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
- Since:
- 1.6
-
toString
public java.lang.String toString()
Gets a debugging toString.- Specified by:
toString
in classBaseChronology
- Returns:
- a debugging string
-
assemble
protected void assemble(AssembledChronology.Fields fields)
Description copied from class:AssembledChronology
Invoked by the constructor and after deserialization to allow subclasses to define all of its supported fields. All unset fields default to unsupported instances.- Specified by:
assemble
in classAssembledChronology
- Parameters:
fields
- container of fields
-
getDaysInYearMax
int getDaysInYearMax()
Get the number of days in the year.- Returns:
- 366
-
getDaysInYear
int getDaysInYear(int year)
Get the number of days in the year.- Parameters:
year
- the year to use- Returns:
- 366 if a leap year, otherwise 365
-
getWeeksInYear
int getWeeksInYear(int year)
Get the number of weeks in the year.- Parameters:
year
- the year to use- Returns:
- number of weeks in the year
-
getFirstWeekOfYearMillis
long getFirstWeekOfYearMillis(int year)
Get the millis for the first week of a year.- Parameters:
year
- the year to use- Returns:
- millis
-
getYearMillis
long getYearMillis(int year)
Get the milliseconds for the start of a year.- Parameters:
year
- The year to use.- Returns:
- millis from 1970-01-01T00:00:00Z
-
getYearMonthMillis
long getYearMonthMillis(int year, int month)
Get the milliseconds for the start of a month.- Parameters:
year
- The year to use.month
- The month to use- Returns:
- millis from 1970-01-01T00:00:00Z
-
getYearMonthDayMillis
long getYearMonthDayMillis(int year, int month, int dayOfMonth)
Get the milliseconds for a particular date.- Parameters:
year
- The year to use.month
- The month to usedayOfMonth
- The day of the month to use- Returns:
- millis from 1970-01-01T00:00:00Z
-
getYear
int getYear(long instant)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Z
-
getMonthOfYear
int getMonthOfYear(long millis)
- Parameters:
millis
- from 1970-01-01T00:00:00Z
-
getMonthOfYear
abstract int getMonthOfYear(long millis, int year)
- Parameters:
millis
- from 1970-01-01T00:00:00Zyear
- precalculated year of millis
-
getDayOfMonth
int getDayOfMonth(long millis)
- Parameters:
millis
- from 1970-01-01T00:00:00Z
-
getDayOfMonth
int getDayOfMonth(long millis, int year)
- Parameters:
millis
- from 1970-01-01T00:00:00Zyear
- precalculated year of millis
-
getDayOfMonth
int getDayOfMonth(long millis, int year, int month)
- Parameters:
millis
- from 1970-01-01T00:00:00Zyear
- precalculated year of millismonth
- precalculated month of millis
-
getDayOfYear
int getDayOfYear(long instant)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Z
-
getDayOfYear
int getDayOfYear(long instant, int year)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Zyear
- precalculated year of millis
-
getWeekyear
int getWeekyear(long instant)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Z
-
getWeekOfWeekyear
int getWeekOfWeekyear(long instant)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Z
-
getWeekOfWeekyear
int getWeekOfWeekyear(long instant, int year)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Zyear
- precalculated year of millis
-
getDayOfWeek
int getDayOfWeek(long instant)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Z
-
getMillisOfDay
int getMillisOfDay(long instant)
- Parameters:
instant
- millis from 1970-01-01T00:00:00Z
-
getDaysInMonthMax
int getDaysInMonthMax()
Gets the maximum number of days in any month.- Returns:
- 31
-
getDaysInMonthMax
int getDaysInMonthMax(long instant)
Gets the maximum number of days in the month specified by the instant.- Parameters:
instant
- millis from 1970-01-01T00:00:00Z- Returns:
- the maximum number of days in the month
-
getDaysInMonthMaxForSet
int getDaysInMonthMaxForSet(long instant, int value)
Gets the maximum number of days in the month specified by the instant. The value represents what the user is trying to set, and can be used to optimise this method.- Parameters:
instant
- millis from 1970-01-01T00:00:00Zvalue
- the value being set- Returns:
- the maximum number of days in the month
-
getDateMidnightMillis
long getDateMidnightMillis(int year, int monthOfYear, int dayOfMonth)
Gets the milliseconds for a date at midnight.- Parameters:
year
- the yearmonthOfYear
- the monthdayOfMonth
- the day- Returns:
- the milliseconds
-
getYearDifference
abstract long getYearDifference(long minuendInstant, long subtrahendInstant)
Gets the difference between the two instants in years.- Parameters:
minuendInstant
- the first instantsubtrahendInstant
- the second instant- Returns:
- the difference
-
isLeapYear
abstract boolean isLeapYear(int year)
Is the specified year a leap year?- Parameters:
year
- the year to test- Returns:
- true if leap
-
isLeapDay
boolean isLeapDay(long instant)
Is the specified instant a leap day?- Parameters:
instant
- the instant to test- Returns:
- true if leap, default is false
-
getDaysInYearMonth
abstract int getDaysInYearMonth(int year, int month)
Gets the number of days in the specified month and year.- Parameters:
year
- the yearmonth
- the month- Returns:
- the number of days
-
getDaysInMonthMax
abstract int getDaysInMonthMax(int month)
Gets the maximum days in the specified month.- Parameters:
month
- the month- Returns:
- the max days
-
getTotalMillisByYearMonth
abstract long getTotalMillisByYearMonth(int year, int month)
Gets the total number of millis elapsed in this year at the start of the specified month, such as zero for month 1.- Parameters:
year
- the yearmonth
- the month- Returns:
- the elapsed millis at the start of the month
-
calculateFirstDayOfYearMillis
abstract long calculateFirstDayOfYearMillis(int year)
Gets the millisecond value of the first day of the year.- Returns:
- the milliseconds for the first of the year
-
getMinYear
abstract int getMinYear()
Gets the minimum supported year.- Returns:
- the year
-
getMaxYear
abstract int getMaxYear()
Gets the maximum supported year.- Returns:
- the year
-
getMaxMonth
int getMaxMonth(int year)
Gets the maximum month for the specified year. This implementation calls getMaxMonth().- Parameters:
year
- the year- Returns:
- the maximum month value
-
getMaxMonth
int getMaxMonth()
Gets the maximum number of months.- Returns:
- 12
-
getAverageMillisPerYear
abstract long getAverageMillisPerYear()
Gets an average value for the milliseconds per year.- Returns:
- the millis per year
-
getAverageMillisPerYearDividedByTwo
abstract long getAverageMillisPerYearDividedByTwo()
Gets an average value for the milliseconds per year, divided by two.- Returns:
- the millis per year divided by two
-
getAverageMillisPerMonth
abstract long getAverageMillisPerMonth()
Gets an average value for the milliseconds per month.- Returns:
- the millis per month
-
getApproxMillisAtEpochDividedByTwo
abstract long getApproxMillisAtEpochDividedByTwo()
Returns a constant representing the approximate number of milliseconds elapsed from year 0 of this chronology, divided by two. This constant must be defined as:(yearAtEpoch * averageMillisPerYear + millisOfYearAtEpoch) / 2
where epoch is 1970-01-01 (Gregorian).
-
setYear
abstract long setYear(long instant, int year)
Sets the year from an instant and year.- Parameters:
instant
- millis from 1970-01-01T00:00:00Zyear
- the year to set- Returns:
- the updated millis
-
getYearInfo
private BasicChronology.YearInfo getYearInfo(int year)
-
-