Giter VIP home page Giter VIP logo

j2cl-java-text's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.