Class DateTimeFormatterBuilder.FractionPrinterParser
- java.lang.Object
-
- org.threeten.bp.format.DateTimeFormatterBuilder.FractionPrinterParser
-
- All Implemented Interfaces:
DateTimeFormatterBuilder.DateTimePrinterParser
- Enclosing class:
- DateTimeFormatterBuilder
static final class DateTimeFormatterBuilder.FractionPrinterParser extends java.lang.Object implements DateTimeFormatterBuilder.DateTimePrinterParser
Prints and parses a numeric date-time field with optional padding.
-
-
Field Summary
Fields Modifier and Type Field Description private booleandecimalPointprivate TemporalFieldfieldprivate intmaxWidthprivate intminWidth
-
Constructor Summary
Constructors Constructor Description FractionPrinterParser(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private longconvertFromFraction(java.math.BigDecimal fraction)Converts a fraction from 0 to 1 for this field to a value.private java.math.BigDecimalconvertToFraction(long value)Converts a value for this field to a fraction between 0 and 1.intparse(DateTimeParseContext context, java.lang.CharSequence text, int position)Parses text into date-time information.booleanprint(DateTimePrintContext context, java.lang.StringBuilder buf)Prints the date-time object to the buffer.java.lang.StringtoString()
-
-
-
Field Detail
-
field
private final TemporalField field
-
minWidth
private final int minWidth
-
maxWidth
private final int maxWidth
-
decimalPoint
private final boolean decimalPoint
-
-
Constructor Detail
-
FractionPrinterParser
FractionPrinterParser(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint)
Constructor.- Parameters:
field- the field to output, not nullminWidth- the minimum width to output, from 0 to 9maxWidth- the maximum width to output, from 0 to 9decimalPoint- whether to output the localized decimal point symbol
-
-
Method Detail
-
print
public boolean print(DateTimePrintContext context, java.lang.StringBuilder buf)
Description copied from interface:DateTimeFormatterBuilder.DateTimePrinterParserPrints the date-time object to the buffer.The context holds information to use during the print. It also contains the date-time information to be printed.
The buffer must not be mutated beyond the content controlled by the implementation.
- Specified by:
printin interfaceDateTimeFormatterBuilder.DateTimePrinterParser- Parameters:
context- the context to print using, not nullbuf- the buffer to append to, not null- Returns:
- false if unable to query the value from the date-time, true otherwise
-
parse
public int parse(DateTimeParseContext context, java.lang.CharSequence text, int position)
Description copied from interface:DateTimeFormatterBuilder.DateTimePrinterParserParses text into date-time information.The context holds information to use during the parse. It is also used to store the parsed date-time information.
- Specified by:
parsein interfaceDateTimeFormatterBuilder.DateTimePrinterParser- Parameters:
context- the context to use and parse into, not nulltext- the input text to parse, not nullposition- the position to start parsing at, from 0 to the text length- Returns:
- the new parse position, where negative means an error with the error position encoded using the complement ~ operator
-
convertToFraction
private java.math.BigDecimal convertToFraction(long value)
Converts a value for this field to a fraction between 0 and 1.The fractional value is between 0 (inclusive) and 1 (exclusive). It can only be returned if the
value rangeis fixed. The fraction is obtained by calculation from the field range using 9 decimal places and a rounding mode ofFLOOR. The calculation is inaccurate if the values do not run continuously from smallest to largest.For example, the second-of-minute value of 15 would be returned as 0.25, assuming the standard definition of 60 seconds in a minute.
- Parameters:
value- the value to convert, must be valid for this rule- Returns:
- the value as a fraction within the range, from 0 to 1, not null
- Throws:
DateTimeException- if the value cannot be converted to a fraction
-
convertFromFraction
private long convertFromFraction(java.math.BigDecimal fraction)
Converts a fraction from 0 to 1 for this field to a value.The fractional value must be between 0 (inclusive) and 1 (exclusive). It can only be returned if the
value rangeis fixed. The value is obtained by calculation from the field range and a rounding mode ofFLOOR. The calculation is inaccurate if the values do not run continuously from smallest to largest.For example, the fractional second-of-minute of 0.25 would be converted to 15, assuming the standard definition of 60 seconds in a minute.
- Parameters:
fraction- the fraction to convert, not null- Returns:
- the value of the field, valid for this rule
- Throws:
DateTimeException- if the value cannot be converted
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-