java.lang.Object
io.github.tonywasher.joceanus.oceanus.date.OceanusDateFormatter
All Implemented Interfaces:
OceanusEventRegistrar.OceanusEventProvider<OceanusDateEvent>

public class OceanusDateFormatter extends Object implements OceanusEventRegistrar.OceanusEventProvider<OceanusDateEvent>
Formatter for Date objects.
Author:
Tony Washer
  • Field Details

  • Constructor Details

    • OceanusDateFormatter

      public OceanusDateFormatter()
      Constructor.
    • OceanusDateFormatter

      public OceanusDateFormatter(Locale pLocale)
      Constructor.
      Parameters:
      pLocale - the locale
  • Method Details

    • getEventRegistrar

      public OceanusEventRegistrar<OceanusDateEvent> getEventRegistrar()
      Description copied from interface: OceanusEventRegistrar.OceanusEventProvider
      Obtain registration object for listeners.
      Specified by:
      getEventRegistrar in interface OceanusEventRegistrar.OceanusEventProvider<OceanusDateEvent>
      Returns:
      the registrar
    • setFormat

      public final void setFormat(String pFormat)
      Set the date format.
      Parameters:
      pFormat - the format string
    • setLocale

      public final void setLocale(Locale pLocale)
      Set the locale.
      Parameters:
      pLocale - the locale
    • formatCalendarDay

      public String formatCalendarDay(Calendar pDate)
      Format a calendar Date.
      Parameters:
      pDate - the date to format
      Returns:
      the formatted date
    • formatLocalDate

      public String formatLocalDate(LocalDate pDate)
      Format a local Date.
      Parameters:
      pDate - the date to format
      Returns:
      the formatted date
    • formatJavaDate

      public String formatJavaDate(Date pDate)
      Format a java Date.
      Parameters:
      pDate - the date to format
      Returns:
      the formatted date
    • formatDate

      public String formatDate(OceanusDate pDate)
      Format a Date.
      Parameters:
      pDate - the date to format
      Returns:
      the formatted date
    • formatDateRange

      public String formatDateRange(OceanusDateRange pRange)
      Format a DateRange.
      Parameters:
      pRange - the range to format
      Returns:
      the formatted date
    • parseJavaDate

      public Date parseJavaDate(String pValue)
      Parse Java Date.
      Parameters:
      pValue - Formatted Date
      Returns:
      the Date
      Throws:
      IllegalArgumentException - on error
    • parseLocalDate

      public LocalDate parseLocalDate(String pValue)
      Parse LocalDate.
      Parameters:
      pValue - Formatted Date
      Returns:
      the Date
      Throws:
      IllegalArgumentException - on error
    • parseCalendarDay

      public Calendar parseCalendarDay(String pValue)
      Parse CalendarDay.
      Parameters:
      pValue - Formatted CalendarDay
      Returns:
      the CalendarDay
      Throws:
      IllegalArgumentException - on error
    • parseDate

      public OceanusDate parseDate(String pValue)
      Parse Date.
      Parameters:
      pValue - Formatted Date
      Returns:
      the DateDay
      Throws:
      IllegalArgumentException - on error
    • parseDateBase

      public OceanusDate parseDateBase(String pValue, int pBaseYear)
      Parse Date using the passed year as base date.

      This is used when a two digit year is utilised

      Parameters:
      pValue - Formatted DateDay
      pBaseYear - the base year
      Returns:
      the DateDay
      Throws:
      IllegalArgumentException - on error
    • getLocale

      public Locale getLocale()
      Obtain the locale.
      Returns:
      the locale
    • toBytes

      public byte[] toBytes(OceanusDate pDate)
      Create a byte array representation of a date.
      Parameters:
      pDate - the date to process
      Returns:
      the processed date
    • fromBytes

      public OceanusDate fromBytes(byte[] pBuffer)
      Parse a byte array representation of a date.
      Parameters:
      pBuffer - the byte representation
      Returns:
      the date