Skip to content

Commit

Permalink
don't truncate hours offset (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
zambrovski authored and lmoesle committed Jan 16, 2024
1 parent cd03b5f commit 9bd7ddf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void unassignUserTask(String taskId) {
public void deferUserTask(String taskId, Instant followUpDate) {
var task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task != null) {
task.setFollowUpDate(Date.from(followUpDate.truncatedTo(ChronoUnit.DAYS)));
task.setFollowUpDate(Date.from(followUpDate));
taskService.saveTask(task);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.UUID;

Expand Down Expand Up @@ -74,13 +75,19 @@ void save() {

@Test
void deferUserTask() {
val instant = LocalDateTime.of(2023, 5, 24, 12, 0).toInstant(ZoneOffset.UTC);
val originalTZ = System.getProperty("user.timezone");
System.setProperty("user.timezone", "Europe/Berlin");
val offsetDateTimeFromFrontend = OffsetDateTime.parse("2024-01-18T00:00:00.000+01:00");
val instant = offsetDateTimeFromFrontend.toInstant();

final TaskFake task = TaskFake.builder().build();
QueryMocks.mockTaskQuery(taskService).singleResult(task);

taskCommandPort.deferUserTask(taskId, instant);
assertThat(task.getFollowUpDate()).isNotNull(); // check only if there is an interaction, no Instant to DateTime transformation is tested
assertThat(task.getFollowUpDate()).isNotNull();
assertThat(task.getFollowUpDate()).isEqualTo("2024-01-18T00:00:00.000+01:00");
verify(taskService).saveTask(task);
System.setProperty("user.timezone", originalTZ);
}
@Test
void undeferUserTask() {
Expand Down

0 comments on commit 9bd7ddf

Please sign in to comment.