Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize SimpleDateFormat month names #212

Open
mcallisto opened this issue Oct 10, 2020 · 2 comments
Open

Localize SimpleDateFormat month names #212

mcallisto opened this issue Oct 10, 2020 · 2 comments

Comments

@mcallisto
Copy link

mcallisto commented Oct 10, 2020

While running the following test on a scalaJS only module of mine:

import java.text.SimpleDateFormat
import java.util.{Date, Locale}

import org.scalatest.flatspec.AnyFlatSpec

class localeTest extends AnyFlatSpec {

  "A date" can "be formatted according to locale" in {
    val pattern = "dd MMMM yyyy"
    val simpleDateFormat = new SimpleDateFormat(pattern, Locale.ENGLISH)
    assert(simpleDateFormat.format(new Date(0L)) === "01 January 1970")
  }

}

I am not getting a localized month name

"01 [0001] 1970" did not equal "01 [January] 1970"

even if the CLDR data seem in place, data.scala is written and its object _en contains the names of the months.

In order to abstract from my system I have tried the following snippet
https://scastie.scala-lang.org/mcallisto/gdksVpgMRhyKk2ct2lFBww/6
and it fails in a similar fashion.

@cquiroz
Copy link
Owner

cquiroz commented Oct 10, 2020

Support for SimpleDateFormat is not that great, could you try using DateTimeFormatter instead?
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

@mcallisto
Copy link
Author

Trying another snippet with DateTimeFormatter
https://scastie.scala-lang.org/mcallisto/gdksVpgMRhyKk2ct2lFBww/49

But Scastie fails

sbt.librarymanagement.ResolveException: Error downloading io.github.cquiroz:scalajavatime_sjs1_2.13:2.0.0
  Not found

not sure why, ScalaJs 1.1.1 on Scala 2.13.3.

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

No branches or pull requests

2 participants