diff --git a/src/main/scala/org/camunda/feel/syntaxtree/Val.scala b/src/main/scala/org/camunda/feel/syntaxtree/Val.scala index 0846d5f80..5c4618cf2 100644 --- a/src/main/scala/org/camunda/feel/syntaxtree/Val.scala +++ b/src/main/scala/org/camunda/feel/syntaxtree/Val.scala @@ -219,8 +219,8 @@ case class ValYearMonthDuration(value: YearMonthDuration) extends Val { object ValYearMonthDuration { def format(value: YearMonthDuration): String = { - val year = value.getYears - val month = value.getMonths % 12 + val year = value.toTotalMonths / 12 + val month = value.toTotalMonths % 12 if (year == 0 && month == 0) "P0Y" diff --git a/src/test/scala/org/camunda/feel/api/StringRepresentationTypeTest.scala b/src/test/scala/org/camunda/feel/api/StringRepresentationTypeTest.scala index 1b259e3f2..2a571e213 100644 --- a/src/test/scala/org/camunda/feel/api/StringRepresentationTypeTest.scala +++ b/src/test/scala/org/camunda/feel/api/StringRepresentationTypeTest.scala @@ -121,6 +121,16 @@ class StringRepresentationTypeTest extends AnyFlatSpec with Matchers { duration.toString should be("P2M") } + it should "return normalized format " in { + ValYearMonthDuration(Period.parse("P2Y")).toString should be("P2Y") + ValYearMonthDuration(Period.parse("P24M")).toString should be("P2Y") + + ValYearMonthDuration(Period.parse("P25M")).toString should be("P2Y1M") + ValYearMonthDuration(Period.parse("P35M")).toString should be("P2Y11M") + + ValYearMonthDuration(Period.parse("P2Y13M")).toString should be("P3Y1M") + } + "A days-time-duration" should "return 'P1DT2H3M4S' " in { val duration = ValDayTimeDuration(Duration.parse("P1DT2H3M4S")) @@ -151,6 +161,17 @@ class StringRepresentationTypeTest extends AnyFlatSpec with Matchers { duration.toString should be("PT4S") } + it should "return normalized format " in { + ValDayTimeDuration(Duration.parse("P5D")).toString should be("P5D") + ValDayTimeDuration(Duration.parse("PT120H")).toString should be("P5D") + ValDayTimeDuration(Duration.parse("PT7200M")).toString should be("P5D") + ValDayTimeDuration(Duration.parse("PT432000S")).toString should be("P5D") + + ValDayTimeDuration(Duration.parse("PT121H")).toString should be("P5DT1H") + ValDayTimeDuration(Duration.parse("PT7201M")).toString should be("P5DT1M") + ValDayTimeDuration(Duration.parse("PT7261M")).toString should be("P5DT1H1M") + } + "A list" should "return '[1, 2]' " in { ValList(List(ValNumber(1), ValNumber(2))).toString should be("[1, 2]") }