Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,065 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
android, kotlin

Hướng nghiên cứu

Lỗi nằm trong core/src/main/java/com/nextcloud/android/common/core/utils/DateFormatter.kt. Hãy bắt đầu bằng cách định vị hàm getConditionallyRelativeFormattedTimeSpan và nhánh cho khoảng thời gian nhỏ hơn ONE_HOUR_IN_MILLIS. Cách sửa là sử dụng quá tải getQuantityString ba đối số, truyền số phút để thay thế. Đồng thời cập nhật bài kiểm tra tương ứng trong DateFormatterTest.kt để sử dụng phương thức đúng. Kiểm tra tệp dịch tiếng Hà Lan values-nl/strings.xml để tìm chuỗi số nhiều còn thiếu. Chạy các bài kiểm tra để xác minh bản sửa lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Java
Star
6
Fork
4
Merge trung bình
6 giờ 28 phút
Pull request đã merge (30 ngày)
30

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nextcloud/android-common

Tất cả issue của nextcloud/android-common

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.