From 1940bbab9cb95308586204fcd68932ce495f315d Mon Sep 17 00:00:00 2001 From: tdurieux Date: Tue, 7 Mar 2017 13:13:44 +0100 Subject: [PATCH] fixed files form Time #5 --- projects/Time/5/org/joda/time/Period.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/projects/Time/5/org/joda/time/Period.java b/projects/Time/5/org/joda/time/Period.java index f404793..5ea67a7 100644 --- a/projects/Time/5/org/joda/time/Period.java +++ b/projects/Time/5/org/joda/time/Period.java @@ -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;