fix(plugins/base): fix negative months display for account less than one year (#558)
This commit is contained in:
@@ -93,7 +93,9 @@ export default async function({login, q}, {conf, data, rest, graphql, plugins, q
|
|||||||
const created = new Date(data.user.createdAt)
|
const created = new Date(data.user.createdAt)
|
||||||
const diff = now - created
|
const diff = now - created
|
||||||
const years = new Date(diff).getUTCFullYear() - new Date(0).getUTCFullYear()
|
const years = new Date(diff).getUTCFullYear() - new Date(0).getUTCFullYear()
|
||||||
const months = new Date(now).getUTCMonth() - created.getUTCMonth() + 12 * years
|
const nowMonth = new Date(now).getUTCMonth()
|
||||||
|
const createdMonth = created.getUTCMonth()
|
||||||
|
const months = nowMonth - createdMonth + 12 * (years + (nowMonth < createdMonth ? 1 : 0))
|
||||||
const days = Math.floor((now - beginningOfYear) / (1000 * 60 * 60 * 24))
|
const days = Math.floor((now - beginningOfYear) / (1000 * 60 * 60 * 24))
|
||||||
computed.registered = {years: years + days / 365.25, months}
|
computed.registered = {years: years + days / 365.25, months}
|
||||||
computed.registration = years ? `${years} year${imports.s(years)} ago` : months ? `${months} month${imports.s(months)} ago` : `${days} day${imports.s(days)} ago`
|
computed.registration = years ? `${years} year${imports.s(years)} ago` : months ? `${months} month${imports.s(months)} ago` : `${days} day${imports.s(days)} ago`
|
||||||
|
|||||||
Reference in New Issue
Block a user