Package com.squarespace.cldrengine.api
Class CalendarDate
- java.lang.Object
-
- com.squarespace.cldrengine.api.CalendarDate
-
- Direct Known Subclasses:
GregorianDate
,PersianDate
public abstract class CalendarDate extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CalendarDate.Swap
-
Constructor Summary
Constructors Modifier Constructor Description protected
CalendarDate(CalendarType type, int firstDay, int minDays)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Pair<java.lang.Long,java.lang.Double>
_add(TimePeriod fields)
Compute a new Julian day and milliseconds UTC by updating one or more fields.protected Pair<java.lang.Long,java.lang.Double>
_addTime(TimePeriod fields)
Converts all time fields into [days, milliseconds].protected void
_computeWeekFields(int woyfield, int ywoyfield, long firstDay, long minDays, long dow, long dom, long doy)
protected TimePeriod
_diff(CalendarDate s, long[] sf, long[] ef)
Compute the number of years, months, days, etc, between two dates.protected TimePeriod
_rollup(TimePeriod span, long[] sf, long[] ef, java.util.List<TimePeriodField> fields)
Roll up time period fields into a subset of fields.protected java.lang.String
_toString(java.lang.String type)
abstract CalendarDate
add(TimePeriod fields)
protected long
checkJDRange(long jd)
int
compare(CalendarDate other)
Compare two dates a and b, returning: a < b -> -1 a = b -> 0 a > b -> 1protected void
computeBaseFields(long[] f)
Compute fields common to all calendars.protected void
computeWeekFields()
Compute WEEK_OF_YEAR and YEAR_WOY on demand.long
dayOfMonth()
long
dayOfWeek()
Day of the week.long
dayOfWeekInMonth()
Ordinal number indicating the day of the week in the current month.long
dayOfYear()
protected abstract int
daysInMonth(long year, int month)
protected abstract int
daysInYear(long year)
TimePeriod
difference(CalendarDate other, java.util.List<TimePeriodField> fields)
Calculate the time period between two dates.long
era()
long
extendedYear()
DateTimePatternFieldType
fieldOfVisualDifference(CalendarDate other)
Computes the field of visual difference between the two dates.int
firstDayOfWeek()
protected double
getRelativeField(TimePeriod period, TimePeriodField field)
long
hour()
Indicates the hour of the morning or afternoon, used for the 12-hour clock (0 - 11).long
hourOfDay()
Indicates the hour of the day, used for the 24-hour clock (0 - 23).protected abstract void
initFields(long[] f)
protected void
initFromJD(long jd, long msDay, java.lang.String zoneId)
protected void
initFromUnixEpoch(long ms, java.lang.String zoneId)
protected TimePeriod
invertPeriod(TimePeriod f)
boolean
isAM()
boolean
isDaylightSavings()
boolean
isLeapYear()
protected void
jdFromUnixEpoch(long ms, long[] f)
Compute Julian day from timezone-adjusted Unix epoch milliseconds.double
julianDay()
Returns a floating point number representing the real Julian Day, UTC.protected TimePeriodField
largestRelativeField(TimePeriod p)
java.lang.String
metaZoneId()
long
milliseconds()
long
millisecondsInDay()
int
minDaysInFirstWeek()
long
minute()
Indicates the minute of the hour (0 - 59).long
modifiedJulianDay()
CLDR's modified Julian day used as the basis for all date calculations.long
month()
Ordinal month, one-based, e.g.protected abstract int
monthCount()
protected abstract long
monthStart(long eyear, double month, boolean useMonth)
long
ordinalDayOfWeek()
Ordinal day of the week.long
relatedYear()
Pair<TimePeriodField,java.lang.Double>
relativeTime(CalendarDate other, TimePeriodField field)
Calculate the relative time between two dates.long
second()
Indicates the second of the minute (0 - 59).protected Pair<java.lang.Long,java.lang.Double>
splitfrac(double n)
abstract CalendarDate
subtract(TimePeriod fields)
protected CalendarDate.Swap
swap(CalendarDate other)
protected int
timePeriodFieldFlags(java.util.List<TimePeriodField> fields)
java.lang.String
timeZoneAbbr()
java.lang.String
timeZoneId()
int
timeZoneOffset()
java.lang.String
timeZoneStableId()
CalendarType
type()
Calendar type for this date, e.g.long
unixEpoch()
Unix epoch with no timezone offset.protected long
unixEpochFromJD(long jd, long msDay)
Given a Julian day and local milliseconds (in UTC), return the Unix epoch milliseconds UTC.protected long[]
utcfields()
protected static long
weekNumber(long firstDay, long minDays, long desiredDay, long dayOfPeriod, long dayOfWeek)
long
weekOfMonth()
Returns the week of the month computed using the locale's 'first day of week' and 'minimal days in first week' where applicable.long
weekOfYear()
long
weekOfYearISO()
abstract CalendarDate
withZone(java.lang.String zoneId)
long
year()
protected long
yearLength(long y)
long
yearOfWeekOfYear()
long
yearOfWeekOfYearISO()
-
-
-
Field Detail
-
fields
protected final long[] fields
-
type
protected final CalendarType type
-
firstDay
protected final int firstDay
-
minDays
protected final int minDays
-
zoneInfo
protected ZoneInfo zoneInfo
-
-
Constructor Detail
-
CalendarDate
protected CalendarDate(CalendarType type, int firstDay, int minDays)
-
-
Method Detail
-
type
public CalendarType type()
Calendar type for this date, e.g. 'gregory' for Gregorian.
-
unixEpoch
public long unixEpoch()
Unix epoch with no timezone offset.
-
firstDayOfWeek
public int firstDayOfWeek()
-
minDaysInFirstWeek
public int minDaysInFirstWeek()
-
julianDay
public double julianDay()
Returns a floating point number representing the real Julian Day, UTC.
-
modifiedJulianDay
public long modifiedJulianDay()
CLDR's modified Julian day used as the basis for all date calculations.
-
era
public long era()
-
extendedYear
public long extendedYear()
-
year
public long year()
-
relatedYear
public long relatedYear()
-
yearOfWeekOfYear
public long yearOfWeekOfYear()
-
weekOfYear
public long weekOfYear()
-
yearOfWeekOfYearISO
public long yearOfWeekOfYearISO()
-
weekOfYearISO
public long weekOfYearISO()
-
month
public long month()
Ordinal month, one-based, e.g. Gregorian JANUARY = 1.
-
weekOfMonth
public long weekOfMonth()
Returns the week of the month computed using the locale's 'first day of week' and 'minimal days in first week' where applicable. For example, for the United States, weeks start on Sunday. Saturday 9/1/2018 would be in week 1, and Sunday 9/2/2018 would begin week 2. September Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
-
dayOfYear
public long dayOfYear()
-
dayOfWeek
public long dayOfWeek()
Day of the week. 1 = SUNDAY, 2 = MONDAY, ..., 7 = SATURDAY
-
ordinalDayOfWeek
public long ordinalDayOfWeek()
Ordinal day of the week. 1 if this is the 1st day of the week, 2 if the 2nd, etc. Depends on the local starting day of the week.
-
dayOfWeekInMonth
public long dayOfWeekInMonth()
Ordinal number indicating the day of the week in the current month. The result of this method can be used to format messages like "2nd Sunday in August".
-
dayOfMonth
public long dayOfMonth()
-
isAM
public boolean isAM()
-
hour
public long hour()
Indicates the hour of the morning or afternoon, used for the 12-hour clock (0 - 11). Noon and midnight are 0, not 12.
-
hourOfDay
public long hourOfDay()
Indicates the hour of the day, used for the 24-hour clock (0 - 23). Noon is 12 and midnight is 0.
-
minute
public long minute()
Indicates the minute of the hour (0 - 59).
-
second
public long second()
Indicates the second of the minute (0 - 59).
-
milliseconds
public long milliseconds()
-
millisecondsInDay
public long millisecondsInDay()
-
metaZoneId
public java.lang.String metaZoneId()
-
timeZoneId
public java.lang.String timeZoneId()
-
timeZoneStableId
public java.lang.String timeZoneStableId()
-
timeZoneOffset
public int timeZoneOffset()
-
timeZoneAbbr
public java.lang.String timeZoneAbbr()
-
isLeapYear
public boolean isLeapYear()
-
isDaylightSavings
public boolean isDaylightSavings()
-
fieldOfVisualDifference
public DateTimePatternFieldType fieldOfVisualDifference(CalendarDate other)
Computes the field of visual difference between the two dates. Note: This assumes the dates are of the same type and have the same timezone offset.
-
compare
public int compare(CalendarDate other)
Compare two dates a and b, returning: a < b -> -1 a = b -> 0 a > b -> 1
-
relativeTime
public Pair<TimePeriodField,java.lang.Double> relativeTime(CalendarDate other, TimePeriodField field)
Calculate the relative time between two dates. If a field is specified the time will be calculated in terms of that single field. Otherwise the field of greatest difference will be used.
-
difference
public TimePeriod difference(CalendarDate other, java.util.List<TimePeriodField> fields)
Calculate the time period between two dates. Note this returns the absolute value.
-
add
public abstract CalendarDate add(TimePeriod fields)
-
subtract
public abstract CalendarDate subtract(TimePeriod fields)
-
withZone
public abstract CalendarDate withZone(java.lang.String zoneId)
-
initFields
protected abstract void initFields(long[] f)
-
monthCount
protected abstract int monthCount()
-
daysInMonth
protected abstract int daysInMonth(long year, int month)
-
daysInYear
protected abstract int daysInYear(long year)
-
monthStart
protected abstract long monthStart(long eyear, double month, boolean useMonth)
-
largestRelativeField
protected TimePeriodField largestRelativeField(TimePeriod p)
-
getRelativeField
protected double getRelativeField(TimePeriod period, TimePeriodField field)
-
invertPeriod
protected TimePeriod invertPeriod(TimePeriod f)
-
swap
protected CalendarDate.Swap swap(CalendarDate other)
-
_rollup
protected TimePeriod _rollup(TimePeriod span, long[] sf, long[] ef, java.util.List<TimePeriodField> fields)
Roll up time period fields into a subset of fields.
-
_diff
protected TimePeriod _diff(CalendarDate s, long[] sf, long[] ef)
Compute the number of years, months, days, etc, between two dates. The result will have all fields as integers.
-
timePeriodFieldFlags
protected int timePeriodFieldFlags(java.util.List<TimePeriodField> fields)
-
_add
protected Pair<java.lang.Long,java.lang.Double> _add(TimePeriod fields)
Compute a new Julian day and milliseconds UTC by updating one or more fields.
-
_addTime
protected Pair<java.lang.Long,java.lang.Double> _addTime(TimePeriod fields)
Converts all time fields into [days, milliseconds].
-
splitfrac
protected Pair<java.lang.Long,java.lang.Double> splitfrac(double n)
-
initFromUnixEpoch
protected void initFromUnixEpoch(long ms, java.lang.String zoneId)
-
initFromJD
protected void initFromJD(long jd, long msDay, java.lang.String zoneId)
-
_toString
protected java.lang.String _toString(java.lang.String type)
-
computeWeekFields
protected void computeWeekFields()
Compute WEEK_OF_YEAR and YEAR_WOY on demand.
-
_computeWeekFields
protected void _computeWeekFields(int woyfield, int ywoyfield, long firstDay, long minDays, long dow, long dom, long doy)
-
yearLength
protected long yearLength(long y)
-
weekNumber
protected static long weekNumber(long firstDay, long minDays, long desiredDay, long dayOfPeriod, long dayOfWeek)
-
utcfields
protected long[] utcfields()
-
jdFromUnixEpoch
protected void jdFromUnixEpoch(long ms, long[] f)
Compute Julian day from timezone-adjusted Unix epoch milliseconds.
-
unixEpochFromJD
protected long unixEpochFromJD(long jd, long msDay)
Given a Julian day and local milliseconds (in UTC), return the Unix epoch milliseconds UTC.
-
computeBaseFields
protected void computeBaseFields(long[] f)
Compute fields common to all calendars. Before calling this, we must have the JULIAN_DAY and MILLIS_IN_DAY fields set. Every calculation is relative to these.
-
checkJDRange
protected long checkJDRange(long jd)
-
-