-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing ISO8601 DateTime with time zones formatted as "+0000" #139
Comments
In JDK 8, which this library targets to on JVM, |
@nathanscb, could you please provide a complete snippet where |
Hi. This line of code documentation states that |
@merlin-zaraza , but the link you provided is not to our repository but to something else. In our repository, there's no such line: https://github.com/Kotlin/kotlinx-datetime/blob/master/core/common/src/Instant.kt#L138 |
Oh. My bad. You are right. Seems like this fork contains such format. Can you add this here? |
@merlin-zaraza We expect a string in the extended ISO format of complete representation for calendar date and time of day (ISO 8601-1:2019, clause 5.4.2.1) as an input of the |
@ilya-g That's understandable and it's ok. The question is how to parse |
@merlin-zaraza Currently there's no way to parse such values because You can work around it currently by transforming an input value to the format |
I have same issue. |
@tateisu sure, but why do you expect it to work for |
After all, I stopped using kotlinx.datetime. It cannot support Android 7-. |
Having looked through the ISO, I see that |
@dkhalanskyjb In the basic format, date and time parts are also written without delimiters, e.g. |
Good point. So, what is requested here is actually some mix of basic and extended formats. |
In my case, the api I work with at my company returns date with this format : "2021-01-01T22:00:00.000+0000". |
Having to write fun Instant.Companion.parseWithBasicOffset(string: String): Instant {
var lastDigit = string.length
while (lastDigit > 0 && string[lastDigit - 1].isDigit()) { --lastDigit }
val digits = string.length - lastDigit // how many digits are there at the end of the string
if (digits <= 2)
return parse(string) // no issue in any case
var newString = string.substring(0, lastDigit + 2)
lastDigit += 2
while (lastDigit < string.length) {
newString += ":" + string.substring(lastDigit, lastDigit + 2)
lastDigit += 2
}
return parse(newString)
} As a workaround, define this function in common code. For (somewhat) valid instants, it adds Example:
|
Thank you @dkhalanskyjb for the snippet. |
Parsing a string as an Instant like
2021-08-22T03:32:10+0000
fails due tofixOffsetRepresentation
adding:00
to the end of the string.The underlying Java Time library is able to handle this fine.
The text was updated successfully, but these errors were encountered: