-
Notifications
You must be signed in to change notification settings - Fork 80
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
fix!: Fix a TimeRange off-by-one bug in nanosecond calculation #5648
Changes from all commits
938b00a
bfddbdf
ccc5b4f
c0861ac
ada7dd7
c6e4fc8
e603d48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,12 @@ | |
* <description>New York Stock Exchange Calendar</description> | ||
* <timeZone>America/New_York</timeZone> | ||
* <default> | ||
* <businessTime><open>09:30</open><close>16:00</close></businessTime> | ||
* <businessTime> | ||
* <open>09:30</open> | ||
* <close>16:00</close> | ||
* <!-- Optional include the close nanosecond in the business time range. --> | ||
* <includeClose>true</includeClose> | ||
* </businessTime> | ||
* <weekend>Saturday</weekend> | ||
* <weekend>Sunday</weekend> | ||
* </default> | ||
|
@@ -51,6 +56,8 @@ | |
* <businessTime> | ||
* <open>09:30</open> | ||
* <close>13:00</close> | ||
* <!-- Optional include the close nanosecond in the business time range. --> | ||
* <includeClose>true</includeClose> | ||
* </businessTime> | ||
* </holiday> | ||
* </calendar> | ||
|
@@ -254,6 +261,7 @@ private static TimeRange<LocalTime>[] parseBusinessRanges(final List<Element> bu | |
for (int i = 0; i < businessRanges.size(); i++) { | ||
final String openTxt = getText(getRequiredChild(businessRanges.get(i), "open")); | ||
final String closeTxt = getText(getRequiredChild(businessRanges.get(i), "close")); | ||
final String includeCloseTxt = getText(businessRanges.get(i).getChild("includeClose")); | ||
|
||
if (closeTxt.startsWith("24:00")) { | ||
throw new RuntimeException("Close time (" + closeTxt | ||
|
@@ -262,7 +270,8 @@ private static TimeRange<LocalTime>[] parseBusinessRanges(final List<Element> bu | |
|
||
final LocalTime open = DateTimeUtils.parseLocalTime(openTxt); | ||
final LocalTime close = DateTimeUtils.parseLocalTime(closeTxt); | ||
rst[i] = new TimeRange<>(open, close, true); | ||
final boolean inclusiveEnd = Boolean.parseBoolean(includeCloseTxt); // defaults to false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Also, does this code path get hit when parsing a "legacy" calendar file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've asked DHE to take a look at how this effects them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question on the legacy path. These are the key parts for the legacy parsing of
The "legacy" and "new" I'm going to commit the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description has been updated to reflect the breaking change. |
||
rst[i] = new TimeRange<>(open, close, inclusiveEnd); | ||
} | ||
|
||
return rst; | ||
|
@@ -282,7 +291,7 @@ private static TimeRange<LocalTime>[] parseBusinessRangesLegacy(final List<Eleme | |
final String closeTxt = openClose[1]; | ||
final LocalTime open = DateTimeUtils.parseLocalTime(openTxt); | ||
final LocalTime close = DateTimeUtils.parseLocalTime(closeTxt); | ||
rst[i] = new TimeRange<>(open, close, true); | ||
rst[i] = new TimeRange<>(open, close, false); | ||
} else { | ||
throw new IllegalArgumentException("Can not parse business periods; open/close = " + br.getText()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't this set to
true
so that "23:59:59.999999999" would include the last nanosecond in the day?Right now, it looks like we can't represent a full day?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to recall some discussion involving DHE? Maybe Japan business day, or some other international concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that there may have been a UTC discussion. I'll look at that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix in there allows UTC to be supported correctly with full 24 hour days. It also gives users control over how to count the close times.