Move formatRelativeDate() to formatText util, add util tests
CI / Lint (pull_request) Successful in 54s
CI / Test (pull_request) Successful in 1m7s
Release Drafter / Update release notes draft (pull_request) Successful in 5s

This commit is contained in:
2026-08-18 16:57:11 -06:00
parent d6e47a1b27
commit 78687b63ff
4 changed files with 94 additions and 25 deletions
+2 -25
View File
@@ -2,26 +2,7 @@ import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { fn } from '@ember/helper';
import or from 'ember-truth-helpers/helpers/or';
function formatRelativeDate(timestamp) {
if (!timestamp) return '';
const date = new Date(timestamp * 1000);
const now = new Date();
const diffMs = now - date;
const diffMin = Math.floor(diffMs / 60000);
const diffHr = Math.floor(diffMin / 60);
const diffDay = Math.floor(diffHr / 24);
if (diffMin < 1) return 'just now';
if (diffMin < 60) return `${diffMin} min ago`;
if (diffHr < 24) return `${diffHr} hr ago`;
if (diffDay < 7) return `${diffDay} day${diffDay === 1 ? '' : 's'} ago`;
return date.toLocaleDateString(undefined, {
year: 'numeric',
month: 'short',
day: 'numeric',
});
}
import formatRelativeDate from '../helpers/format-relative-date';
export default class ContributionPhoto extends Component {
get item() {
@@ -44,10 +25,6 @@ export default class ContributionPhoto extends Component {
return this.item?.placeNameLoading;
}
get relativeDate() {
return formatRelativeDate(this.item?.createdAt);
}
get tags() {
// Collect unique tags across all photos in the contribution group
const all = (this.item?.photos || []).flatMap((p) => p.tags || []);
@@ -86,7 +63,7 @@ export default class ContributionPhoto extends Component {
{{/if}}
</div>
<div class="contribution-meta">
{{this.relativeDate}}
{{formatRelativeDate @item.createdAt}}
{{#if (gt this.item.photos.length 1)}}
·
{{this.item.photos.length}}
+6
View File
@@ -0,0 +1,6 @@
import { helper } from '@ember/component/helper';
import { formatRelativeDate as format } from '../utils/format-text';
export default helper(function formatRelativeDate([timestamp]) {
return format(timestamp);
});
+20
View File
@@ -12,3 +12,23 @@ export function capitalize(text) {
if (typeof text !== 'string' || !text) return '';
return text.charAt(0).toUpperCase() + text.slice(1);
}
export function formatRelativeDate(timestamp) {
if (!timestamp) return '';
const date = new Date(timestamp * 1000);
const now = new Date();
const diffMs = now - date;
const diffMin = Math.floor(diffMs / 60000);
const diffHr = Math.floor(diffMin / 60);
const diffDay = Math.floor(diffHr / 24);
if (diffMin < 1) return 'just now';
if (diffMin < 60) return `${diffMin} min ago`;
if (diffHr < 24) return `${diffHr} hr ago`;
if (diffDay < 7) return `${diffDay} day${diffDay === 1 ? '' : 's'} ago`;
return date.toLocaleDateString(undefined, {
year: 'numeric',
month: 'short',
day: 'numeric',
});
}