Class FWDataFormatter
java.lang.Object
net.simplace.core.io.FWDataFormatter
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classsome final parameters for Pattern -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates the formatter for the current time.FWDataFormatter(long aDate) FWDataFormatter(long aDate, String aVisuPattern) FWDataFormatter(String aDateString) Parses a date string; precision and visualisation pattern are derived from the string.FWDataFormatter(String aDateString, String aVisuPattern) Parses a date string; the precision pattern is derived from the string.FWDataFormatter(LocalDateTime aDate) FWDataFormatter(LocalDateTime aDate, String aVisuPattern) -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares with a string, aLocalDateTimeor another formatter, using the coarser of both visualisation patterns.inthashCode()Constant hash code:equals(Object)compares in the coarser pattern of both formatters, and some patterns contain no common field (e.g.static LocalDateTimeParses a date string including its time (24:00is read as23:59).voidplusDays(int aDaysCount) Adds days to the date.voidplusYears(int aYearsCount) Adds years to the date.voidsetDataPattern(String aDataPattern) voidSets the Date and checks for compatibility of DatePrecision to stored DatabasePrecisionPattern.voidSets the Date and forces to change DatePrecision to given Pattern.voidsetVisuPattern(String aVisuPattern) toForeignPatternString(String aForeignPattern) toString()static StringtoString(LocalDateTime aFormatedDate, String aPattern) Formats a date; for patterns with time23:59is shown as24:00.static FWDataFormattertransformToDate(String aText) Creates a formatter from a text: a number with more than 4 digits is taken as milliseconds, otherwise the text is parsed.
-
Field Details
-
DAY_MILLIS
public static final long DAY_MILLISreturns 86400000- See Also:
-
-
Constructor Details
-
FWDataFormatter
public FWDataFormatter()Creates the formatter for the current time. -
FWDataFormatter
- Parameters:
aDate- the date
-
FWDataFormatter
public FWDataFormatter(long aDate) - Parameters:
aDate- the date in milliseconds since 1970 (UTC)
-
FWDataFormatter
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 stringaVisuPattern- the visualisation pattern (seeFWDataFormatter.Pattern)- Throws:
ParseException- if the string cannot be parsed
-
FWDataFormatter
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
- Parameters:
aDate- the date;nulluses the current time (a warning is logged)aVisuPattern- visualisation and precision pattern
-
FWDataFormatter
- Parameters:
aDate- the date in milliseconds since 1970 (UTC)aVisuPattern- visualisation and precision pattern
-
-
Method Details
-
getFormatterDate
- Returns:
- the date
-
getDataPattern
- Returns:
- the precision pattern
-
getVisuPattern
- Returns:
- the visualisation pattern
-
setVisuPattern
- Parameters:
aVisuPattern- the visualisation pattern (seeFWDataFormatter.Pattern)- Throws:
ParseException- if the pattern is unknown or not compatible with the precision
-
setDataPattern
- Parameters:
aDataPattern- the precision pattern (seeFWDataFormatter.Pattern)- Throws:
ParseException- if the pattern is unknown or not compatible with the visualisation pattern
-
setDate
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
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 stringaPattern- 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
-
toDataStoreString
- Returns:
- the date formatted with the precision pattern
-
toForeignPatternString
-
parseDate
Parses a date string including its time (24:00is read as23: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 stringaPattern- the pattern- Returns:
- the date, or
nullfor an empty string - Throws:
ParseException- if the string cannot be parsed (the error is logged)
-
equals
-
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). -
toString
Formats a date; for patterns with time23:59is shown as24:00.- Parameters:
aFormatedDate- the dateaPattern- the pattern- Returns:
- the formatted date
-
transformToDate
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,
nullfornull, or the current time if the text cannot be parsed (the error is logged)
-