Refactor date range formatting using enum-based approach. #8
+1,450
−1,180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor date range formatting using enum-based approach for improved maintainability
Description
This PR introduces a significant refactoring of the date range formatting functionality. The main goal is to improve code organization, readability, and maintainability while preserving the existing behavior. The changes introduce an enum-based approach to categorize different date range scenarios, allowing for a more structured and extensible codebase.
Changes Made
DateRangeType
enum to categorize different date range scenarios.formatDateRange
function to use a switch statement based onDateRangeType
.formatYear
formatQuarter
formatMonth
formatAcrossYears
formatAcrossMonths
formatAcrossDays
formatSameDay
Motivation
The previous implementation of date range formatting, while functional, lacked clear separation of concerns for different date range scenarios. This refactoring aims to make the code more modular, easier to understand, and simpler to extend in the future.
Testing
Performance Considerations
While the new implementation introduces additional function calls, the performance impact is expected to be negligible. The benefits in code clarity and maintainability outweigh any minor performance costs.
Additional Notes for Reviewers
determineDateRangeType
function, as it's crucial for correctly categorizing date ranges.formatSameDay
function now takes an object as an argument for improved readability. Please review if this approach aligns with the project's conventions.Thank you for reviewing this PR. Your feedback and suggestions are greatly appreciated!