Joda allowed for date_optional_time and strict_date_optional_time a decimal point to be . dot or , comma For our java.time implementation we should also extend this for strict_date_optional_time-nanos the approach to fix this is the same as in iso8601 parser closes #43730
This commit is contained in:
parent
2176d09c37
commit
247f2dabad
|
@ -112,6 +112,10 @@ public class DateFormatters {
|
|||
.optionalStart()
|
||||
.appendFraction(NANO_OF_SECOND, 1, 9, true)
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
.appendLiteral(',')
|
||||
.appendFraction(NANO_OF_SECOND, 1, 9, false)
|
||||
.optionalEnd()
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
.appendZoneOrOffsetId()
|
||||
|
@ -139,6 +143,10 @@ public class DateFormatters {
|
|||
.appendFraction(NANO_OF_SECOND, 3, 9, true)
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
.appendLiteral(',')
|
||||
.appendFraction(NANO_OF_SECOND, 3, 9, false)
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
.appendZoneOrOffsetId()
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
|
@ -940,6 +948,10 @@ public class DateFormatters {
|
|||
.optionalStart()
|
||||
.appendFraction(NANO_OF_SECOND, 1, 9, true)
|
||||
.optionalEnd()
|
||||
.optionalStart()
|
||||
.appendLiteral(',')
|
||||
.appendFraction(NANO_OF_SECOND, 1, 9, false)
|
||||
.optionalEnd()
|
||||
.optionalStart().appendZoneOrOffsetId().optionalEnd()
|
||||
.optionalStart().appendOffset("+HHmm", "Z").optionalEnd()
|
||||
.optionalEnd()
|
||||
|
|
|
@ -40,6 +40,26 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
public class JavaJodaTimeDuellingTests extends ESTestCase {
|
||||
|
||||
//these parsers should allow both ',' and '.' as a decimal point
|
||||
public void testDecimalPointParsing(){
|
||||
assertSameDate("2001-01-01T00:00:00.123Z", "strict_date_optional_time");
|
||||
assertSameDate("2001-01-01T00:00:00,123Z", "strict_date_optional_time");
|
||||
|
||||
assertSameDate("2001-01-01T00:00:00.123Z", "date_optional_time");
|
||||
assertSameDate("2001-01-01T00:00:00,123Z", "date_optional_time");
|
||||
|
||||
// only java.time has nanos parsing, but the results for 3digits should be the same
|
||||
DateFormatter jodaFormatter = Joda.forPattern("strict_date_optional_time");
|
||||
DateFormatter javaFormatter = DateFormatter.forPattern("strict_date_optional_time_nanos");
|
||||
assertSameDate("2001-01-01T00:00:00.123Z", "strict_date_optional_time_nanos", jodaFormatter, javaFormatter);
|
||||
assertSameDate("2001-01-01T00:00:00,123Z", "strict_date_optional_time_nanos", jodaFormatter, javaFormatter);
|
||||
|
||||
assertParseException("2001-01-01T00:00:00.123,456Z", "strict_date_optional_time");
|
||||
assertParseException("2001-01-01T00:00:00.123,456Z", "date_optional_time");
|
||||
//This should fail, but java is ok with this because the field has the same value
|
||||
// assertJavaTimeParseException("2001-01-01T00:00:00.123,123Z", "strict_date_optional_time_nanos");
|
||||
}
|
||||
|
||||
public void testIncompatiblePatterns() {
|
||||
// in joda 'y' means year, this is changed to 'u' in java.time. difference is in before era yeaers
|
||||
assertSameMillis("-0001-01-01", "yyyy-MM-dd", "8uuuu-MM-dd");
|
||||
|
|
Loading…
Reference in New Issue