Skip to content

[Studio] Implement format utility functions - #660

Open
zhaohai666 wants to merge 1 commit into
apache:rocketmq-studiofrom
zhaohai666:pr-fe-02-format-utilities
Open

[Studio] Implement format utility functions#660
zhaohai666 wants to merge 1 commit into
apache:rocketmq-studiofrom
zhaohai666:pr-fe-02-format-utilities

Conversation

@zhaohai666

Copy link
Copy Markdown

Summary

Replace TODO stub implementations in format.ts with full-featured utility
functions used across the dashboard.

  • formatDateTime(date): Format to 'YYYY-MM-DD HH:mm:ss' with proper padding
  • formatDate(date): Format to 'YYYY-MM-DD' (was a TODO returning raw string)
  • formatBytes(bytes, decimals?): Human-readable 1024-based formatting
    (was a TODO returning raw 'X B'), handles zero and negative values
  • formatNumber(num): Thousands separator formatting (e.g. 1234567 → '1,234,567')
  • formatDelay(seconds, lang?): Duration formatting with i18n support
    (zh: "22小时55分钟", en: "22h 55m")
  • formatPercent(value, decimals?): Fixed-decimal percentage formatting

All functions are pure with no side effects, making them easy to test and reuse.

Test plan

  • Verify formatDateTime handles valid dates, invalid dates, and string input
  • Verify formatBytes: 0 → '0 B', 1536 → '1.5 KB', 1048576 → '1 MB'
  • Verify formatDelay: 82500 → '22小时55分钟' (zh), '22h 55m' (en)
  • Verify formatPercent: 99.5 → '99.5%'

…ay, percent)

Replace TODO stub implementations in format.ts with full-featured utilities:
- formatDateTime / formatDate: proper date formatting with padding
- formatBytes: human-readable 1024-based byte formatting
- formatNumber: thousands separator formatting
- formatDelay: duration formatting with i18n support (zh/en)
- formatPercent: fixed-decimal percentage formatting
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.

1 participant