mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
improve time ago calculation
This commit is contained in:
parent
523b320888
commit
0b70162a11
@ -52,7 +52,9 @@
|
|||||||
"jwt-decode": "3.1.2",
|
"jwt-decode": "3.1.2",
|
||||||
"less": "4.1.2",
|
"less": "4.1.2",
|
||||||
"linebridge": "0.13.0",
|
"linebridge": "0.13.0",
|
||||||
|
"luxon": "^3.0.4",
|
||||||
"moment": "2.29.1",
|
"moment": "2.29.1",
|
||||||
|
"moment-timezone": "^0.5.37",
|
||||||
"mpegts.js": "^1.6.10",
|
"mpegts.js": "^1.6.10",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"plyr": "^3.6.12",
|
"plyr": "^3.6.12",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import moment from "moment"
|
|
||||||
import classnames from "classnames"
|
import classnames from "classnames"
|
||||||
|
import momentTimezone from "moment-timezone"
|
||||||
|
import { DateTime } from "luxon"
|
||||||
|
|
||||||
import { Image } from "components"
|
import { Image } from "components"
|
||||||
import { Icons } from "components/Icons"
|
import { Icons } from "components/Icons"
|
||||||
@ -17,8 +18,11 @@ export default (props) => {
|
|||||||
const updateTimeAgo = () => {
|
const updateTimeAgo = () => {
|
||||||
let createdAt = props.postData.created_at ?? ""
|
let createdAt = props.postData.created_at ?? ""
|
||||||
|
|
||||||
// calculate time ago (use UTC time)
|
const inputTimezone = momentTimezone.tz(createdAt).tz()
|
||||||
let timeAgo = moment.utc(createdAt).fromNow()
|
|
||||||
|
const inputTimeInLocalTimezone = momentTimezone.tz(createdAt, inputTimezone).tz(momentTimezone.tz.guess()).format()
|
||||||
|
|
||||||
|
const timeAgo = DateTime.fromISO(inputTimeInLocalTimezone).toRelative()
|
||||||
|
|
||||||
setTimeAgo(timeAgo)
|
setTimeAgo(timeAgo)
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
"formidable": "^2.0.1",
|
"formidable": "^2.0.1",
|
||||||
"jsonwebtoken": "8.5.1",
|
"jsonwebtoken": "8.5.1",
|
||||||
"linebridge": "0.13.0",
|
"linebridge": "0.13.0",
|
||||||
|
"luxon": "^3.0.4",
|
||||||
"minio": "^7.0.32",
|
"minio": "^7.0.32",
|
||||||
"moment": "2.29.1",
|
"moment": "2.29.1",
|
||||||
|
"moment-timezone": "^0.5.37",
|
||||||
"mongoose": "6.1.9",
|
"mongoose": "6.1.9",
|
||||||
"nanoid": "3.2.0",
|
"nanoid": "3.2.0",
|
||||||
"passport": "0.5.2",
|
"passport": "0.5.2",
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { Post } from "../../../models"
|
import { Post } from "../../../models"
|
||||||
import getPostData from "./getPostData"
|
import getPostData from "./getPostData"
|
||||||
|
import momentTimezone from "moment-timezone"
|
||||||
|
|
||||||
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 current_timezone = momentTimezone.tz.guess()
|
||||||
const created_at = new Date().toISOString()
|
const created_at = momentTimezone.tz(Date.now(), current_timezone).format()
|
||||||
|
|
||||||
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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user