Skip to content

Commit

Permalink
fixed files form Time #5
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 4556bf7 commit 1940bba
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions projects/Time/5/org/joda/time/Period.java
Original file line number Diff line number Diff line change
Expand Up @@ -1625,13 +1625,19 @@ public Period normalizedStandard(PeriodType type) {
int years = getYears();
int months = getMonths();
if (years != 0 || months != 0) {
years = FieldUtils.safeAdd(years, months / 12);
months = months % 12;
if (years != 0) {
result = result.withYears(years);
long totalMonths = years * 12L + months;
if (type.isSupported(DurationFieldType.YEARS_TYPE)) {
int normalizedYears = FieldUtils.safeToInt(totalMonths / 12);
result = result.withYears(normalizedYears);
totalMonths = totalMonths - (normalizedYears * 12);
}
if (months != 0) {
result = result.withMonths(months);
if (type.isSupported(DurationFieldType.MONTHS_TYPE)) {
int normalizedMonths = FieldUtils.safeToInt(totalMonths);
result = result.withMonths(normalizedMonths);
totalMonths = totalMonths - normalizedMonths;
}
if (totalMonths != 0) {
throw new UnsupportedOperationException("Unable to normalize as PeriodType is missing either years or months but period has a month/year amount: " + toString());
}
}
return result;
Expand Down

0 comments on commit 1940bba

Please sign in to comment.