Comments (4)
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.
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:
Please provide a failing test case or executable sample that demonstrates the problem.
from threetenabp.
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.
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)
- Add Usage info HOT 1
- Update tzdb.dat to new version. HOT 3
- Duplicate ThreeTen Classes in AndroidTest HOT 2
- Calculation problem HOT 4
- IllegalStateException: Already initialized HOT 14
- minusDays() returns wrong date for specific use case HOT 2
- R8 issue with Ser HOT 14
- Contribution: Gson.toJson with @Expose annotations error HOT 1
- Will we still need this library after java.time will be desugared? HOT 6
- Do I actually want to switch to desugared native apis? HOT 7
- Wrong Format OffsetDateTime HOT 1
- Bug in DateTimeFormatter - Wrong year. HOT 1
- Help for specific pattern HOT 1
- Support Compose Preview HOT 2
- Wrong time zone offset HOT 1
- NoClassDefFoundError in android 4.4 even with multidex enabled HOT 2
- Returns the Value to 1926 HOT 3
- Please *do not* consider switching to core library desugaring HOT 2
- Fatal Exception: n30.g Unknown time-zone ID: America/Ciudad_Juarez HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from threetenabp.