Skip to content

Commit

Permalink
[JBPM-10225] Considering time for Dates (#2397) (#2400)
Browse files Browse the repository at this point in the history
Co-authored-by: Francisco Javier Tirado Sarti <[email protected]>
  • Loading branch information
github-actions[bot] and fjtirado authored Mar 18, 2024
1 parent 3b6411d commit 764c616
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ private Optional<Object> getObjectFromClass(final Object value) {
}

private static Collection<DateFormat> dateFormats = Arrays.asList(new SimpleDateFormat("yyyy-MM-ddHH:mm:ss"),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"),
new SimpleDateFormat("yyyy-MM-dd"), new SimpleDateFormat("HH:mm:ss"), DateFormat.getDateInstance(),
DateFormat.getTimeInstance(),
DateFormat.getDateTimeInstance());

private Date parseDate(String toBeParsed) {
private static Date parseDate(String toBeParsed) {
StringBuilder sb = new StringBuilder();
for (DateFormat dateFormat : dateFormats) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.ZonedDateTime;
import java.util.Date;

import org.assertj.core.api.InstanceOfAssertFactories;
import org.jbpm.process.core.datatype.impl.type.ObjectDataType;
import org.junit.Test;

Expand All @@ -44,6 +45,8 @@ public void testReadValueDate() {
assertThat(dateType.readValue("12:12:12")).isInstanceOf(Date.class);
assertThat(dateType.valueOf("2012-02-02")).isInstanceOf(Date.class);
assertThat(dateType.valueOf("12:12:12")).isInstanceOf(Date.class);
assertThat(dateType.valueOf("2016-01-11T01:06:32")).isInstanceOf(Date.class)
.asInstanceOf(InstanceOfAssertFactories.DATE).hasHourOfDay(1).hasMinute(6).hasSecond(32);
assertThat(dateType.valueOf("pepe")).isInstanceOf(String.class);
assertThatThrownBy(() -> dateType.readValue("pepe")).isInstanceOf(IllegalArgumentException.class);
}
Expand Down

0 comments on commit 764c616

Please sign in to comment.