refactor(datetime): Standardize date/time formatting with DateUtils#4164
Merged
Conversation
This commit centralizes and refactors date, time, and relative time formatting to use Android's built-in `DateUtils` and `DateFormat` utilities. This change ensures consistent, locale-aware formatting across the application and removes custom implementations. Key changes include: * **Centralized `formatAgo`**: Moved the `formatAgo` function from `core/model` to `core/ui/util` and rewrote it to use `DateUtils.getRelativeTimeSpanString` for accurate and translatable relative time spans (e.g., "5 min. ago"). * **Locale-Aware Date/Time Pickers**: Updated `EditWaypointDialog` to use `android.text.format.DateFormat.getDateFormat(context)` and `getTimeFormat(context)` instead of `SimpleDateFormat`. This respects the user's system settings for date and time formatting (e.g., MM/dd/yyyy vs. dd/MM/yyyy, 12/24-hour clock). * **Standardized Timestamp Formatting**: Replaced `DateFormat.getDateTimeInstance` with `DateUtils.formatDateTime` in various UI components like `PositionLog`, `TracerouteLog`, and `MapView` to provide a consistent, abbreviated date/time representation. * **Code Cleanup**: Removed now-redundant `DateFormat` instances and simplified function signatures by removing `dateFormat` parameters where it's now handled centrally. * **String Resources**: Added new string resources for the debugging screens to improve localization. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4164 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 2 2
Lines 19 19
Branches 7 7
=====================================
Misses 19 19 ☔ View full report in Codecov by Sentry. |
Improves the `formatAgo` utility to display "now" for timestamps less than a minute ago. Previously, `formatAgo` would display "0 min. ago". This change makes the function a Composable to access string resources and adds logic to return "now" for very recent times, providing a more intuitive user experience. A new string resource for "now" has been added. resolves #4115 Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Removes the `@Composable` annotation from the `formatAgo` utility function. This change allows it to be called from non-composable contexts. The implementation is updated to use a direct `getString` call for string resources instead of the composable `stringResource`. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit centralizes and refactors date, time, and relative time formatting to use Android's built-in
DateUtilsandDateFormatutilities. This change ensures consistent, locale-aware formatting across the application and removes custom implementations.Key changes include:
formatAgo: Moved theformatAgofunction fromcore/modeltocore/ui/utiland rewrote it to useDateUtils.getRelativeTimeSpanStringfor accurate and translatable relative time spans (e.g., "5 min. ago").EditWaypointDialogto useandroid.text.format.DateFormat.getDateFormat(context)andgetTimeFormat(context)instead ofSimpleDateFormat. This respects the user's system settings for date and time formatting (e.g., MM/dd/yyyy vs. dd/MM/yyyy, 12/24-hour clock).DateFormat.getDateTimeInstancewithDateUtils.formatDateTimein various UI components likePositionLog,TracerouteLog, andMapViewto provide a consistent, abbreviated date/time representation.DateFormatinstances and simplified function signatures by removingdateFormatparameters where it's now handled centrally.resolves #4115 by providing a translatable "now" string