You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[OffsetDateTime.format] Different result between robolectric and emulator #7910
When i execute OffsetDateTime.format, different results will occur between Robolectric and Device/Emulator.
Steps to Reproduce
@Test
fun test() {
Locale.setDefault(Locale("en", "AU"))
val time = OffsetDateTime.parse("2023-01-01T10:00:00Z")
val formatter = DateTimeFormatter.ofPattern("d MMM yyyy")
println("FINGERPRINT: ${Build.FINGERPRINT}\nresult:${time.format(formatter)}")
}
Robolectric
device/emulator
Robolectric : 1 Jan. 2023 (with a ".")
Device/Emulator: 1 Jan 2023
Unfortunately OffsetDateTime is a Java core class, so any differences are due to the implementation differences between the JDK and Libcore (Android's implementation of the Java core classes).
Unfortunately OffsetDateTime is a Java core class, so any differences are due to the implementation differences between the JDK and Libcore (Android's implementation of the Java core classes).
We've added a section on Robolectric's website for this case: https://robolectric.org/best-practices/#month-names
As @hoisie pointed out, these classes are part of the Java API, and Robolectric cannot alter their behavior.
You can run your tests on an Android device to get the correct result.
Activity
hoisie commentedon Jan 5, 2023
Unfortunately OffsetDateTime is a Java core class, so any differences are due to the implementation differences between the JDK and Libcore (Android's implementation of the Java core classes).
This is the Android version:
https://cs.android.com/android/platform/superproject/+/master:libcore/ojluni/src/main/java/java/time/OffsetDateTime.java;l=122?q=OffsetDateTime&sq=
okamayana-tinyspeck commentedon May 11, 2023
Is this also the case for
DateTimeFormatter? Also, are there any workarounds?MGaetan89 commentedon Jul 8, 2024
It's the same for
DateTimeFormatter, yes.We have documented it here, for the timezone difference: https://robolectric.org/best-practices/#android-libcore-and-openjdk-have-different-implementations
For your issue regarding month name, we can add a dedicated section, if there is a known alternative/workaround.
MGaetan89 commentedon Jul 17, 2024
We've added a section on Robolectric's website for this case: https://robolectric.org/best-practices/#month-names
As @hoisie pointed out, these classes are part of the Java API, and Robolectric cannot alter their behavior.
You can run your tests on an Android device to get the correct result.