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.*
@Entity
data class Comment(var createdAt: OffsetDateTime = OffsetDateTime.now(),
var updatedAt: OffsetDateTime? = null,
var updatedAt: OffsetDateTime = OffsetDateTime.now(),
var body: String = "",
@ManyToOne
var article: Article = Article(),
......
......@@ -2,21 +2,27 @@ package io.realworld.model.inout
import com.fasterxml.jackson.annotation.JsonRootName
import io.realworld.model.User
import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
@JsonRootName("comment")
data class Comment(val createdAt: String,
val updatedAt: String?,
val updatedAt: String,
val body: String,
val author: Profile,
val id: Long) {
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 {
return Comment(
id = model.id,
body = model.body,
createdAt = model.createdAt.format(DateTimeFormatter.ISO_DATE_TIME),
updatedAt = model.updatedAt?.format(DateTimeFormatter.ISO_DATE_TIME),
createdAt = dateFormat(model.createdAt),
updatedAt = dateFormat(model.updatedAt),
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