Skip to content

Commit

Permalink
fix: Avoid invalid dates
Browse files Browse the repository at this point in the history
Restrict the date/date-time pattern to avoid the creation of invalid dates (e.g. leap year, month with 31 days, etc.).

(cherry picked from commit 85806fe)
  • Loading branch information
saig0 committed Aug 23, 2024
1 parent 0edac2f commit 9b44b57
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/scala/org/camunda/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ package org.camunda

import scala.math.BigDecimal
import org.slf4j.LoggerFactory

import java.time.temporal.ChronoField.{
DAY_OF_MONTH,
HOUR_OF_DAY,
MINUTE_OF_HOUR,
SECOND_OF_MINUTE,
NANO_OF_SECOND,
YEAR,
MONTH_OF_YEAR,
DAY_OF_MONTH
NANO_OF_SECOND,
SECOND_OF_MINUTE,
YEAR
}

import java.util.regex.Pattern
import org.camunda.feel.syntaxtree.ZonedTime

import java.time.format.{DateTimeFormatterBuilder, SignStyle}
import java.time.format.{DateTimeFormatterBuilder, ResolverStyle, SignStyle}
import java.time.{Duration, LocalDate, LocalDateTime, LocalTime, Period, ZonedDateTime}

/** @author
Expand Down Expand Up @@ -189,17 +189,20 @@ package object feel {
.appendValue(MONTH_OF_YEAR, 2)
.appendLiteral("-")
.appendValue(DAY_OF_MONTH, 2)
.toFormatter();
.toFormatter()
.withResolverStyle(ResolverStyle.STRICT)

val localDateTimeFormatter = new DateTimeFormatterBuilder()
.append(dateFormatter)
.append(timeFormatterWithPrefix)
.toFormatter();
.toFormatter()
.withResolverStyle(ResolverStyle.STRICT)

val dateTimeFormatter = new DateTimeFormatterBuilder()
.append(dateFormatter)
.append(timeFormatterWithPrefix)
.append(offsetFormatter)
.toFormatter();
.toFormatter()
.withResolverStyle(ResolverStyle.STRICT)

}

0 comments on commit 9b44b57

Please sign in to comment.