Skip to content

Commit e133d9d

Browse files
committed
Test and fix late chronology bind to reduced parse
1 parent 882aeaa commit e133d9d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,7 @@ int setValue(DateTimeParseContext context, long value, int errorPos, int success
26102610
if (baseDate != null) {
26112611
Chronology chrono = context.getEffectiveChronology();
26122612
baseValue = chrono.date(baseDate).get(field);
2613+
context.addChronologyChangedParser(this, value, errorPos, successPos);
26132614
}
26142615
int parseLen = successPos - errorPos;
26152616
if (parseLen == minWidth && value >= 0) {

src/main/java/org/threeten/bp/format/DateTimeParseContext.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.util.ArrayList;
3535
import java.util.HashMap;
36+
import java.util.List;
3637
import java.util.Locale;
3738
import java.util.Map;
3839
import java.util.Objects;
@@ -41,6 +42,7 @@
4142
import org.threeten.bp.ZoneId;
4243
import org.threeten.bp.chrono.Chronology;
4344
import org.threeten.bp.chrono.IsoChronology;
45+
import org.threeten.bp.format.DateTimeFormatterBuilder.ReducedPrinterParser;
4446
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
4547
import org.threeten.bp.jdk8.Jdk8Methods;
4648
import org.threeten.bp.temporal.TemporalField;
@@ -355,7 +357,24 @@ int setParsedField(TemporalField field, long value, int errorPos, int successPos
355357
*/
356358
void setParsed(Chronology chrono) {
357359
Objects.requireNonNull(chrono, "chrono");
358-
currentParsed().chrono = chrono;
360+
Parsed currentParsed = currentParsed();
361+
currentParsed.chrono = chrono;
362+
if (currentParsed.callbacks != null) {
363+
List<Object[]> callbacks = new ArrayList<>(currentParsed.callbacks);
364+
currentParsed.callbacks.clear();
365+
for (Object[] objects : callbacks) {
366+
ReducedPrinterParser pp = (ReducedPrinterParser) objects[0];
367+
pp.setValue(this, (long) objects[1], (int) objects[2], (int) objects[3]);
368+
}
369+
}
370+
}
371+
372+
void addChronologyChangedParser(ReducedPrinterParser reducedPrinterParser, long value, int errorPos, int successPos) {
373+
Parsed currentParsed = currentParsed();
374+
if (currentParsed.callbacks == null) {
375+
currentParsed.callbacks = new ArrayList<>(2);
376+
}
377+
currentParsed.callbacks.add(new Object[] {reducedPrinterParser, value, errorPos, successPos});
359378
}
360379

361380
/**
@@ -410,6 +429,7 @@ final class Parsed extends DefaultInterfaceTemporalAccessor {
410429
final Map<TemporalField, Long> fieldValues = new HashMap<>();
411430
boolean leapSecond;
412431
Period excessDays = Period.ZERO;
432+
List<Object[]> callbacks;
413433

414434
private Parsed() {
415435
}

0 commit comments

Comments
 (0)