Giter Site home page Giter Site logo

Comments (4)

JakeWharton avatar JakeWharton commented on August 24, 2024 1

This library is just a repackaging of the timezone database, it's not an Android-specific version of the library. The failures you're seeing would occur with usage of the normal ThreeTenBP library if you us it on Android. Working around this problem is going to be out-of-scope for this library. A fix would have to be pursued directly in ThreeTenBP.

from threetenabp.

JakeWharton avatar JakeWharton commented on August 24, 2024

I cannot reproduce. With the latest on master I can add the following to the sample app:

    String input = "Thu Dec 31 1998 23:22:50 GMT+0300 (CET)";
    String inputPattern = "E MMM dd yyyy HH:mm:ss 'GMT'Z (z)";

    LocalDateTime ldt = LocalDateTime.parse(input,
            DateTimeFormatter.ofPattern(inputPattern, Locale.US));
    tv.setText(ldt.toString());

and it displays the correct value:
Screen Shot 2019-11-19 at 5 32 58 PM

Please provide a failing test case or executable sample that demonstrates the problem.

from threetenabp.

t1r avatar t1r commented on August 24, 2024

Hello,
I think the problem is in parsing some of the Time Zone Abbreviations, like BST, MSK and so on.
Here are test cases:

  //org.threeten.bp.format.DateTimeParseException: Text 'Tue Nov 19 2019 00:00:00 GMT+0300 (MSK)' could not be parsed at index 35
  @Test public void test_parse_tzdbGmtZone_MSK() {
    AndroidThreeTen.init(context);
    String dateString = "Tue Nov 19 2019 00:00:00 GMT+0300 (MSK)";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E MMM dd yyyy HH:mm:ss 'GMT'Z (z)", Locale.US);
    LocalDateTime parsed = LocalDateTime.parse(dateString, formatter);
    assertEquals(parsed, LocalDateTime.of(2019, 11, 19, 0, 0, 0, 0));
  }

  //DateTimeParseException
  @Test public void test_parse_tzdbGmtZone_BST() {
    AndroidThreeTen.init(context);
    String dateString = "Tue Nov 19 2019 00:00:00 GMT+0100 (BST)";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E MMM dd yyyy HH:mm:ss 'GMT'Z (z)", Locale.US);
    LocalDateTime parsed = LocalDateTime.parse(dateString, formatter);
    assertEquals(parsed, LocalDateTime.of(2019, 11, 19, 0, 0, 0, 0));
  }

  //DateTimeParseException
  @Test public void test_parse_tzdbGmtZone_NCT() {
    AndroidThreeTen.init(context);
    String dateString = "Tue Nov 19 2019 00:00:00 GMT+0100 (NCT)";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E MMM dd yyyy HH:mm:ss 'GMT'Z (z)", Locale.US);
    LocalDateTime parsed = LocalDateTime.parse(dateString, formatter);
    assertEquals(parsed, LocalDateTime.of(2019, 11, 19, 0, 0, 0, 0));
  }

  //pass
  @Test public void test_parse_tzdbGmtZone_CET() {
    AndroidThreeTen.init(context);
    String dateString = "Tue Nov 19 2019 00:00:00 GMT+0100 (CET)";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E MMM dd yyyy HH:mm:ss 'GMT'Z (z)", Locale.US);
    LocalDateTime parsed = LocalDateTime.parse(dateString, formatter);
    assertEquals(parsed, LocalDateTime.of(2019, 11, 19, 0, 0, 0, 0));
  }

All of them are pass in the ThreeTen lib.
Thank You.

from threetenabp.

t1r avatar t1r commented on August 24, 2024

Hello @JakeWharton,
I researched this issue more deeper. And found out a reason.

Briefly speaking problem is in getDisplayName() method of java.util.TimeZone, which has a different implementation for Android and Java.

Comment, from source code of androids TimeZone implementation.
// BEGIN Android-changed: implement using android.icu.text.TimeZoneNames

More details:

We call getDisplayName() in the @Override public int parse(DateTimeParseContext context, CharSequence text, int position) of DateTimeFormatterBuilder class for build a zone ids map, that is used for parse time zone.

As a result, we have maps of size:
631 - in android
880 - in java

Android map doesn't contain "MSK", "BST", "NCT" and a lot of another time zone ids. What is the cause of DateTimeParseException.

How can we fix it - i don't know. It looks rather complicated, because we need to rewrite some of org.threeten.bp classes to change implementation of getDisplayName() specially for android.

Best wishes.

PS: Sorry for my bad english.

from threetenabp.

Related Issues (20)

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.