This project aims to provide an most of java.time
by taking a fork of threetenbp.
- Only
java.time
imports should be used, theorg.threeten.bp
source is shaded tojava.time
during the build and not available in transpiled code. - The public APIs for both
java.time
andorg.threetenbp
are almost identical in the vast majority of class names, methods and fields. - Many other java packages are required by
java.time
and are not currently emulated by the JRE provided by j2cl. - The missing JRE packages are provided and listed at additional java packages.
Changes have been kept to a minimum when porting org.threeten.bp
. It should be relatively straightforward to pull
updates from the original when necessary.
- Unnecessary code has been commented out as much as possible.
- Replacing
java.util.regex.Pattern
with a pure java equivalent - Eliminating some reflection to call a new JDK8
java.util.Locale
method. - Serialization support has been removed, but the deserializations remain and are used to recreate the tzdb data and rules.
- New previously un emulated APIs that are used internally are now emulated completely (
java.util.Calendar
).
Most features such as parsing and formatting all of the dates, times and related classes should work using the java.util.Locale
and java.util.TimeZone
selected for bundling.
java.time.chrono.Chronology
support forjava.util.ServiceLoader
has been removed rendering the manifest entries ignored.java.time.chrono.DayOfWeek#getDisplayName
has been removed. Ticket.java.time.chrono.Era#getDisplayName
has been removed. Ticket.java.time.chrono.HijrahDate
support for loading a deviation file given by a system property has been removed. Ticketjava.time.chrono.Month#getDisplayName
has been removed. Ticket.java.time.zone.ZoneId#getDisplay
has been removed. Ticket.- Serialization of any class is not supported.
- See j2cl-java-util-currency-annotation-processor for more info about selecting which currencies get bundled.
This is required by
java.text.DateFormat
which is used internally by org.threeten.bp. - See j2cl-java-util-locale-annotation-processor for more info about selecting which locales get bundled.
- See j2cl-java-util-TimeZone-annotation-processor for more info about selecting which locales get bundled.
- See j2cl-locale for more info about logging.
The currency code XXX
must be selected as it is used by various java.text
classes as a source of defaults.
Builds were repeated on JunitTest
with only the selection of Locale and Timezone changed. Building has been done with compilationLevel=ADVANCED
so that
dead code is pruned and everything is obsfucated and minified.
Each sample includes the selected locales and timezone along with some logging that reports the actual size of data for
a JRE component such as java.text.DateFormatSymbols
and so on. The selected logging text is taken from the log generated
during the build by j2cl-maven-plugin.
TimeZones: 23 All Australian.
Locale: 2
LocaleProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.locale.generated.LocaleProvider.java, 1 Locale(s) selected by "EN-NZ", data: 15 char(s), utf-8: 15 byte(s), gzipped 33 byte(s)
DateFormatSymbolsProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DateFormatSymbolsProvider.java, 1 Locale(s) selected by "EN-NZ", data: 256 char(s), utf-8: 256 byte(s), gzipped 177 byte(s)
DateFormatProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DateFormatProvider.java, 1 Locale(s) selected by "EN-NZ", data: 473 char(s), utf-8: 473 byte(s), gzipped 136 byte(s)
DecimalFormatProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DecimalFormatProvider.java, 1 Locale(s) selected by "EN-NZ", data: 263 char(s), utf-8: 264 byte(s), gzipped 120 byte(s)
DecimalFormatSymbolsProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DecimalFormatSymbolsProvider.java, 1 Locale(s) selected by "EN-NZ", data: 31 char(s), utf-8: 35 byte(s), gzipped 55 byte(s)
TimeZoneProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.timezone.generated.TimeZoneProvider.java, 1 Locale(s) selected by "EN-NZ", 23 TimeZone(s) selected by "Australia/*", data: 22650 char(s), utf-8: 22650 byte(s), gzipped 2017 byte(s)
CurrencyProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.currency.generated.CurrencyProvider.java, 1 Locale(s) selected by "EN-NZ", 1 Currency(s) selected by "XXX", data: 54 char(s), utf-8: 54 byte(s), gzipped 60 byte(s)
TimeZones: 23 All Australian.
Locale: 2
LocaleProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.locale.generated.LocaleProvider.java, 2 Locale(s) selected by "EN-NZ,EN-AU", data: 29 char(s), utf-8: 29 byte(s), gzipped 41 byte(s)
DateFormatSymbolsProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DateFormatSymbolsProvider.java, 2 Locale(s) selected by "EN-NZ,EN-AU", data: 529 char(s), utf-8: 529 byte(s), gzipped 229 byte(s)
DateFormatProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DateFormatProvider.java, 2 Locale(s) selected by "EN-NZ,EN-AU", data: 945 char(s), utf-8: 945 byte(s), gzipped 174 byte(s)
DecimalFormatProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DecimalFormatProvider.java, 2 Locale(s) selected by "EN-NZ,EN-AU", data: 269 char(s), utf-8: 270 byte(s), gzipped 124 byte(s)
DecimalFormatSymbolsProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DecimalFormatSymbolsProvider.java, 2 Locale(s) selected by "EN-NZ,EN-AU", data: 60 char(s), utf-8: 68 byte(s), gzipped 68 byte(s)
TimeZoneProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.timezone.generated.TimeZoneProvider.java, 2 Locale(s) selected by "EN-NZ,EN-AU", 23 TimeZone(s) selected by "Australia/*", data: 22926 char(s), utf-8: 22926 byte(s), gzipped 2032 byte(s)
CurrencyProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.currency.generated.CurrencyProvider.java, 2 Locale(s) selected by "EN-NZ,EN-AU", 1 Currency(s) selected by "XXX", data: 98 char(s), utf-8: 98 byte(s), gzipped 79 byte(s)
TimeZones: 23 All Australian.
Locales: "en-001,en-150,en-AG,en-AI,en-AS,en-AT,en-AU,en-BB,en-BE,en-BI,en-BM,en-BS,en-BW,en-BZ,en-CA,en-CC,en-CH,en-CK,en-CM,en-CX,en-CY,en-DE,en-DG,en-DK,en-DM,en-ER,en-FI,en-FJ,en-FK,en-FM,en-GB,en-GD,en-GG,en-GH,en-GI,en-GM,en-GU,en-GY,en-HK,en-IE,en-IL,en-IM,en-IN,en-IO,en-JE,en-JM,en-KE,en-KI,en-KN,en-KY,en-LC,en-LR,en-LS,en-MG,en-MH,en-MO,en-MP,en-MS,en-MT,en-MU,en-MW,en-MY,en-NA,en-NF,en-NG,en-NL,en-NR,en-NU,en-NZ,en-PG,en-PH,en-PK,en-PN,en-PR,en-PW,en-RW,en-SB,en-SC,en-SD,en-SE,en-SG,en-SH,en-SI,en-SL,en-SS,en-SX,en-SZ,en-TC,en-TK,en-TO,en-TT,en-TV,en-TZ,en-UG,en-UM,en-US,en-US-POSIX,en-VC,en-VG,en-VI,en-VU,en-WS,en-ZA,en-ZM,en-ZW"
en-001,en-150,en-AG,en-AI,en-AS,en-AT,en-AU,en-BB,en-BE,en-BI,en-BM,en-BS,en-BW,en-BZ,en-CA,en-CC,en-CH,en-CK,en-CM,en-CX,en-CY,en-DE,en-DG,en-DK,en-DM,en-ER,en-FI,en-FJ,en-FK,en-FM,en-GB,en-GD,en-GG,en-GH,en-GI,en-GM,en-GU,en-GY,en-HK,en-IE,en-IL,en-IM,en-IN,en-IO,en-JE,en-JM,en-KE,en-KI,en-KN,en-KY,en-LC,en-LR,en-LS,en-MG,en-MH,en-MO,en-MP,en-MS,en-MT,en-MU,en-MW,en-MY,en-NA,en-NF,en-NG,en-NL,en-NR,en-NU,en-NZ,en-PG,en-PH,en-PK,en-PN,en-PR,en-PW,en-RW,en-SB,en-SC,en-SD,en-SE,en-SG,en-SH,en-SI,en-SL,en-SS,en-SX,en-SZ,en-TC,en-TK,en-TO,en-TT,en-TV,en-TZ,en-UG,en-UM,en-US,en-US-POSIX,en-VC,en-VG,en-VI,en-VU,en-WS,en-ZA,en-ZM,en-ZW
LocaleProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.locale.generated.LocaleProvider.java, 105 Locale(s) selected by "EN-*", data: 1490 char(s), utf-8: 1490 byte(s), gzipped 512 byte(s)
DateFormatSymbolsProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DateFormatSymbolsProvider.java, 105 Locale(s) selected by "EN-*", data: 1930 char(s), utf-8: 1930 byte(s), gzipped 495 byte(s)
DateFormatProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DateFormatProvider.java, 105 Locale(s) selected by "EN-*", data: 9918 char(s), utf-8: 9918 byte(s), gzipped 1108 byte(s)
DecimalFormatProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DecimalFormatProvider.java, 105 Locale(s) selected by "EN-*", data: 12548 char(s), utf-8: 12684 byte(s), gzipped 916 byte(s)
DecimalFormatSymbolsProviderAnnotationProcessor generated walkingkooka.j2cl.java.text.generated.DecimalFormatSymbolsProvider.java, 105 Locale(s) selected by "EN-*", data: 2211 char(s), utf-8: 2483 byte(s), gzipped 642 byte(s)
TimeZoneProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.timezone.generated.TimeZoneProvider.java, 105 Locale(s) selected by "EN-*", 23 TimeZone(s) selected by "Australia/*", data: 29596 char(s), utf-8: 29596 byte(s), gzipped 2276 byte(s)
CurrencyProviderAnnotationProcessor generated walkingkooka.j2cl.java.util.currency.generated.CurrencyProvider.java, 105 Locale(s) selected by "EN-*", 1 Currency(s) selected by "XXX", data: 2602 char(s), utf-8: 2620 byte(s), gzipped 1045 byte(s)
Cost of the same junit test with an empty test is about 50k.
Examining the total size of the single javascript file and the size of the embedded data most of the cost is for code and not data.
The java.time
uses many other java packages, both as utilities and as the source for locale sensitive text and symbols,
such as week days and more. The test using all EN locales is not considerably bigger and thats because many EN locales actually
share exactly the same data, with EN-AU and EN-NZ everything from week names, number symbols and more, the only real difference
are symbols relating to currency.
There are many other opportunites to share data and reduce code bloat which are not mentioned here and some have issues already created in their respective projects, such as only bundling current or current + future timezone data and more.