#25·cli

Duplicate parseTimestamp() logic across commands

Author: MayurK-cmdCreated Aug 26, 2026Updated Aug 26, 2026

Both SpotCommand and PerpsCommand implement similar but inconsistent parseTimestamp() methods. Spot converts to ISO format (new Date(ms).toISOString()), while Perps converts to Unix seconds. This duplication makes maintenance harder and creates risk of subtle bugs if timestamp handling needs to change.

Expected behavior:

  • Single shared implementation in src/lib/
  • Both commands use the same function
  • Consistent timestamp handling across all commands

Current behavior:

  • SpotCommand.parseTimestamp(): lines 930-938(returns ISO string)
  • PerpsCommand.parseTimestamp(): lines 906-914 (returns Unix seconds)
  • Different behavior, duplicated code

Locations:

  • src/commands/SpotCommand.ts:930-938
  • src/commands/PerpsCommand.ts:906-914

Suggested fix: Create src/lib/DateConverter.ts: export class DateConverter { public static parseTimestamp(value: string): string { if(/^\d+$/.test(value)) { return value; // assume Unix timestamp } const ms = new Date(value).getTime(); if (isNaN(ms)) { throw new Error(Invalid date: ${value}); } return String(Math.floor(ms / 1000)); // return Unix seconds } }

Then replace both implementations with DateConverter.parseTimestamp().

Type: Refactor - Code Quality