Class FWDataFormatter

java.lang.Object
net.simplace.core.io.FWDataFormatter

public class FWDataFormatter extends Object
A date with a data precision pattern (how precise the date is, derived from the parsed string) and a visualisation pattern (how it is shown). Times 24:00 are stored as 23:59 and shown as 24:00 again.
Author:
Andreas Enders please re-implement this class with needed functions
  • Field Details

  • Constructor Details

    • FWDataFormatter

      public FWDataFormatter()
      Creates the formatter for the current time.
    • FWDataFormatter

      public FWDataFormatter(LocalDateTime aDate)
      Parameters:
      aDate - the date
    • FWDataFormatter

      public FWDataFormatter(long aDate)
      Parameters:
      aDate - the date in milliseconds since 1970 (UTC)
    • FWDataFormatter

      public FWDataFormatter(String aDateString, String aVisuPattern) throws ParseException
      Parses a date string; the precision pattern is derived from the string. If the visualisation pattern is unknown or incompatible, the precision pattern is used (a warning is logged).
      Parameters:
      aDateString - the date string
      aVisuPattern - the visualisation pattern (see FWDataFormatter.Pattern)
      Throws:
      ParseException - if the string cannot be parsed
    • FWDataFormatter

      public FWDataFormatter(String aDateString) throws ParseException
      Parses a date string; precision and visualisation pattern are derived from the string.
      Parameters:
      aDateString - the date string
      Throws:
      ParseException - if the string is empty or cannot be parsed
    • FWDataFormatter

      public FWDataFormatter(LocalDateTime aDate, String aVisuPattern)
      Parameters:
      aDate - the date; null uses the current time (a warning is logged)
      aVisuPattern - visualisation and precision pattern
    • FWDataFormatter

      public FWDataFormatter(long aDate, String aVisuPattern)
      Parameters:
      aDate - the date in milliseconds since 1970 (UTC)
      aVisuPattern - visualisation and precision pattern
  • Method Details

    • getFormatterDate

      public LocalDateTime getFormatterDate()
      Returns:
      the date
    • getDataPattern

      public String getDataPattern()
      Returns:
      the precision pattern
    • getVisuPattern

      public String getVisuPattern()
      Returns:
      the visualisation pattern
    • setVisuPattern

      public void setVisuPattern(String aVisuPattern) throws ParseException
      Parameters:
      aVisuPattern - the visualisation pattern (see FWDataFormatter.Pattern)
      Throws:
      ParseException - if the pattern is unknown or not compatible with the precision
    • setDataPattern

      public void setDataPattern(String aDataPattern) throws ParseException
      Parameters:
      aDataPattern - the precision pattern (see FWDataFormatter.Pattern)
      Throws:
      ParseException - if the pattern is unknown or not compatible with the visualisation pattern
    • setDate

      public void setDate(String aDateString) throws ParseException
      Sets the Date and checks for compatibility of DatePrecision to stored DatabasePrecisionPattern. If not compatible ParseException is thrown
      Parameters:
      aDateString - the date string
      Throws:
      ParseException - if the string cannot be parsed or its precision is not compatible
    • setDate

      public void setDate(String aDateString, String aPattern) throws ParseException
      Sets the Date and forces to change DatePrecision to given Pattern. If pattern is not compatible to possible Patterns (class Pattern) ParseException is thrown
      Parameters:
      aDateString - the date string
      aPattern - the pattern of the string, used as precision and visualisation pattern
      Throws:
      ParseException - if the pattern is unknown or the string cannot be parsed
    • plusDays

      public void plusDays(int aDaysCount)
      Adds days to the date.
      Parameters:
      aDaysCount - number of days (may be negative)
    • plusYears

      public void plusYears(int aYearsCount)
      Adds years to the date.
      Parameters:
      aYearsCount - number of years (may be negative)
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the date formatted with the visualisation pattern
    • toDataStoreString

      public String toDataStoreString()
      Returns:
      the date formatted with the precision pattern
    • toForeignPatternString

      public String toForeignPatternString(String aForeignPattern)
      Parameters:
      aForeignPattern - any DateTimeFormatter pattern
      Returns:
      the date formatted with the pattern
    • parseDate

      public static LocalDateTime parseDate(String aDateString, String aPattern) throws ParseException
      Parses a date string including its time (24:00 is read as 23:59). Fields missing in the pattern are set to their start (January, first day, 00:00:00; year 1970 for time-only patterns).
      Parameters:
      aDateString - the date string
      aPattern - the pattern
      Returns:
      the date, or null for an empty string
      Throws:
      ParseException - if the string cannot be parsed (the error is logged)
    • equals

      public boolean equals(Object aDate)
      Compares with a string, a LocalDateTime or another formatter, using the coarser of both visualisation patterns.
      Overrides:
      equals in class Object
      Parameters:
      aDate - the object to compare
      Returns:
      true if both dates are equal in the coarser pattern
    • hashCode

      public int hashCode()
      Constant hash code: equals(Object) compares in the coarser pattern of both formatters, and some patterns contain no common field (e.g. TIME, MONTH), so only a constant is consistent with equals (correct, but slow as key of hash based collections).
      Overrides:
      hashCode in class Object
      See Also:
    • toString

      public static String toString(LocalDateTime aFormatedDate, String aPattern)
      Formats a date; for patterns with time 23:59 is shown as 24:00.
      Parameters:
      aFormatedDate - the date
      aPattern - the pattern
      Returns:
      the formatted date
    • transformToDate

      public static FWDataFormatter transformToDate(String aText)
      Creates a formatter from a text: a number with more than 4 digits is taken as milliseconds, otherwise the text is parsed.
      Parameters:
      aText - the text
      Returns:
      the formatter, null for null, or the current time if the text cannot be parsed (the error is logged)