Class OceanusDate
java.lang.Object
io.github.tonywasher.joceanus.oceanus.date.OceanusDate
- All Implemented Interfaces:
Comparable<OceanusDate>
Represents a Date object that is fixed to a particular day. There is no concept of time within
the day Calendar objects that are built to represent the Date are set to noon on the day in
question.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intThe Hash prime.protected static final intThe Number of months in a Quarter.protected static final intThe Year shift for DateDay Id. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new Date and initialise with today's date.OceanusDate(int pYear, int pMonth, int pDay) Construct an explicit Date.OceanusDate(int pYear, int pMonth, int pDay, Locale pLocale) Construct an explicit Date for a locale.OceanusDate(int pYear, Month pMonth, int pDay) Construct an explicit Date.OceanusDate(int pYear, Month pMonth, int pDay, Locale pLocale) Construct an explicit Date for a locale.OceanusDate(OceanusDate pDate) Construct a new Date and initialise from a date.OceanusDate(String pValue) Construct a Date from a formatted string.OceanusDate(String pValue, Locale pLocale) Construct a Date from a formatted string.OceanusDate(String pValue, Locale pLocale, String pFormat) Construct a Date from a formatted string.OceanusDate(LocalDate pDate) Construct a new Date and initialise from a java date.OceanusDate(LocalDate pDate, Locale pLocale) Construct a new Date and initialise from a java date.OceanusDate(Date pDate) Construct a new Date and initialise from a java date.OceanusDate(Date pDate, Locale pLocale) Construct a new Date and initialise from a java date.OceanusDate(Locale pLocale) Construct a new Date and initialise with todays date. -
Method Summary
Modifier and TypeMethodDescriptionvoidadjustBackwardByPeriod(OceanusDatePeriod pPeriod) Adjust the date by a period in a backward direction.voidadjustDay(int iDay) Adjust the date by a number of days.voidadjustField(TemporalUnit iField, int iUnits) Adjust the date by a determined amount.voidadjustForwardByPeriod(OceanusDatePeriod pPeriod) Adjust the date by a period in a forward direction.voidadjustMonth(int iMonth) Adjust the date by a number of months.voidadjustYear(int iYear) Adjust the date by a number of years.intageOn(OceanusDate pDate) Calculate the age that someone born on this date will be on a given date.intcompareTo(OceanusDate pThat) intcompareToRange(OceanusDateRange pRange) Compare this date to a range.voidcopyDate(OceanusDate pDate) Copy a date from another DateDay.longdaysUntil(OceanusDate pDate) Calculate the days until the specified date.voidAdjust the date to the end of the month.voidAdjust the date to the end of the year.voidAdjust the date to the end of the following month.booleangetDate()Get the Date associated with this object.intgetDay()Get the day of the date.Get the day of the week.intgetId()Get the id of the date.Get the locale associated with this object.intgetMonth()Get the month of the date.Get the month value.intgetYear()Get the year of the date.inthashCode()static booleanisDifferent(OceanusDate pCurr, OceanusDate pNew) Determine whether two DateDay objects differ.voidSet the date format.voidSet locale for the DateDay.voidAdjust the date to the start of the month.voidAdjust the date to the start of the quarter.voidAdjust the date to the start of the year.voidAdjust the date to the start of the fiscal year.voidstartPeriod(OceanusDatePeriod pPeriod) Adjust the date to the start of the period.Convert the LocalDate to a Calendar.toDate()Convert the LocalDate to a Date.toString()
-
Field Details
-
HASH_PRIME
protected static final int HASH_PRIMEThe Hash prime.- See Also:
-
SHIFT_ID_YEAR
protected static final int SHIFT_ID_YEARThe Year shift for DateDay Id. This is 9 corresponding to (1 shiftLeft 9 places) = 512- See Also:
-
MONTHS_IN_QUARTER
protected static final int MONTHS_IN_QUARTERThe Number of months in a Quarter.- See Also:
-
-
Constructor Details
-
OceanusDate
public OceanusDate()Construct a new Date and initialise with today's date. -
OceanusDate
Construct a new Date and initialise with todays date.- Parameters:
pLocale- the locale
-
OceanusDate
Construct a new Date and initialise from a java date.- Parameters:
pDate- the java date to initialise from
-
OceanusDate
Construct a new Date and initialise from a java date.- Parameters:
pDate- the java date to initialise frompLocale- the locale for this date
-
OceanusDate
Construct a new Date and initialise from a java date.- Parameters:
pDate- the java calendar to initialise from
-
OceanusDate
Construct a new Date and initialise from a java date.- Parameters:
pDate- the java date to initialise frompLocale- the locale for this date
-
OceanusDate
Construct a new Date and initialise from a date.- Parameters:
pDate- the finance date to initialise from
-
OceanusDate
public OceanusDate(int pYear, int pMonth, int pDay) Construct an explicit Date.- Parameters:
pYear- the yearpMonth- the month (1 to 12 etc)pDay- the day of the month
-
OceanusDate
Construct an explicit Date.- Parameters:
pYear- the yearpMonth- the month (Month.JUNE etc)pDay- the day of the month
-
OceanusDate
Construct an explicit Date for a locale.- Parameters:
pYear- the yearpMonth- the month (1 to 12 etc)pDay- the day of the monthpLocale- the locale for this date
-
OceanusDate
Construct an explicit Date for a locale.- Parameters:
pYear- the yearpMonth- the month (Month.JUNE etc)pDay- the day of the monthpLocale- the locale for this date
-
OceanusDate
Construct a Date from a formatted string.- Parameters:
pValue- the formatted string
-
OceanusDate
Construct a Date from a formatted string.- Parameters:
pValue- the formatted stringpLocale- the locale for this date
-
OceanusDate
Construct a Date from a formatted string.- Parameters:
pValue- the formatted stringpLocale- the locale for this datepFormat- the format to use for parsing
-
-
Method Details
-
getYear
public int getYear()Get the year of the date.- Returns:
- the year of the date
-
getMonth
public int getMonth()Get the month of the date.- Returns:
- the month of the date
-
getDay
public int getDay()Get the day of the date.- Returns:
- the day of the date
-
getDayOfWeek
Get the day of the week.- Returns:
- the day of the week
-
getMonthValue
Get the month value.- Returns:
- the month value
-
getId
public int getId()Get the id of the date. This is a unique integer representation of the date usable as an id for the date.- Returns:
- the id of the date
-
getDate
Get the Date associated with this object.- Returns:
- the date
-
getLocale
Get the locale associated with this object.- Returns:
- the java locale
-
setLocale
Set locale for the DateDay.- Parameters:
pLocale- the locale
-
setFormat
Set the date format.- Parameters:
pFormat- the format string
-
adjustYear
public void adjustYear(int iYear) Adjust the date by a number of years.- Parameters:
iYear- the number of years to adjust by
-
adjustMonth
public void adjustMonth(int iMonth) Adjust the date by a number of months.- Parameters:
iMonth- the number of months to adjust by
-
adjustDay
public void adjustDay(int iDay) Adjust the date by a number of days.- Parameters:
iDay- the number of days to adjust by
-
adjustField
Adjust the date by a determined amount.- Parameters:
iField- the field to adjustiUnits- the number of units to adjust by
-
adjustForwardByPeriod
Adjust the date by a period in a forward direction.- Parameters:
pPeriod- the period to adjust by
-
adjustBackwardByPeriod
Adjust the date by a period in a backward direction.- Parameters:
pPeriod- the period to adjust by
-
startPeriod
Adjust the date to the start of the period.- Parameters:
pPeriod- the period to adjust by
-
endNextMonth
public void endNextMonth()Adjust the date to the end of the following month. -
startCalendarMonth
public void startCalendarMonth()Adjust the date to the start of the month. -
endCalendarMonth
public void endCalendarMonth()Adjust the date to the end of the month. -
startCalendarQuarter
public void startCalendarQuarter()Adjust the date to the start of the quarter. -
startCalendarYear
public void startCalendarYear()Adjust the date to the start of the year. -
endCalendarYear
public void endCalendarYear()Adjust the date to the end of the year. -
startFiscalYear
public void startFiscalYear()Adjust the date to the start of the fiscal year. -
ageOn
Calculate the age that someone born on this date will be on a given date.- Parameters:
pDate- the date for which to calculate the age- Returns:
- the age on that date
-
daysUntil
Calculate the days until the specified date.- Parameters:
pDate- the date for which to days until- Returns:
- the days until that date
-
copyDate
Copy a date from another DateDay.- Parameters:
pDate- the date to copy from
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<OceanusDate>
-
compareToRange
Compare this date to a range.- Parameters:
pRange- the range to compare to- Returns:
- -1 if date is before range, 0 if date is within range, 1 if date is after range
-
equals
-
hashCode
public int hashCode() -
toDate
Convert the LocalDate to a Date.- Returns:
- the associated date
-
toCalendar
Convert the LocalDate to a Calendar.- Returns:
- the Calendar
-
isDifferent
Determine whether two DateDay objects differ.- Parameters:
pCurr- The current DatepNew- The new Date- Returns:
trueif the objects differ,falseotherwise
-