Skip to content

refactor: extract shared parseTimestamp utility to avoid duplication - #30

Open
MayurK-cmd wants to merge 1 commit into
jup-ag:mainfrom
MayurK-cmd:fix/extract-shared-parse-timestamp-utility
Open

refactor: extract shared parseTimestamp utility to avoid duplication#30
MayurK-cmd wants to merge 1 commit into
jup-ag:mainfrom
MayurK-cmd:fix/extract-shared-parse-timestamp-utility

Conversation

@MayurK-cmd

Copy link
Copy Markdown

Refactor: extract shared parseTimestamp utility to avoid duplication

Both SpotCommand and PerpsCommand implemented identical parseTimestamp()
logic to convert user input (ISO dates or UNIX timestamps) to Unix seconds.
This duplication made maintenance harder and created risk if timestamp
handling needed to change.

Created new DateConverter utility class with a shared parseTimestamp()
method that both commands now use. This ensures consistent behavior across
all commands that need to parse timestamps.

Changes:

  • Create src/lib/DateConverter.ts with parseTimestamp() utility
  • Replace implementation in SpotCommand.parseTimestamp()
  • Replace implementation in PerpsCommand.parseTimestamp()
  • Removes2 duplicate implementations (9 lines each)

No functional changes — same behavior, less code.

Fixes: #25

Both SpotCommand and PerpsCommand had duplicate parseTimestamp() methods
with inconsistent behavior. Created shared DateConverter.parseTimestamp()
utility to ensure consistent timestamp handling across all commands.

Changes:
- Create src/lib/DateConverter.ts with parseTimestamp() method
- Update SpotCommand to use DateConverter.parseTimestamp()
- Update PerpsCommand to use DateConverter.parseTimestamp()
- Reduces code duplication by 2 implementations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate parseTimestamp() logic across commands

1 participant