getConditionallyRelativeFormattedTimeSpan shows literal %dm instead of a number for anything under 1 hour
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
- Lĩnh vực
- internationalization, mobile
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nextcloud/android-common
-
toolbar icon theming is broken for left and right side iconsCó thể làm lại được @AndyScherzinger đã nhận 927 ngày trước và không có pull request nào đang mở. Đang mởbug
nextcloud/android-common#333 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Discussion: naming schemeĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
nextcloud/android-common#290 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dependency DashboardĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 10/100
nextcloud/android-common#255 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
common featuresĐang mởoverview
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
nextcloud/android-common#56 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Testing setupĐang mởenhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
nextcloud/android-common#18 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của nextcloud/android-common
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Black theme and viewing mode.Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
oracle/javavscode#652 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenAPITools/openapi-generator#25014 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
AloisSeckar/demos-java#380 ·