Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

toLocaleString long options do not seem to work on Android #340

Open
bitttttten opened this issue Apr 8, 2020 · 0 comments
Open

toLocaleString long options do not seem to work on Android #340

bitttttten opened this issue Apr 8, 2020 · 0 comments

Comments

@bitttttten
Copy link

bitttttten commented Apr 8, 2020

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..".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant