From 593bca86a971b707390ab395b061ca23499cb757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Wed, 17 Jul 2024 14:48:56 +0200 Subject: [PATCH] Document differences in month names between Android and OpenJDK (#274) --- docs/best-practices.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/best-practices.md b/docs/best-practices.md index 923fc1637..62dbda1d2 100644 --- a/docs/best-practices.md +++ b/docs/best-practices.md @@ -26,12 +26,20 @@ Below is an incomplete list of differences you may encounter: #### Timezone handling -When using [`SimpleDateFormat#parse()`](https://developer.android.com/reference/kotlin/java/text/SimpleDateFormat#parse) to parse a timezone using the `Z` marker, Android supports time zones with a colon (ie. `08:00`), while OpenJDK doesn't (ie. `0800`). +When using [`SimpleDateFormat#parse()`](https://developer.android.com/reference/kotlin/java/text/SimpleDateFormat#parse) to parse a timezone using the `Z` marker, Android supports time zones with a colon (i.e. `08:00`), while OpenJDK doesn't (i.e. `0800`). -To workaround this: +To work around this: - If your min SDK version is 24 or higher, you can use the `X` marker instead. - Use the `java.time` API, with [library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) enabled. - Run the corresponding tests using regular Android tests. **Related issues:** [#1030](https://github.com/robolectric/robolectric/issues/1030), [#1257](https://github.com/robolectric/robolectric/issues/1257), [#5220](https://github.com/robolectric/robolectric/issues/5220). + +#### Month names + +When using [`DateTimeFormatter.ofPattern(String)`](https://developer.android.com/reference/kotlin/java/time/format/DateTimeFormatter#ofpattern) to create a formatter displaying a short month name (using the `MMM` pattern), Android will use three-characters names (i.e. `Jan`), while OpenJDK will use three-characters names followed by a period (i.e. `Jan.`). + +In this case, we recommend running the corresponding tests as regular Android tests. + +**Related issues:** [#7910](https://github.com/robolectric/robolectric/issues/7910).