Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#1,065 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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 未満の期間の分岐を見つけてください。修正は、3引数の 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分
マージ済み PR(30日)
26

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nextcloud/android-common のほかの issue

nextcloud/android-common の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。