/** * Formatting helpers for the SequenceViewer component. * Extracted for testability and reuse. */ /** * Determines the CSS arrow direction class based on message direction. * "CPE→ACS" messages point left-to-right (arrow-right). * "ACS→CPE" messages point right-to-left (arrow-left). */ export function getArrowClass(direction: 'CPE→ACS' | 'ACS→CPE'): 'arrow-right' | 'arrow-left' { return direction === 'CPE→ACS' ? 'arrow-right' : 'arrow-left' } /** * Formats an ISO 8601 timestamp into HH:mm:ss.SSS display format. * Uses UTC time to ensure consistent formatting regardless of timezone. */ export function formatTimestamp(isoTimestamp: string): string { const date = new Date(isoTimestamp) const hours = String(date.getUTCHours()).padStart(2, '0') const minutes = String(date.getUTCMinutes()).padStart(2, '0') const seconds = String(date.getUTCSeconds()).padStart(2, '0') const millis = String(date.getUTCMilliseconds()).padStart(3, '0') return `${hours}:${minutes}:${seconds}.${millis}` } /** * Truncates a CWMP method name to 40 characters if it exceeds that length. * Appends an ellipsis character (…) when truncated. */ export function truncateMethod(method: string): string { if (method.length > 40) { return method.substring(0, 40) + '…' } return method } /** * Returns true if the method name exceeds 40 characters and needs truncation. */ export function needsTruncation(method: string): boolean { return method.length > 40 } /** * Formats a trace start time ISO string into a localized display string. */ export function formatTraceStartTime(iso: string): string { return new Date(iso).toLocaleString() }