Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#1,065 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
android, kotlin

Línea de trabajo

El error está en core/src/main/java/com/nextcloud/android/common/core/utils/DateFormatter.kt. Comience localizando la función getConditionallyRelativeFormattedTimeSpan y la rama para intervalos menores que ONE_HOUR_IN_MILLIS. La solución es usar la sobrecarga getQuantityString de tres argumentos, pasando el recuento de minutos para la sustitución. También actualice la prueba correspondiente en DateFormatterTest.kt para usar el método correcto. Verifique el archivo de traducción al neerlandés values-nl/strings.xml en busca de la cadena plural faltante. Ejecute las pruebas para verificar la corrección.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Java
Estrellas
6
Forks
4
Merge medio
6 h 28 min
PR fusionados (30 d)
30

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nextcloud/android-common

Todos los issues de nextcloud/android-common

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.