28 lines
702 B
JavaScript
28 lines
702 B
JavaScript
const moment = require('moment-jalaali')
|
|
|
|
function formatLastOnlineStatus(lastOnlineDate, ghostMode = false) {
|
|
if (ghostMode) return 'نامشخص'
|
|
if (!lastOnlineDate) return 'آفلاین'
|
|
|
|
const now = moment()
|
|
const lastOnline = moment(lastOnlineDate)
|
|
if (!lastOnline.isValid()) return 'آفلاین'
|
|
|
|
const diffMinutes = now.diff(lastOnline, 'minutes')
|
|
|
|
if (diffMinutes < 1) {
|
|
return 'آنلاین'
|
|
}
|
|
if (diffMinutes < 60) {
|
|
return `${diffMinutes} دقیقه پیش`
|
|
}
|
|
if (diffMinutes < 1440) {
|
|
return `${Math.floor(diffMinutes / 60)} ساعت پیش`
|
|
}
|
|
return `${Math.floor(diffMinutes / 1440)} روز پیش`
|
|
}
|
|
|
|
module.exports = {
|
|
formatLastOnlineStatus
|
|
}
|