use utc time

This commit is contained in:
srgooglo 2022-10-12 16:29:58 +02:00
parent 2524afe8d0
commit 8232f8caa5
2 changed files with 10 additions and 2 deletions

View File

@ -15,7 +15,12 @@ export default (props) => {
} }
const updateTimeAgo = () => { const updateTimeAgo = () => {
setTimeAgo(moment(props.postData.created_at ?? "").fromNow()) let createdAt = props.postData.created_at ?? ""
// calculate time ago (use UTC time)
let timeAgo = moment.utc(createdAt).fromNow()
setTimeAgo(timeAgo)
} }
React.useEffect(() => { React.useEffect(() => {

View File

@ -4,11 +4,14 @@ import getPostData from "./getPostData"
export default async (payload) => { export default async (payload) => {
const { user_id, message, additions, type, data } = payload const { user_id, message, additions, type, data } = payload
// set creation date (Must be in UTC)
const created_at = new Date().toISOString()
const post = new Post({ const post = new Post({
user_id: typeof user_id === "object" ? user_id.toString() : user_id, user_id: typeof user_id === "object" ? user_id.toString() : user_id,
message: String(message).toString(), message: String(message).toString(),
additions: additions ?? [], additions: additions ?? [],
created_at: new Date().toISOString(), created_at: created_at,
type: type, type: type,
data: data, data: data,
}) })