public abstract class CalendarMetrics
extends java.lang.Object
Please note that most methods use a packed month instead of just a month number. That's due to the need to specify leap months in certain
calendaring systems. Do not make any assumptions about the format of the packed month since this is an internal implementation detail. To get the
actual month number and the leap month flag use monthNum(int) and isLeapMonth(int).
However, packed months are integers that are guaranteed to be comparable with respect to their natural order. So if a and b are two
packed months, it's guaranteed that a<b if a comes before b in the year.
| Modifier and Type | Class and Description |
|---|---|
static class |
CalendarMetrics.CalendarMetricsFactory |
| Modifier and Type | Field and Description |
|---|---|
int |
minDaysInFirstWeek
The minimal number of days in the first week.
|
Weekday |
weekStart
The first day of the week.
|
int |
weekStartInt
The first day of the week int.
|
| Constructor and Description |
|---|
CalendarMetrics(java.lang.String name,
Weekday weekStart,
int minDaysInFirstWeek) |
| Modifier and Type | Method and Description |
|---|---|
static int |
dayOfMonth(int monthAndDay)
Get the day of month from a compound MonthAndDay value like
getMonthAndDayOfYearDay(int, int) and monthAndDay(int, int) return it. |
boolean |
equals(java.lang.Object obj)
By default two
CalendarMetrics equal when they are of the same class and the week definition equals. |
abstract int |
getDayOfMonthOfYearDay(int year,
int yearDay)
Determines the day of month for a given day of year.
|
int |
getDayOfWeek(int year,
int yearDay)
Returns the day of week of the given year date.
|
int |
getDayOfWeek(int year,
int packedMonth,
int dayOfMonth)
Returns the day of week of the given date.
|
abstract int |
getDayOfYear(int year,
int packedMonth,
int dayOfMonth)
Get the day of the year for the specified date.
|
abstract int |
getDaysPerPackedMonth(int year,
int packedMonth)
Get the number of days in a specific packed month.
|
abstract int |
getDaysPerYear(int year)
Get the number of days in the given year.
|
abstract int |
getMaxMonthDayNum()
Returns the largest month day number that the current calendar supports.
|
abstract int |
getMaxWeekNoNum()
Returns the largest week number that the current calendar supports.
|
abstract int |
getMaxYearDayNum()
Returns the largest year day number that the current calendar supports.
|
abstract int |
getMonthAndDayOfYearDay(int year,
int yearDay)
Determines the month and day for a given day of year.
|
abstract int |
getMonthsPerYear(int year)
Get the number of months in the given year.
|
abstract int |
getPackedMonthOfYearDay(int year,
int yearDay)
Determines the month of a given day of year.
|
abstract int |
getWeekDayOfFirstYearDay(int year)
Get the weekday of the first day (which is January the 1st in a Gregorian Calendar) in the given year.
|
abstract int |
getWeekOfYear(int year,
int yearDay)
Get the ISO week number of the given date.
|
int |
getWeekOfYear(int year,
int packedMonth,
int dayOfMonth)
Get the ISO week number of the given date.
|
abstract int |
getWeeksPerYear(int year)
Get the number of ISO weeks in the given year.
|
abstract int |
getYearDayOfFirstWeekStart(int year)
Get the day of year of the start of the first week in a year.
|
abstract int |
getYearDayOfIsoYear(int year,
int weekOfYear,
int dayOfWeek)
Get the day of the year for the specified ISO week date, see ISO week date
If the day belongs to the previous year zero or a negative value is returned.
|
abstract int |
getYearDayOfWeekStart(int year,
int week)
Get the day of year of the start of the given week in a year.
|
abstract int |
getYearDaysForPackedMonth(int year,
int packedMonth)
Get the number of days preceding the given month in the given year.
|
int |
hashCode() |
boolean |
isLeapMonth(int packedMonth)
Returns whether a certain packed month is a leap month, i.e. a month that exists in certain years only.
|
static int |
monthAndDay(int packedMonth,
int day)
Returns a packed value that contains a packed month and a month day.
|
int |
monthNum(int packedMonth)
Returns the month number of a packed month.
|
abstract long |
nextDay(long instance)
Moves the given instance forward to the next (existing day).
|
abstract long |
nextDay(long instance,
int n)
Moves the given instance forward by one or more days.
|
abstract long |
nextMonth(long instance)
Moves the given instance forward by one month.
|
abstract long |
nextMonth(long instance,
int n)
Moves the given instance forward by one or more months.
|
static int |
packedMonth(int monthAndDay)
Get the packed month from a compound MonthAndDay value like
getMonthAndDayOfYearDay(int, int) and monthAndDay(int, int) return it. |
int |
packedMonth(int monthNum,
boolean leapMonth)
Returns a packed month, which is a combination of the month number and a leap month flag.
|
int |
packedMonth(java.lang.String month)
Returns a packed month from a string representation.
|
java.lang.String |
packedMonthToString(int packedMonth)
Convert the packed month to a numerical string representation.
|
abstract long |
prevDay(long instance)
Moves the given instance backward to the previous (existing) day.
|
abstract long |
prevDay(long instance,
int n)
Moves the given instance backward by one or more days.
|
abstract long |
prevMonth(long instance)
Moves the given instance backward by one month.
|
abstract long |
prevMonth(long instance,
int n)
Moves the given instance backward by one or more months.
|
boolean |
scaleEquals(CalendarMetrics obj)
Returns whether two
CalendarMetrics implement the same calendar scale. |
long |
setDayOfWeek(long instance,
int dayOfWeek)
Changes the day of week of the given instance ot the given value, but keeping the week number constant
|
long |
startOfWeek(long instance)
Get the start date of the week the given instance is in.
|
abstract long |
toInstance(long timestamp,
java.util.TimeZone timeZone)
Converts a timestamp to an instance in the given
TimeZone. |
long |
toMillis(long instance,
java.util.TimeZone timeZone)
Convert an instance to milliseconds since the epoch (i.e. since 1970-01-01 0:00:00 UTC).
|
abstract long |
toMillis(java.util.TimeZone timeZone,
int year,
int packedMonth,
int dayOfMonth,
int hours,
int minutes,
int seconds,
int millis)
Convert the given (local) date to milliseconds since the epoch using the given
TimeZone. |
java.lang.String |
toString() |
boolean |
validate(long instance)
Validates the given instance.
|
public final Weekday weekStart
public final int weekStartInt
public final int minDaysInFirstWeek
public CalendarMetrics(java.lang.String name,
Weekday weekStart,
int minDaysInFirstWeek)
public static int monthAndDay(int packedMonth,
int day)
packedMonth - The packed month.day - The day of month.packedMonth(int),
dayOfMonth(int)public static int packedMonth(int monthAndDay)
getMonthAndDayOfYearDay(int, int) and monthAndDay(int, int) return it.monthAndDay - An integer that contains a packed month and a day.public static int dayOfMonth(int monthAndDay)
getMonthAndDayOfYearDay(int, int) and monthAndDay(int, int) return it.monthAndDay - An integer that contains a packed month and a day.public int packedMonth(java.lang.String month)
The string representation is the 1-based month number followed by an optional L literal to indicate a leap month.
month - The string representation of the month.java.lang.IllegalArgumentException - if the given (leap-) month does not exist in this calendar scale or the month string is otherwise malformed.public java.lang.String packedMonthToString(int packedMonth)
packedMonth - The packed month.public int packedMonth(int monthNum,
boolean leapMonth)
Note that not all calendar scales support leap months.
monthNum - The 0-based month number.leapMonth - true if this is a leap month, false otherwise.java.lang.IllegalArgumentException - if the given (leap-) month does not exist in this calendar scale.public boolean isLeapMonth(int packedMonth)
packedMonth - The packed month to test.true if the month is a leap month, false otherwise.public int monthNum(int packedMonth)
packedMonth - The packed month.public abstract int getMaxMonthDayNum()
public abstract int getMaxYearDayNum()
public abstract int getMaxWeekNoNum()
public abstract int getDaysPerPackedMonth(int year,
int packedMonth)
year - The year.packedMonth - The packed month.public abstract int getPackedMonthOfYearDay(int year,
int yearDay)
year - The year.yearDay - The year day.public abstract int getDayOfMonthOfYearDay(int year,
int yearDay)
year - The year.yearDay - The year day.public abstract int getMonthAndDayOfYearDay(int year,
int yearDay)
packedMonth(int) and dayOfMonth(int) like in:
int monthAndDay = mCalendarMetrics.getMonthAndDayOfYearDay(year, yearDay); int month = CalendarMetrics.packedMonth(monthAndDay); int dayOfMonth = CalendarMetrics.dayOfMonth(monthAndDay);
year - The year.yearDay - The day of the year. Must be a valid value between 1 and the maximum number of days in that year.public abstract int getYearDaysForPackedMonth(int year,
int packedMonth)
year - The year.packedMonth - The packed month.public abstract int getMonthsPerYear(int year)
year - The year.public abstract int getDaysPerYear(int year)
year - The year.public abstract int getWeeksPerYear(int year)
year - The year.public int getWeekOfYear(int year,
int packedMonth,
int dayOfMonth)
Note: this will return 0 if the week belongs to the previous ISO year and a value greater than getWeeksPerYear(int) if the week
belongs to the next ISO year.
year - The year.packedMonth - The packed month.dayOfMonth - The day of month.public abstract int getWeekOfYear(int year,
int yearDay)
Note: this will return 0 if the week belongs to the previous ISO year and a value greater than getWeeksPerYear(int) if the week
belongs to the next ISO year.
year - The year.yearDay - The day of year.public int getDayOfWeek(int year,
int yearDay)
year - The year.yearDay - The day of the year.0 means Sunday and 6 means Saturday or the respective week days in the
respective calendar scale.public int getDayOfWeek(int year,
int packedMonth,
int dayOfMonth)
year - The year.packedMonth - The packed month number.dayOfMonth - The day of the month.0 means Sunday and 6 means Saturday or the respective week days in the respective
calendar scale.public abstract int getDayOfYear(int year,
int packedMonth,
int dayOfMonth)
year - The year.packedMonth - The packed month.dayOfMonth - The day of month.public abstract int getYearDayOfIsoYear(int year,
int weekOfYear,
int dayOfWeek)
If the day belongs to the previous year zero or a negative value is returned. If the day belongs to the next year the result is larger than getDaysPerYear(int) for year.
year - The year.weekOfYear - The ISO week of the year.dayOfWeek - The day of the week.public abstract int getWeekDayOfFirstYearDay(int year)
year - The year.public abstract int getYearDayOfFirstWeekStart(int year)
weekStart and minDaysInFirstWeek.year - The year.public abstract int getYearDayOfWeekStart(int year,
int week)
weekStart and minDaysInFirstWeek.year - The year.week - The week.public long toMillis(long instance,
java.util.TimeZone timeZone)
instance - The instance to convert.timeZone - The time zone or null for all day and floating instances.public abstract long toMillis(java.util.TimeZone timeZone,
int year,
int packedMonth,
int dayOfMonth,
int hours,
int minutes,
int seconds,
int millis)
TimeZone.timeZone - The time zone or null for floating dates (and all-day dates).year - The year.packedMonth - The packed month.dayOfMonth - The day of the month.hours - The hour of the day.minutes - The minutes.seconds - The seconds.millis - The milliseconds.public abstract long toInstance(long timestamp,
java.util.TimeZone timeZone)
TimeZone.timestamp - The time in milliseconds since the epoch.timeZone - The time zone, may be null in which case UTC will be used.public boolean validate(long instance)
At present this method doesn't check for leap seconds and it doesn't honor daylight saving switches. So it validates times between 2:00h and 3:00 to
true even if the local time can't have these values due to daylight savings.
instance - The instance to validate.true if the date is valid, false otherwise.public abstract long nextMonth(long instance)
nextMonth(long, int) with n = 1.instance - The instance to modify.public abstract long nextMonth(long instance,
int n)
instance - The instance to modify.n - The number of months to add.public abstract long prevMonth(long instance)
prevMonth(long, int) with n = 1.instance - The instance to modify.public abstract long prevMonth(long instance,
int n)
instance - The instance to modify.n - The number of months to go back.public abstract long nextDay(long instance)
instance - The instance to modify.public abstract long nextDay(long instance,
int n)
instance - The instance to modify.n - The number of days to add.public abstract long prevDay(long instance)
instance - The instance to modify.public abstract long prevDay(long instance,
int n)
instance - The instance to modify.n - The number of days to go back.public long startOfWeek(long instance)
instance - The instance.public long setDayOfWeek(long instance,
int dayOfWeek)
instance - The instance to modify.dayOfWeek - The new day of the week.public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
CalendarMetrics equal when they are of the same class and the week definition equals. Subclasses may override this to change this
behavior, i.e. Islamic calendars need to match the leap year rule as well.equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean scaleEquals(CalendarMetrics obj)
CalendarMetrics implement the same calendar scale.
By default two CalendarMetrics use the same calendar scale when they are of the same class. Subclasses may override this to change this behavior,
i.e. Islamic calendars need to match the leap year rule as well.