Skip to content

Implement parsing Instant with offset #107

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

Merged
merged 6 commits into from
Apr 16, 2021
Merged

Conversation

dkhalanskyjb
Copy link
Collaborator

Fixes #56

@dkhalanskyjb dkhalanskyjb requested a review from ilya-g April 7, 2021 12:53
@dkhalanskyjb dkhalanskyjb force-pushed the instant-parse-with-offset branch 3 times, most recently from a2539dc to c35a0b8 Compare April 7, 2021 13:19
Triple("2020-01-01T00:01:01.123456789-17:59:59", 1577901660L, 123456789),
Triple("2020-01-01T00:01:01.010203040+17:59:59", 1577772062L, 10203040),
Triple("2020-01-01T00:01:01.010203040+17:59", 1577772121L, 10203040),
// Triple("2020-01-01T00:01:01+00", 1577836861L, 0), // fails on JS, passes everywhere else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvement proposal: it's hard to correlate the expected epochSecond values with the source strings. Perhaps better use a pair of values as input: the value with an offset and the corresponding value with Z, and compare results of their parsing for equality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is the proper way to write this test. Fixed.

Comment on lines 128 to 130
* In addition to allowing the `Z` designator of the UTC+0 time zone to be passed as the time zone offset, which
* is required by the ISO-8601, this parser also accepts the other possible offsets, but does not provide a way
* to query the result for which offset was specified in the string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to rephrase this simpler, something like:

Supports the following ways of specifying the time zone offset:

  • Z designator for the UTC+0 time zone,
  • a custom time zone offset specified with +hh, or +hh:mm, or +hh:mm:ss, where negative offsets are prefixed with - instead of +.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I was clever by half there. However, now that we are so explicit about the accepted offsets, we can't just ignore that parsing +hh fails on JS, so I added a workaround for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that JDK8 also fails to parse +hh, as evidenced by the build failing. Added a workaround for that, too.

@dkhalanskyjb dkhalanskyjb force-pushed the instant-parse-with-offset branch from c35a0b8 to 3e11ed8 Compare April 14, 2021 08:36
@dkhalanskyjb dkhalanskyjb force-pushed the instant-parse-with-offset branch from afa1678 to 3cf0fa5 Compare April 14, 2021 20:43
@dkhalanskyjb dkhalanskyjb merged commit 1dd7d04 into master Apr 16, 2021
@dkhalanskyjb dkhalanskyjb deleted the instant-parse-with-offset branch April 16, 2021 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to parse instants with UTC offsets other than Z
2 participants