Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor([migrate-two-remaining-local-formatters]): consolidate EventDetail/TaskItem formatters into shared utils

Adam Eivyb3463a307b0b
diff --git a/client/src/components/calendar/EventDetail.jsx b/client/src/components/calendar/EventDetail.jsx
index aab1ae11da..ca64b85393 100644
--- a/client/src/components/calendar/EventDetail.jsx
+++ b/client/src/components/calendar/EventDetail.jsx
@@ -1,4 +1,5 @@
import { X, MapPin, Clock, Users, Repeat, CalendarDays } from 'lucide-react';
+import { formatEventDateTime } from '../../utils/formatters';
const RSVP_STYLES = {
accepted: 'bg-port-success/20 text-port-success',
@@ -7,11 +8,6 @@ const RSVP_STYLES = {
none: 'bg-gray-700 text-gray-400'
};
-function formatDateTime(dateStr, isAllDay) {
- if (isAllDay) return new Date(dateStr).toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' });
- return new Date(dateStr).toLocaleString([], { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
-}
-
export default function EventDetail({ event, onClose }) {
return (
<div className="fixed inset-0 z-50 flex justify-end">
@@ -47,13 +43,13 @@ export default function EventDetail({ event, onClose }) {
</div>
) : (
<>
- <div>{formatDateTime(event.startTime, false)}</div>
+ <div>{formatEventDateTime(event.startTime)}</div>
<div className="text-gray-500">to</div>
- <div>{formatDateTime(event.endTime, false)}</div>
+ <div>{formatEventDateTime(event.endTime)}</div>
</>
)}
{event.isAllDay && (
- <div className="mt-1 text-gray-500">{formatDateTime(event.startTime, true)}</div>
+ <div className="mt-1 text-gray-500">{formatEventDateTime(event.startTime, { allDay: true })}</div>
)}
</div>
</div>
diff --git a/client/src/components/cos/tabs/TaskItem.jsx b/client/src/components/cos/tabs/TaskItem.jsx
index c65fea9629..fc5904fddf 100644
--- a/client/src/components/cos/tabs/TaskItem.jsx
+++ b/client/src/components/cos/tabs/TaskItem.jsx
@@ -20,6 +20,7 @@ import {
import toast from '../../ui/Toast';
import * as api from '../../../services/api';
import { filterSelectableModels } from '../../../utils/providers';
+import { formatDurationMin } from '../../../utils/formatters';
const statusIcons = {
pending: <Clock size={16} aria-hidden="true" className="text-yellow-500" />,
@@ -75,16 +76,6 @@ function extractTaskType(description) {
return 'feature';
}
-// Format duration in minutes
-function formatDurationMin(mins) {
- if (mins >= 60) {
- const hours = Math.floor(mins / 60);
- const remainingMins = mins % 60;
- return remainingMins > 0 ? `~${hours}h ${remainingMins}m` : `~${hours}h`;
- }
- return `~${mins}m`;
-}
-
// Format file size for display
function formatAttachmentSize(bytes) {
if (!bytes) return '';
@@ -261,7 +252,7 @@ export default function TaskItem({ task, isSystem, awaitingApproval, onRefresh,
title={`Based on ${durationEstimate.basedOn} completed ${durationEstimate.taskType} tasks`}
>
<Timer size={10} aria-hidden="true" />
- {formatDurationMin(durationEstimate.estimatedMin)}
+ {formatDurationMin(durationEstimate.estimatedMin, { approximate: true })}
</span>
)}
{/* Success rate indicator for pending tasks */}
diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.js
index 3d56575fc0..adb167d9d3 100644
--- a/client/src/utils/formatters.js
+++ b/client/src/utils/formatters.js
@@ -240,16 +240,40 @@ export function formatDurationMs(ms) {
/**
* Format a duration in minutes as a human-readable string
* @param {number} minutes - Duration in minutes
- * @returns {string} Formatted duration (e.g., "30m", "1h 30m", "2h")
+ * @param {object} [options]
+ * @param {boolean} [options.approximate=false] - Prefix the result with `~`
+ * to signal an estimate (e.g., "~1h 30m") for predicted/averaged durations.
+ * @returns {string} Formatted duration (e.g., "30m", "1h 30m", "2h", "~2h")
*/
-export function formatDurationMin(minutes) {
+export function formatDurationMin(minutes, { approximate = false } = {}) {
if (minutes == null) return '';
+ const prefix = approximate ? '~' : '';
if (minutes >= 60) {
const h = Math.floor(minutes / 60);
const m = minutes % 60;
- return m ? `${h}h ${m}m` : `${h}h`;
+ return m ? `${prefix}${h}h ${m}m` : `${prefix}${h}h`;
}
- return `${minutes}m`;
+ return `${prefix}${minutes}m`;
+}
+
+/**
+ * Format a calendar event's date+time, with a distinct all-day rendering.
+ * Tuned for the event-detail panel: timed events show a short weekday plus
+ * time (e.g. "Sat, Apr 1, 1:30 PM"); all-day events show a full weekday and
+ * year (e.g. "Saturday, April 1, 2026"). Kept separate from `formatDateTime`
+ * because the weekday-led shape is event-specific.
+ * @param {string|Date|null} dateStr - ISO timestamp or Date object
+ * @param {object} [options]
+ * @param {boolean} [options.allDay=false] - Render date-only (all-day event).
+ * @returns {string} Formatted event date/time, or '' for missing/invalid input
+ */
+export function formatEventDateTime(dateStr, { allDay = false } = {}) {
+ if (!dateStr) return '';
+ const date = new Date(dateStr);
+ if (Number.isNaN(date.getTime())) return '';
+ // All-day events render exactly like `formatDateFull` (full weekday + year).
+ if (allDay) return formatDateFull(date);
+ return date.toLocaleString([], { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
}
/**
diff --git a/client/src/utils/formatters.test.js b/client/src/utils/formatters.test.js
new file mode 100644
index 0000000000..ac1be1bfd3
--- /dev/null
+++ b/client/src/utils/formatters.test.js
@@ -0,0 +1,55 @@
+import { describe, it, expect } from 'vitest';
+import { formatDurationMin, formatEventDateTime } from './formatters.js';
+
+describe('formatDurationMin', () => {
+ it('formats sub-hour, exact-hour, and hour+min durations', () => {
+ expect(formatDurationMin(30)).toBe('30m');
+ expect(formatDurationMin(60)).toBe('1h');
+ expect(formatDurationMin(90)).toBe('1h 30m');
+ expect(formatDurationMin(120)).toBe('2h');
+ });
+
+ it('returns empty string for null/undefined', () => {
+ expect(formatDurationMin(null)).toBe('');
+ expect(formatDurationMin(undefined)).toBe('');
+ });
+
+ it('does not prefix by default — existing callers stay unchanged', () => {
+ expect(formatDurationMin(90)).toBe('1h 30m');
+ expect(formatDurationMin(45)).toBe('45m');
+ });
+
+ it('prefixes with ~ when approximate (TaskItem estimate semantics)', () => {
+ expect(formatDurationMin(30, { approximate: true })).toBe('~30m');
+ expect(formatDurationMin(60, { approximate: true })).toBe('~1h');
+ expect(formatDurationMin(210, { approximate: true })).toBe('~3h 30m');
+ });
+});
+
+describe('formatEventDateTime', () => {
+ // Local-time ISO (no trailing Z) so parsing is deterministic relative to
+ // the test runtime's timezone.
+ const sample = '2026-04-01T13:30:00';
+
+ it('returns empty string for missing/invalid input', () => {
+ expect(formatEventDateTime(null)).toBe('');
+ expect(formatEventDateTime('')).toBe('');
+ expect(formatEventDateTime('not-a-date')).toBe('');
+ });
+
+ it('renders a timed event with short weekday + time', () => {
+ expect(formatEventDateTime(sample)).toBe(
+ new Date(sample).toLocaleString([], { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' })
+ );
+ });
+
+ it('renders an all-day event as a full weekday + year date', () => {
+ expect(formatEventDateTime(sample, { allDay: true })).toBe(
+ new Date(sample).toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' })
+ );
+ });
+
+ it('all-day and timed renderings differ', () => {
+ expect(formatEventDateTime(sample, { allDay: true })).not.toBe(formatEventDateTime(sample));
+ });
+});