Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#1,065 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, kotlin

调研方向

该错误位于 core/src/main/java/com/nextcloud/android/common/core/utils/DateFormatter.kt 中。首先找到函数 getConditionallyRelativeFormattedTimeSpan 以及针对小于 ONE_HOUR_IN_MILLIS 的时间跨度的分支。修复方法是使用三个参数的 getQuantityString 重载,传递分钟数以进行替换。同时更新 DateFormatterTest.kt 中的相应测试以使用正确的方法。检查荷兰语翻译文件 values-nl/strings.xml 中缺失的复数字符串。运行测试以验证修复。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Java
星标
6
派生
4
平均合并
8 小时 1 分钟
30 天内合并 PR
26

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nextcloud/android-common 的其他 Issue

查看 nextcloud/android-common 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。