-
Notifications
You must be signed in to change notification settings - Fork 873
refactor: change how timings are formatted #17623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is a hotfix and has been automatically approved.
- ✅ Base is main or release branch
- ✅ Has hotfix label
- ✅ Head is from coder/coder
- ✅ Less than 100 lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors how timing values are formatted in the WorkspaceTiming module by replacing the multiple unit decomposition with a simplified conditional format based on thresholds.
- Refactored the formatTime function for clearer unit conversion.
- Updated the calculation of formatted time using a single value and unit based on predefined thresholds.
value = time; | ||
unit = "ms"; | ||
} else if (absTime < minute) { | ||
value = time / second; | ||
unit = "s"; | ||
} else if (absTime < hour) { | ||
value = time / minute; | ||
unit = "m"; | ||
} else if (absTime < day) { | ||
value = time / hour; | ||
unit = "h"; | ||
} else { | ||
value = time / day; | ||
unit = "d"; | ||
} | ||
if (hours > 0) { | ||
parts.push(`${hours % 24}h`); | ||
} | ||
if (minutes > 0) { | ||
parts.push(`${minutes % 60}m`); | ||
} | ||
if (seconds > 0) { | ||
parts.push(`${seconds % 60}s`); | ||
} | ||
if (time % 1000 > 0) { | ||
parts.push(`${time % 1000}ms`); | ||
} | ||
|
||
return parts.join(" "); | ||
return `${value.toLocaleString(undefined, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'absTime' for the threshold comparisons but assigning the unmodified 'time' for the value may lead to inconsistent formatting for negative inputs. Consider using 'absTime' for the conversion calculation or explicitly handling negative values.
Copilot uses AI. Check for mistakes.
No description provided.