-
Notifications
You must be signed in to change notification settings - Fork 81
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
Calendar API changes so that methods accepting strings return strings #5029
Conversation
@@ -1287,7 +1291,7 @@ public LocalDate[] businessDates(final LocalDate start, final LocalDate end) { | |||
* @throws InvalidDateException if the dates are not in the valid range | |||
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed | |||
*/ | |||
public LocalDate[] businessDates(final String start, final String end) { | |||
public String[] businessDates(final String start, final String end) { |
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.
Every other businessDate
overload returns a LocalDate[]
. I don't think the one that takes string inputs needs to be special.
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 assumed that String in implies String out. If someone is working in strings, do you expect that they would not want this result in strings as well?
@@ -1357,14 +1361,16 @@ public LocalDate[] nonBusinessDates(final LocalDate start, final LocalDate end, | |||
* @throws InvalidDateException if the dates are not in the valid range | |||
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed | |||
*/ | |||
public LocalDate[] nonBusinessDates(final String start, final String end, final boolean startInclusive, | |||
public String[] nonBusinessDates(final String start, final String end, final boolean startInclusive, |
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.
Same comment as the one on businessDates
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 assumed that String in implies String out. If someone is working in strings, do you expect that they would not want this result in strings as well?
@@ -1430,7 +1436,7 @@ public LocalDate[] nonBusinessDates(final LocalDate start, final LocalDate end) | |||
* @throws InvalidDateException if the dates are not in the valid range | |||
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed | |||
*/ | |||
public LocalDate[] nonBusinessDates(final String start, final String end) { | |||
public String[] nonBusinessDates(final String start, final String end) { |
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.
Same comment as the one I made on businessDates
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 assumed that String in implies String out. If someone is working in strings, do you expect that they would not want this result in strings as well?
@@ -165,6 +165,7 @@ private YearData getYearData(final int year) { | |||
|
|||
// region Getters | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think there needs to be one
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 agree; people can convert these to strings on their own, or stick with java.time types (as we'd generally recommend).
I don't strongly oppose a firstValidDateStr()
; I just wouldn't add it proactively. We can always add it later if people ask for it.
@@ -1214,14 +1216,16 @@ public LocalDate[] businessDates(final LocalDate start, final LocalDate end, fin | |||
* @throws InvalidDateException if the dates are not in the valid range | |||
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed | |||
*/ | |||
public LocalDate[] businessDates(final String start, final String end, final boolean startInclusive, | |||
public String[] businessDates(final String start, final String end, final boolean startInclusive, |
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.
Same comment as on the other overload.
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 assumed that String in implies String out. If someone is working in strings, do you expect that they would not want this result in strings as well?
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 think String in -> String out
, LocalDate in -> LocalDate out
is the most user-friendly
@@ -174,6 +175,7 @@ public LocalDate firstValidDate() { | |||
return firstValidDate; | |||
} | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think so.
@@ -2091,6 +2099,7 @@ public ZonedDateTime minusNonBusinessDays(final ZonedDateTime time, final int da | |||
return plusNonBusinessDays(time, -days); | |||
} | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think so.
@@ -2108,6 +2117,7 @@ public LocalDate futureBusinessDate(final int days) { | |||
return plusBusinessDays(calendarDate(), days); | |||
} | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think so.
@@ -2125,6 +2135,7 @@ public LocalDate pastBusinessDate(final int days) { | |||
return minusBusinessDays(calendarDate(), days); | |||
} | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think so.
@@ -89,6 +90,7 @@ public String toString() { | |||
|
|||
// region Now | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think so
@@ -117,6 +119,7 @@ public DayOfWeek dayOfWeek(final LocalDate date) { | |||
return DateTimeUtils.dayOfWeek(date); | |||
} | |||
|
|||
// TODO: should this return a String? |
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.
All of the overloads for this method return a DayOfWeek
. The one that takes string as input doesn't have to be special. It should conform to the behavior the overloads have.
@@ -392,6 +397,7 @@ public ZonedDateTime minusDays(final ZonedDateTime time, final int days) { | |||
return plusDays(time, -days); | |||
} | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think so.
@@ -403,6 +409,7 @@ public LocalDate futureDate(final int days) { | |||
return plusDays(calendarDate(), days); | |||
} | |||
|
|||
// TODO: should there be a string equivalent? |
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 don't think so.
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.
There were four methods in BusinessCalendar
that I noticed behavior differed between overloads:
minusBusinessDays
minusNonBusinessDays
plusBusinessDays
plusNonBusinessDays
Those four have 4 overloads each - in all but 1 overload, the method returns the same type that's passed in. The only one where that's not the case is when a String is passed in. In that case, a LocalDate
is returned. Those are the only 4 methods I think should change so that the behavior is consistent across all overloads.
After glancing at Calendar
as well, there are two methods where I think this should change in the same way:
minusDays
plusDays
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.
Looks good to me — String in -> String out
, LocalDate in -> LocalDate out
, and always LocalDate
if there are no date arguments.
It does make me wonder if we should make parseLocalDate()
accept nulls — it would be nice to be able to do parseLocalDate(someFunctionResultOrJoinedOnColumnThatMayBeNull)
whenever you have a string date, without having to handle nulls manually. We have parseLocalDateQuiet()
(and similar for other parse methods), but those also swallow format exceptions.
@@ -165,6 +165,7 @@ private YearData getYearData(final int year) { | |||
|
|||
// region Getters | |||
|
|||
// TODO: should there be a string equivalent? |
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 agree; people can convert these to strings on their own, or stick with java.time types (as we'd generally recommend).
I don't strongly oppose a firstValidDateStr()
; I just wouldn't add it proactively. We can always add it later if people ask for it.
@@ -1214,14 +1216,16 @@ public LocalDate[] businessDates(final LocalDate start, final LocalDate end, fin | |||
* @throws InvalidDateException if the dates are not in the valid range | |||
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed | |||
*/ | |||
public LocalDate[] businessDates(final String start, final String end, final boolean startInclusive, | |||
public String[] businessDates(final String start, final String end, final boolean startInclusive, |
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 think String in -> String out
, LocalDate in -> LocalDate out
is the most user-friendly
Labels indicate documentation is required. Issues for documentation have been opened: Community: https://github.com/deephaven/deephaven.io/issues/3616 |
Suggested changes to the Calendar API so that methods that accept string inputs return strings.