diff --git a/build.gradle b/build.gradle index 56ba0d2..8414531 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'com.github.mfornos:humanize-slim:1.2.2' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'mysql:mysql-connector-java' diff --git a/src/main/java/jp/ac/kobe_u/cs/itspecialist/todoapp/entity/ToDo.java b/src/main/java/jp/ac/kobe_u/cs/itspecialist/todoapp/entity/ToDo.java index c0f901f..901f6b6 100644 --- a/src/main/java/jp/ac/kobe_u/cs/itspecialist/todoapp/entity/ToDo.java +++ b/src/main/java/jp/ac/kobe_u/cs/itspecialist/todoapp/entity/ToDo.java @@ -9,6 +9,7 @@ import javax.persistence.Id; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import humanize.Humanize; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -31,4 +32,15 @@ public class ToDo { Date createdAt; //作成日時 @Temporal(TemporalType.TIMESTAMP) Date doneAt; //完了日時 + + public String humanizeCreatedAt() { + return Humanize.naturalDay(createdAt); + } + + public String humanizeDoneAt() { + if(doneAt == null) { + return ""; + } + return Humanize.naturalDay(doneAt); + } } diff --git a/src/main/resources/templates/alllist.html b/src/main/resources/templates/alllist.html index 8580517..66a2b2e 100644 --- a/src/main/resources/templates/alllist.html +++ b/src/main/resources/templates/alllist.html @@ -24,7 +24,7 @@ <td>[[${todo.seq}]]</td> <td>[[${todo.title}]]</td> <td>[[${todo.mid}]]</td> - <td>[[${todo.createdAt}]]</td> + <td th:title="${todo.createdAt}">[[${todo.humanizeCreatedAt()}]]</td> </tr> </table> @@ -40,7 +40,7 @@ <td>[[${done.seq}]]</td> <td>[[${done.title}]]</td> <td>[[${done.mid}]]</td> - <td>[[${done.doneAt}]]</td> + <td th:title="${done.doneAt}">[[${done.humanizeDoneAt()}]]</td> </tr> </table> diff --git a/src/main/resources/templates/list.html b/src/main/resources/templates/list.html index a2939b9..6ea3201 100644 --- a/src/main/resources/templates/list.html +++ b/src/main/resources/templates/list.html @@ -23,7 +23,7 @@ <tr th:each="todo: ${todos}"> <td>[[${todo.seq}]]</td> <td>[[${todo.title}]]</td> - <td>[[${todo.createdAt}]]</td> + <td th:title="${todo.createdAt}">[[${todo.humanizeCreatedAt()}]]</td> <td> <a th:href="@{/{mid}/todos/{seq}/done(mid=${member.mid},seq=${todo.seq})}">完了</a> </td> @@ -53,8 +53,8 @@ <tr th:each="done: ${dones}"> <td>[[${done.seq}]]</td> <td>[[${done.title}]]</td> - <td>[[${done.createdAt}]]</td> - <td>[[${done.doneAt}]]</td> + <td th:title="${done.createdAt}">[[${done.humanizeCreatedAt()}]]</td> + <td th:title="${done.doneAt}">[[${done.humanizeDoneAt()}]]</td> </tr> </table>