Skip to content

A j2cl compatible subset of the many classes belonging to the java.text package.

License

Notifications You must be signed in to change notification settings

mP1/j2cl-java-text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status License Language grade: Java Total alerts J2CL compatible

java.text j2cl

This aims to provide most of the basics of the java.text package. Note while most of the core functionality is present, some parts are methods are missing. Care should be taken when selecting locales and other extracted data to avoid very large amounts of data being extracted resulting in javascript with huge strings holding this data.

DecimalFormat

Note there are some differences between the JDK and emulated DecimalFormat. Where possible behaviour is matched using black box approach, with multiple tests that perform the same operation with the same parameters and then compare state or results such as output from format or parse.

pattern parsing

The JDK DecimalFormat parse of patterns has some strange quirks resulting in the negative suffix in the pattern being ignored, and empty string returned. An example of this counter intuitive behaviour is given below.

new java.text.DecimalFormat("P#S;PP##SS").getNegativeSuffix() // returns empty and not SS

parse string with number

The minimumIntegerDigits, maximumFractionDigits and minimumFractionDigits are not actually honoured by DecimalFormat.parse.

This example demonstrates that the minimumIntegerDigit count is ignored during parsing and the number returned.

java.text.DecimalFormat f = new java.text.DecimalFormat("000");
f.getMaximumIntegerDigits(); // returns 2147483647
f.getMinimumIntegerDigits(); // returns 3
f.parse("1"); // returns 1

This example demonstrates that the maximumFractionDigits count is ignored, because the string has more fraction digits than the pattern.

java.text.DecimalFormat f = new java.text.DecimalFormat("#");
f.getMaximumFractionDigits(); // returns 0
f.getMinimumFractionDigits(); // returns 0
f.parse("1.25"); // returns 1.25

This example demonstrates that the maximumFractionDigits count is ignored, because the string has less fraction digits than the pattern.

java.text.DecimalFormat f = new java.text.DecimalFormat("#.0000");
f.getMaximumFractionDigits(); // returns 4
f.getMinimumFractionDigits(); // returns 4
f.parse("1.5"); // returns 1.5

To match compatibility the behaviour of ignoring the counts are ignored.

SimpleDateFormat

Is an almost complete replacement for java.text.SimpleDateFormat supporting formatting and parsing pattern letters.

  • java.text.ParsePosition index and errorIndex is supported and matches the behaviour or the JRE class.
  • WEEK_YEAR which is represented by the pattern letter "Y" TODO format TODO parse
SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
f.parse("31/12/1999") // gives a Date with 31 December 1999.

Annotation processor arguments

The currency code XXX must be selected as it is used by various java.text classes as a source of defaults.

Missing functionality

For the moment the following classes will not be supported:

  • Annotation

  • AttributedCharacterIterator.Attribute

  • AttributedString

  • Bidi

  • BreakIterator

  • ChoiceFormat

  • CollationElementIterator

  • CollationKey

  • Collator

  • MessageFormat

  • MessageFormat.Field

  • RuleBasedCollator

  • Serialization is not supported, and all support classes and forms including magic methods such as writeReplace are removed.

Transpiling

The j2cl-maven-plugin will shade the source during the transpile phase, so walkingkooka.j2cl.java.text is available to the runtime as java.text.

About

A j2cl compatible subset of the many classes belonging to the java.text package.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages