Skip to content

Commit

Permalink
Merge pull request #2575 from myxmaster/activity_year_optional
Browse files Browse the repository at this point in the history
Activity: Display year if not current year
  • Loading branch information
kaloudis authored Nov 25, 2024
2 parents d4d4fbb + 1a05d71 commit ffd7543
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions utils/DateTimeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@ class DateTimeUtils {
}
};

listFormattedDateShort = (timestamp: number | string) =>
this.listFormattedDate(timestamp, 'mmm d, HH:MM');
listFormattedDateShort = (timestamp: number | string) => {
const date = new Date(Number(timestamp) * 1000);
const currentYear = new Date().getFullYear();
const dateYear = date.getFullYear();

const format =
dateYear < currentYear ? "mmm d, 'yy, HH:MM" : 'mmm d, HH:MM';

return this.listFormattedDate(timestamp, format);
};

listFormattedDateOrder = (timestamp: Date) => {
const updated = dateFormat(timestamp, 'hh:mm tt');
const day = dateFormat(timestamp, 'ddd, mmm dd');
return `${updated} | ${day}`;
const currentYear = new Date().getFullYear();
const dateYear = timestamp.getFullYear();

const time = dateFormat(timestamp, 'hh:mm tt');
const monthAndDay = dateFormat(timestamp, 'ddd, mmm dd');
const year =
dateYear < currentYear ? `, '${dateFormat(timestamp, 'yy')}` : '';

return `${time} | ${monthAndDay}${year}`;
};
}

Expand Down

0 comments on commit ffd7543

Please sign in to comment.