getConditionallyRelativeFormattedTimeSpan shows literal %dm instead of a number for anything under 1 hour
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
该错误位于 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
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nextcloud/android-common 的其他 Issue
-
toolbar icon theming is broken for left and right side icons可能重新可做 @AndyScherzinger 于 929 天前认领,目前没有进行中的 PR。 未关闭bug
nextcloud/android-common#333 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
nextcloud/android-common#290 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 10/100
nextcloud/android-common#255 ·
维护者通常 1 天内回复
-
common features未关闭overview
难度 5/5 一周以上 新手友好度 20/100
nextcloud/android-common#56 · 2 条评论 ·
维护者通常 1 天内回复
-
Testing setup未关闭enhancement
难度 4/5 3-5 天 新手友好度 25/100
nextcloud/android-common#18 ·
维护者通常 1 天内回复
查看 nextcloud/android-common 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
github/copilot-sdk#2793 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
enhancement good first issue
难度 1/5 1-3 小时 新手友好度 88/100