diff --git a/source/plugins/achievements/list/organizations.mjs b/source/plugins/achievements/list/organizations.mjs index 084fccc5..f1f6b3b1 100644 --- a/source/plugins/achievements/list/organizations.mjs +++ b/source/plugins/achievements/list/organizations.mjs @@ -143,7 +143,7 @@ export default async function({list, login, data, computed, imports, graphql, qu //Member { - const value = computed.registered.diff + const { years: value } = computed.registered const unlock = null list.push({ diff --git a/source/plugins/achievements/list/users.mjs b/source/plugins/achievements/list/users.mjs index 6569ffb5..0745f41e 100644 --- a/source/plugins/achievements/list/users.mjs +++ b/source/plugins/achievements/list/users.mjs @@ -219,7 +219,7 @@ export default async function({list, login, data, computed, imports, graphql, qu //Member { - const value = computed.registered.diff + const { years: value } = computed.registered const unlock = null list.push({ diff --git a/source/plugins/core/index.mjs b/source/plugins/core/index.mjs index db947527..a198f2ba 100644 --- a/source/plugins/core/index.mjs +++ b/source/plugins/core/index.mjs @@ -88,11 +88,15 @@ export default async function({login, q}, {conf, data, rest, graphql, plugins, q computed.commits += data.user.contributionsCollection.totalCommitContributions + data.user.contributionsCollection.restrictedContributionsCount //Compute registration date - const diff = (Date.now() - (new Date(data.user.createdAt)).getTime()) / (365 * 24 * 60 * 60 * 1000) - const years = Math.floor(diff) - const months = Math.floor((diff - years) * 12) - computed.registered = {years, months, diff} - computed.registration = years ? `${years} year${imports.s(years)} ago` : months ? `${months} month${imports.s(months)} ago` : `${Math.ceil(diff * 365)} day${imports.s(Math.ceil(diff * 365))} ago` + const now = Date.now() + const beginningOfYear = new Date(now).setUTCMonth(0, 1) + const created = new Date(data.user.createdAt) + const diff = now - created + const years = new Date(diff).getUTCFullYear() - new Date(0).getUTCFullYear() + const months = new Date(now).getUTCMonth() - created.getUTCMonth() + 12 * years + const days = Math.floor((now - beginningOfYear) / (1000 * 60 * 60 * 24)) + 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.cakeday = years > 1 ? [new Date(), new Date(data.user.createdAt)].map(date => date.toISOString().match(/(?\d{2}-\d{2})(?=T)/)?.groups?.mmdd).every((v, _, a) => v === a[0]) : false //Compute calendar