getConditionallyRelativeFormattedTimeSpan shows literal %dm instead of a number for anything under 1 hour
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- internationalization, mobile
Research direction
The bug is in core/src/main/java/com/nextcloud/android/common/core/utils/DateFormatter.kt. Start by locating the function getConditionallyRelativeFormattedTimeSpan and the branch for spans less than ONE_HOUR_IN_MILLIS. The fix is to use the three-argument getQuantityString overload, passing the minutes count for substitution. Also update the corresponding test in DateFormatterTest.kt to use the correct method. Check the Dutch translation file values-nl/strings.xml for the missing plural string while you're there. Run the tests to verify the fix.
Written by the indexing model from the issue text.
Description
Summary
For a timestamp less than an hour old, DateFormatter.getConditionallyRelativeFormattedTimeSpan() returns the literal unsubstituted string %dm instead of e.g. 13m. Reproduced via the Notes app (it.niedermann.owncloud.notes), which uses this library — the note list showed %dm for any note modified 1–59 minutes ago, while notes older than an hour rendered correctly ("10 u" etc.).
Root cause
In core/src/main/java/com/nextcloud/android/common/core/utils/DateFormatter.kt, the "less than 1h" branch calls the 2-argument Resources.getQuantityString(int, int) overload, which selects a plural form but performs no substitution:
span < ONE_HOUR_IN_MILLIS -> {
context.resources
.getQuantityString(
R.plurals.date_formatting_relative_minutes,
span.toInt() / ONE_MINUTE_IN_MILLIS
)
}
Since values/strings.xml defines this plural as <item quantity="other">%dm</item>, the %d is never substituted. The next branch (hours) uses the correct 3-arg overload:
val hours: Int = span.toInt() / ONE_HOUR_IN_MILLIS
context.resources.getQuantityString(R.plurals.date_formatting_relative_hours, hours, hours)
Suggested fix
span < ONE_HOUR_IN_MILLIS -> {
val minutes = span.toInt() / ONE_MINUTE_IN_MILLIS
context.resources.getQuantityString(R.plurals.date_formatting_relative_minutes, minutes, minutes)
}
Note on test coverage
DateFormatterTest.kt's Test relative minutes formatting computes its expected value with the same broken 2-arg call, so it passes despite the bug — worth using the 3-arg form there too once fixed, to actually catch this.
Secondary, unrelated gap
values-nl/strings.xml doesn't translate date_formatting_relative_minutes at all (only date_formatting_now and date_formatting_relative_hours are present), so Dutch falls back to the English base string for that one plural. Doesn't affect the substitution bug either way, but worth completing while in there.
Environment
- Nextcloud Notes app, via
com.nextcloud.android.common:core(whatever version it currently pulls) - LineageOS 22 (Android 15), Dutch (
nl) locale - OnePlus 6
- Dominant language
- Java
- Stars
- 6
- Forks
- 4
- Avg merge
- 6h 28m
- Merged PRs (30d)
- 30
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nextcloud/android-common
-
toolbar icon theming is broken for left and right side iconsMay be free again @AndyScherzinger claimed this 926 days ago, and no pull request is open. Openbug
nextcloud/android-common#333 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
nextcloud/android-common#290 · 1 comment ·
Maintainers usually reply within 1 day
-
Dependency DashboardOpen
Difficulty 4/5 3-5 days Newbie friendliness 10/100
nextcloud/android-common#255 ·
Maintainers usually reply within 1 day
-
common featuresOpenoverview
Difficulty 5/5 Over a week Newbie friendliness 20/100
nextcloud/android-common#56 · 2 comments ·
Maintainers usually reply within 1 day
-
Testing setupOpenenhancement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
nextcloud/android-common#18 ·
Maintainers usually reply within 1 day
All issues in nextcloud/android-common
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openhab/openhab-core#5847 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
apache/parquet-java#3820 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
beehive-lab/jllm#187 ·