Intl.js icon indicating copy to clipboard operation
Intl.js copied to clipboard

toLocaleString `long` options do not seem to work on Android

Open bitttttten opened this issue 6 years ago • 0 comments

I am using this library to help with parsing strings on react native, with luxon. Android has some issues with toLocaleString so following this comment I am using this library which is super nice. Apart from I cannot get "long" to work in toLocaleString.

import { DateTime } from "luxon"
import { Platform } from "react-native"

if (Platform.OS === "android") {
  require("intl")
  require("intl/locale-data/jsonp/en")
  require("intl/locale-data/jsonp/nl")
}

const getPrettyDate = (date: DateTime) => {
  return date.toLocaleString({
    weekday: "long",
    month: "long",
    day: "2-digit",
  })
}

test("getPrettyDate", () => {
  expect(
    getPrettyDate(DateTime.fromRFC2822("Fri, 25 Nov 2016 12:00:00 +0000"))
  ).toBe(`Friday, November 25`)
})

This will fail on Android because it produces the string "Fri, Nov 25" instead of the "long" variant which should be "Friday, November 25". On iOS devices, the above test will pass.

The intl require statements are definitely working, since if I remove the require statements, then getPrettyDate will produce something like "Friday, November 25, 2016, 12:00..".

bitttttten avatar Apr 08 '20 10:04 bitttttten