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

Return a UTC ZonedDateTime from CargoRoutingDTO::getArrivalDeadline #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DanilSuits
Copy link

Internally, the arrivalDeadline assumes a UTC context; but when returning that information to the web client, the timezone information was being stripped away from the value. This caused the output representation of the arrivalDeadline to be an interpretation of the arrival instant in the user.timezone, rather than in UTC. Thus under certain conditions an off-by-one error was introduced.

The original version of the admin/show template was using org.thymeleaf.expression.Dates, which was expecting that the arrivalDate in the model would be a java.util.Date. As a consequence, deep in the call stack the arrivalDate Instant was being converted via Date.from(Instant). This conversion keeps the instant (epochMillis) constant, but the day/month/year are Date::normalized values, which is to say computed from epochMillis and TimeZone::getDefaultRef....

To eliminate the off by one error, the template is updated to use org.thymeleaf.expression.Temporals::format, which is intended for use with the java.time API. We then load a ZonedDateTime, rather than an Instant, into the model, ensuring that the output data matches the original input.

Danil added 2 commits October 3, 2024 00:06
The convention of assertJ is: assertThat(actual)...(expected)

Reversing these arguments creates a misleading message.

Clear messages are particularly important for
AdminAcceptanceTest::adminSiteCanBookNewCargo, because
the expected value is neither constant nor obvious.
By switching the admin/show template from

org.thymeleaf.expression.Dates::format

to

org.thymeleaf.expression.Temporals::format

we avoid an implicit conversion via Date::from(Instant), which
was introducing coupling to user.timezone, introducing an
off-by-one error in the representation of the arrivalDeadline.

Temporals::format is also coupled to user.timezone, therefore
instead of returning an instant we return a ZonedDateTime.  To
ensure that our representation of the output date is consistent with
the parsing of the input date (see CargoAdminController::register),
we specify ZoneOffset.UTC in both places.
Copy link
Contributor

@orende orende left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me ✔️

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

Successfully merging this pull request may close these issues.

2 participants