Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update date formatting to display minutes, hours, days, and months #147

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions app/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,27 @@ export const sleep = (ms: number) => {

export function timeAgo(date: Date) {
const now = new Date();
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
const postedDate = new Date(date.toISOString().replace('Z', '')).getTime();
const seconds = Math.floor((now.getTime() - postedDate) / 1000);

let interval = Math.floor(seconds / 31536000);
if (interval > 1) {
if (interval >= 1) {
return `${interval}y ago`;
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
if (interval >= 1) {
return `${interval}mo ago`;
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
if (interval >= 1) {
return `${interval}d ago`;
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
if (interval >= 1) {
return `${interval}h ago`;
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
if (interval >= 1) {
return `${interval}m ago`;
}
return `Just Now`;
Expand Down