Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date parsing failure when assigning cargo to route #99

Closed
wsargent opened this issue Apr 23, 2023 · 4 comments · Fixed by #136 · May be fixed by #100
Closed

Date parsing failure when assigning cargo to route #99

wsargent opened this issue Apr 23, 2023 · 4 comments · Fixed by #136 · May be fixed by #100
Labels

Comments

@wsargent
Copy link

wsargent commented Apr 23, 2023

I can get the application to error when booking cargo:

  1. Go to http://localhost:8080/dddsample/admin/list
  2. Click on book new cargo http://localhost:8080/dddsample/admin/registration
  3. Origin JNTKO Destination AUMEL, Select arrival deadline a couple of months out "03/06/2023" (not US-locale, it uses Europe Locale)
  4. Click book http://localhost:8080/dddsample/admin/show?trackingId=7FEB8AEE
  5. Says Not routed - so click "Route this cargo" - http://localhost:8080/dddsample/admin/selectItinerary?trackingId=7FEB8AEE
  6. Click first button, "assign cargo to this route"

See page with exception:

Sun Apr 23 14:13:04 PDT 2023
There was an unexpected error (type=Bad Request, status=400).
Validation failed for object='routeAssignmentCommand'. Error count: 10

The logs show:

Field error in object 'routeAssignmentCommand' on field 'legs[1].toDate': rejected value [2023-04-29 07:05]; codes [typeMismatch.routeAssignmentCommand.legs[1].toDate,typeMismatch.routeAssignmentCommand.legs.toDate,typeMismatch.legs[1].toDate,typeMismatch.legs.toDate,typeMismatch.toDate,typeMismatch.java.time.Instant,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [routeAssignmentCommand.legs[1].toDate,legs[1].toDate]; arguments []; default message [legs[1].toDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.Instant' for property 'legs[1].toDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.Instant] for value '2023-04-29 07:05'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2023-04-29 07:05]]

Running on Ubuntu 18, JDK 11

❱ java -version                 
Picked up JAVA_TOOL_OPTIONS: -XX:-UseBiasedLocking -Djdk.nio.maxCachedBufferSize=262144 -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints
openjdk version "11.0.14.1" 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)
@wsargent
Copy link
Author

Looks like it's probably

th:value="${#dates.format(leg.loadTime,'yyyy-MM-dd hh:mm')}"/>

@orende
Copy link
Contributor

orende commented May 11, 2023

Hi @wsargent ! I had a look at the PR but would like to see a test verifying the fix.

@wsargent
Copy link
Author

wsargent commented May 11, 2023 via email

@MakenChan
Copy link

image
public class InstDateEditor extends PropertyEditorSupport {

@Override
public void setAsText(@Nullable String text) throws IllegalArgumentException {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
    LocalDateTime dateTime = LocalDateTime.parse(text, formatter);
    setValue(dateTime.toInstant(ZoneOffset.UTC));
}

/**
 * Format the Date as String, using the specified DateFormat.
 */
@Override
public String getAsText() {
    Instant value = (Instant) getValue();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
    String formattedDateTime = formatter.format(value.atZone(ZoneOffset.UTC));
    return (value != null ? formattedDateTime : "");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants