Skip to main content
Glama
time.utils.ts943 B
/** * @fileoverview Time utilities for formatting timestamps * Shared across CLI, MCP, extension, and other interfaces */ import { format, formatDistanceToNow } from 'date-fns'; /** * Format a date as relative time from now (e.g., "2 hours ago", "3 days ago") * @param date - Date string or Date object to format * @returns Relative time string (e.g., "less than a minute ago", "5 minutes ago", "2 weeks ago") */ export function formatRelativeTime(date: string | Date): string { const dateObj = typeof date === 'string' ? new Date(date) : date; // Use date-fns for robust formatting with proper edge case handling return formatDistanceToNow(dateObj, { addSuffix: true }); } /** * Format a date as a time string (e.g., "02:30:45 PM") * @param date - Date object to format * @returns Formatted time string in 12-hour format with seconds */ export function formatTime(date: Date): string { return format(date, 'hh:mm:ss a'); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/eyaltoledano/claude-task-master'

If you have feedback or need assistance with the MCP directory API, please join our Discord server