Skip to content
Snippets Groups Projects
Commit 071f999a authored by Alexandre Grison's avatar Alexandre Grison
Browse files

comment date format

parent f1d01ca0
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ import javax.persistence.* ...@@ -5,7 +5,7 @@ import javax.persistence.*
@Entity @Entity
data class Comment(var createdAt: OffsetDateTime = OffsetDateTime.now(), data class Comment(var createdAt: OffsetDateTime = OffsetDateTime.now(),
var updatedAt: OffsetDateTime? = null, var updatedAt: OffsetDateTime = OffsetDateTime.now(),
var body: String = "", var body: String = "",
@ManyToOne @ManyToOne
var article: Article = Article(), var article: Article = Article(),
......
...@@ -2,21 +2,27 @@ package io.realworld.model.inout ...@@ -2,21 +2,27 @@ package io.realworld.model.inout
import com.fasterxml.jackson.annotation.JsonRootName import com.fasterxml.jackson.annotation.JsonRootName
import io.realworld.model.User import io.realworld.model.User
import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@JsonRootName("comment") @JsonRootName("comment")
data class Comment(val createdAt: String, data class Comment(val createdAt: String,
val updatedAt: String?, val updatedAt: String,
val body: String, val body: String,
val author: Profile, val author: Profile,
val id: Long) { val id: Long) {
companion object { companion object {
fun dateFormat(date: OffsetDateTime): String {
return date.toZonedDateTime().withZoneSameInstant(ZoneId.of("Z")).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)
}
fun fromModel(model: io.realworld.model.Comment, currentUser: User): Comment { fun fromModel(model: io.realworld.model.Comment, currentUser: User): Comment {
return Comment( return Comment(
id = model.id, id = model.id,
body = model.body, body = model.body,
createdAt = model.createdAt.format(DateTimeFormatter.ISO_DATE_TIME), createdAt = dateFormat(model.createdAt),
updatedAt = model.updatedAt?.format(DateTimeFormatter.ISO_DATE_TIME), updatedAt = dateFormat(model.updatedAt),
author = Profile.fromUser(model.author, currentUser) author = Profile.fromUser(model.author, currentUser)
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment