private static Period withTwoMostSignificantNonZeroFieldsOnly(Period period) { int nonZeroFieldsFound = 0; for (DurationFieldType durationFieldType : period.getFieldTypes()) { if (period.get(durationFieldType) != 0) { if (nonZeroFieldsFound < 2) { nonZeroFieldsFound++; } else { period = period.withField(durationFieldType, 0); } } } return period; }