Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

getConditionallyRelativeFormattedTimeSpan shows literal %dm instead of a number for anything under 1 hour

Open Beginner friendly
#1,065 0 comments 0 reactions 0 assignees View on GitHub

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
Tech stack
android, kotlin

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextcloud/android-common

All issues in nextcloud/android-common

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.