java.lang.Object
io.github.tonywasher.joceanus.oceanus.date.OceanusDate
All Implemented Interfaces:
Comparable<OceanusDate>

public class OceanusDate extends Object implements 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 Details

    • HASH_PRIME

      protected static final int HASH_PRIME
      The Hash prime.
      See Also:
    • SHIFT_ID_YEAR

      protected static final int SHIFT_ID_YEAR
      The 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_QUARTER
      The Number of months in a Quarter.
      See Also:
  • Constructor Details

    • OceanusDate

      public OceanusDate()
      Construct a new Date and initialise with today's date.
    • OceanusDate

      public OceanusDate(Locale pLocale)
      Construct a new Date and initialise with todays date.
      Parameters:
      pLocale - the locale
    • OceanusDate

      public OceanusDate(LocalDate pDate)
      Construct a new Date and initialise from a java date.
      Parameters:
      pDate - the java date to initialise from
    • OceanusDate

      public OceanusDate(LocalDate pDate, Locale pLocale)
      Construct a new Date and initialise from a java date.
      Parameters:
      pDate - the java date to initialise from
      pLocale - the locale for this date
    • OceanusDate

      public OceanusDate(Date pDate)
      Construct a new Date and initialise from a java date.
      Parameters:
      pDate - the java calendar to initialise from
    • OceanusDate

      public OceanusDate(Date pDate, Locale pLocale)
      Construct a new Date and initialise from a java date.
      Parameters:
      pDate - the java date to initialise from
      pLocale - the locale for this date
    • OceanusDate

      public OceanusDate(OceanusDate pDate)
      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 year
      pMonth - the month (1 to 12 etc)
      pDay - the day of the month
    • OceanusDate

      public OceanusDate(int pYear, Month pMonth, int pDay)
      Construct an explicit Date.
      Parameters:
      pYear - the year
      pMonth - the month (Month.JUNE etc)
      pDay - the day of the month
    • OceanusDate

      public OceanusDate(int pYear, int pMonth, int pDay, Locale pLocale)
      Construct an explicit Date for a locale.
      Parameters:
      pYear - the year
      pMonth - the month (1 to 12 etc)
      pDay - the day of the month
      pLocale - the locale for this date
    • OceanusDate

      public OceanusDate(int pYear, Month pMonth, int pDay, Locale pLocale)
      Construct an explicit Date for a locale.
      Parameters:
      pYear - the year
      pMonth - the month (Month.JUNE etc)
      pDay - the day of the month
      pLocale - the locale for this date
    • OceanusDate

      public OceanusDate(String pValue)
      Construct a Date from a formatted string.
      Parameters:
      pValue - the formatted string
    • OceanusDate

      public OceanusDate(String pValue, Locale pLocale)
      Construct a Date from a formatted string.
      Parameters:
      pValue - the formatted string
      pLocale - the locale for this date
    • OceanusDate

      public OceanusDate(String pValue, Locale pLocale, String pFormat)
      Construct a Date from a formatted string.
      Parameters:
      pValue - the formatted string
      pLocale - the locale for this date
      pFormat - 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

      public DayOfWeek getDayOfWeek()
      Get the day of the week.
      Returns:
      the day of the week
    • getMonthValue

      public Month 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

      public LocalDate getDate()
      Get the Date associated with this object.
      Returns:
      the date
    • getLocale

      public Locale getLocale()
      Get the locale associated with this object.
      Returns:
      the java locale
    • setLocale

      public void setLocale(Locale pLocale)
      Set locale for the DateDay.
      Parameters:
      pLocale - the locale
    • setFormat

      public void setFormat(String pFormat)
      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

      public void adjustField(TemporalUnit iField, int iUnits)
      Adjust the date by a determined amount.
      Parameters:
      iField - the field to adjust
      iUnits - the number of units to adjust by
    • adjustForwardByPeriod

      public void adjustForwardByPeriod(OceanusDatePeriod pPeriod)
      Adjust the date by a period in a forward direction.
      Parameters:
      pPeriod - the period to adjust by
    • adjustBackwardByPeriod

      public void adjustBackwardByPeriod(OceanusDatePeriod pPeriod)
      Adjust the date by a period in a backward direction.
      Parameters:
      pPeriod - the period to adjust by
    • startPeriod

      public void startPeriod(OceanusDatePeriod pPeriod)
      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

      public int ageOn(OceanusDate pDate)
      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

      public long daysUntil(OceanusDate pDate)
      Calculate the days until the specified date.
      Parameters:
      pDate - the date for which to days until
      Returns:
      the days until that date
    • copyDate

      public void copyDate(OceanusDate pDate)
      Copy a date from another DateDay.
      Parameters:
      pDate - the date to copy from
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(OceanusDate pThat)
      Specified by:
      compareTo in interface Comparable<OceanusDate>
    • compareToRange

      public int compareToRange(OceanusDateRange pRange)
      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

      public boolean equals(Object pThat)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toDate

      public Date toDate()
      Convert the LocalDate to a Date.
      Returns:
      the associated date
    • toCalendar

      public Calendar toCalendar()
      Convert the LocalDate to a Calendar.
      Returns:
      the Calendar
    • isDifferent

      public static boolean isDifferent(OceanusDate pCurr, OceanusDate pNew)
      Determine whether two DateDay objects differ.
      Parameters:
      pCurr - The current Date
      pNew - The new Date
      Returns:
      true if the objects differ, false otherwise