Fix timeAgo and notifications

pull/5917/head
Daniel Supernault 8 months ago
parent 115061d9e4
commit 27fa798208
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -142,35 +142,7 @@
},
timeAgo(ts) {
let date = new Date(ts);
let now = new Date();
let seconds = Math.floor((now - date) / 1000);
let interval = Math.floor(seconds / 31536000);
if (interval >= 1) {
return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'year');
}
interval = Math.floor(seconds / 2592000);
if (interval >= 1) {
return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'month');
}
interval = Math.floor(seconds / 604800);
if (interval >= 1) {
return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'week');
}
interval = Math.floor(seconds / 86400);
if (interval >= 1) {
return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'day');
}
interval = Math.floor(seconds / 3600);
if (interval >= 1) {
return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'hour');
}
interval = Math.floor(seconds / 60);
if (interval >= 1) {
return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'minute');
}
return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-seconds, 'second');
return App.util.format.timeAgo(ts);
},
mentionUrl(status) {

@ -151,7 +151,7 @@
</p>
</div>
</div>
<div class="small text-muted font-weight-bold" style="font-size: 0.575em;" st :title="n.created_at">{{timeAgo(n.created_at)}}</div>
<div class="small text-muted font-weight-bold" style="font-size: 12px;" :title="n.created_at">{{timeAgo(n.created_at)}}</div>
</div>
</div>

@ -96,36 +96,40 @@ window.App.util = {
}
return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count);
}),
timeAgo: (function(ts) {
let date = new Date(ts);
let now = new Date();
let seconds = Math.floor((now - date) / 1000);
let interval = Math.floor(seconds / 31536000);
if (interval >= 1) {
return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'year');
}
interval = Math.floor(seconds / 2592000);
timeAgo: (function(ts) {
const date = new Date(ts);
const now = new Date();
const seconds = Math.floor((now - date) / 1000);
const secondsInYear = 60 * 60 * 24 * 365.25;
let interval = Math.floor(seconds / secondsInYear);
if (interval >= 1) {
return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'month');
return interval + "y";
}
interval = Math.floor(seconds / 604800);
interval = Math.floor(seconds / (60 * 60 * 24 * 7));
if (interval >= 1) {
return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'week');
return interval + "w";
}
interval = Math.floor(seconds / 86400);
interval = Math.floor(seconds / (60 * 60 * 24));
if (interval >= 1) {
return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'day');
return interval + "d";
}
interval = Math.floor(seconds / 3600);
interval = Math.floor(seconds / (60 * 60));
if (interval >= 1) {
return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'hour');
return interval + "h";
}
interval = Math.floor(seconds / 60);
if (interval >= 1) {
return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'minute');
return interval + "m";
}
return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-seconds, 'second');
}),
return Math.floor(seconds) + "s";
}),
timeAhead: (function(ts, short = true) {
let date = Date.parse(ts);
let diff = date - Date.parse(new Date());

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save