Skip to content

Commit

Permalink
Calendar API changes so that methods accepting strings return strings (
Browse files Browse the repository at this point in the history
…#5029)

When the calendar API accepts strings, return strings.
  • Loading branch information
chipkent authored Jan 12, 2024
1 parent 4e783a1 commit d11f342
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1214,14 +1214,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,
final boolean endInclusive) {
if (start == null || end == null) {
return null;
}

return businessDates(DateTimeUtils.parseLocalDate(start), DateTimeUtils.parseLocalDate(end), startInclusive,
endInclusive);
final LocalDate[] dates =
businessDates(DateTimeUtils.parseLocalDate(start), DateTimeUtils.parseLocalDate(end), startInclusive,
endInclusive);
return dates == null ? null : Arrays.stream(dates).map(DateTimeUtils::formatDate).toArray(String[]::new);
}

/**
Expand Down Expand Up @@ -1287,7 +1289,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) {
return businessDates(start, end, true, true);
}

Expand Down Expand Up @@ -1357,14 +1359,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,
final boolean endInclusive) {
if (start == null || end == null) {
return null;
}

return nonBusinessDates(DateTimeUtils.parseLocalDate(start), DateTimeUtils.parseLocalDate(end), startInclusive,
endInclusive);
final LocalDate[] dates =
nonBusinessDates(DateTimeUtils.parseLocalDate(start), DateTimeUtils.parseLocalDate(end), startInclusive,
endInclusive);
return dates == null ? null : Arrays.stream(dates).map(DateTimeUtils::formatDate).toArray(String[]::new);
}

/**
Expand Down Expand Up @@ -1430,7 +1434,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) {
return nonBusinessDates(start, end, true, true);
}

Expand Down Expand Up @@ -1748,12 +1752,13 @@ public LocalDate plusBusinessDays(final LocalDate date, final int days) {
* @throws InvalidDateException if the date is not in the valid range
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate plusBusinessDays(final String date, final int days) {
public String plusBusinessDays(final String date, final int days) {
if (date == null || days == NULL_INT) {
return null;
}

return plusBusinessDays(DateTimeUtils.parseLocalDate(date), days);
final LocalDate d = plusBusinessDays(DateTimeUtils.parseLocalDate(date), days);
return d == null ? null : d.toString();
}

/**
Expand Down Expand Up @@ -1840,7 +1845,7 @@ public LocalDate minusBusinessDays(final LocalDate date, final int days) {
* @throws InvalidDateException if the date is not in the valid range
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate minusBusinessDays(final String date, final int days) {
public String minusBusinessDays(final String date, final int days) {
if (date == null || days == NULL_INT) {
return null;
}
Expand Down Expand Up @@ -1939,12 +1944,13 @@ public LocalDate plusNonBusinessDays(final LocalDate date, final int days) {
* @throws InvalidDateException if the date is not in the valid range
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate plusNonBusinessDays(final String date, final int days) {
public String plusNonBusinessDays(final String date, final int days) {
if (date == null || days == NULL_INT) {
return null;
}

return this.plusNonBusinessDays(DateTimeUtils.parseLocalDate(date), days);
final LocalDate d = this.plusNonBusinessDays(DateTimeUtils.parseLocalDate(date), days);
return d == null ? null : d.toString();
}

/**
Expand Down Expand Up @@ -2034,7 +2040,7 @@ public LocalDate minusNonBusinessDays(final LocalDate date, final int days) {
* @throws InvalidDateException if the date is not in the valid range
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate minusNonBusinessDays(final String date, final int days) {
public String minusNonBusinessDays(final String date, final int days) {
if (date == null || days == NULL_INT) {
return null;
}
Expand Down
21 changes: 13 additions & 8 deletions engine/time/src/main/java/io/deephaven/time/calendar/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static io.deephaven.util.QueryConstants.NULL_INT;
Expand Down Expand Up @@ -258,12 +259,13 @@ public LocalDate plusDays(final LocalDate date, final int days) {
* {@link io.deephaven.util.QueryConstants#NULL_INT}.
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate plusDays(final String date, final int days) {
public String plusDays(final String date, final int days) {
if (date == null || days == NULL_INT) {
return null;
}

return plusDays(DateTimeUtils.parseLocalDate(date), days);
final LocalDate d = plusDays(DateTimeUtils.parseLocalDate(date), days);
return d == null ? null : d.toString();
}

/**
Expand Down Expand Up @@ -339,12 +341,13 @@ public LocalDate minusDays(final LocalDate date, final int days) {
* {@link io.deephaven.util.QueryConstants#NULL_INT}.
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate minusDays(final String date, final int days) {
public String minusDays(final String date, final int days) {
if (date == null || days == NULL_INT) {
return null;
}

return minusDays(DateTimeUtils.parseLocalDate(date), days);
final LocalDate d = minusDays(DateTimeUtils.parseLocalDate(date), days);
return d == null ? null : d.toString();
}

/**
Expand Down Expand Up @@ -457,14 +460,16 @@ public LocalDate[] calendarDates(final LocalDate start, final LocalDate end, fin
* @return dates between {@code start} and {@code end}, or {@code null} if any input is {@code null}.
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate[] calendarDates(final String start, final String end, final boolean startInclusive,
public String[] calendarDates(final String start, final String end, final boolean startInclusive,
final boolean endInclusive) {
if (start == null || end == null) {
return null;
}

return calendarDates(DateTimeUtils.parseLocalDate(start), DateTimeUtils.parseLocalDate(end), startInclusive,
endInclusive);
final LocalDate[] dates =
calendarDates(DateTimeUtils.parseLocalDate(start), DateTimeUtils.parseLocalDate(end), startInclusive,
endInclusive);
return dates == null ? null : Arrays.stream(dates).map(DateTimeUtils::formatDate).toArray(String[]::new);
}

/**
Expand Down Expand Up @@ -528,7 +533,7 @@ public LocalDate[] calendarDates(final LocalDate start, final LocalDate end) {
* any input is {@code null}.
* @throws DateTimeUtils.DateTimeParseException if the string cannot be parsed
*/
public LocalDate[] calendarDates(final String start, final String end) {
public String[] calendarDates(final String start, final String end) {
return calendarDates(start, end, true, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class StaticCalendarMethods {
/** @see io.deephaven.time.calendar.BusinessCalendar#businessDates(java.lang.String,java.lang.String) */
public static java.time.LocalDate[] businessDates( java.lang.String start, java.lang.String end ) {return Calendars.calendar().businessDates( start, end );}
public static java.lang.String[] businessDates( java.lang.String start, java.lang.String end ) {return Calendars.calendar().businessDates( start, end );}

/** @see io.deephaven.time.calendar.BusinessCalendar#businessDates(java.time.Instant,java.time.Instant) */
public static java.time.LocalDate[] businessDates( java.time.Instant start, java.time.Instant end ) {return Calendars.calendar().businessDates( start, end );}
Expand All @@ -43,7 +43,7 @@ public class StaticCalendarMethods {
public static java.time.LocalDate[] businessDates( java.time.ZonedDateTime start, java.time.ZonedDateTime end ) {return Calendars.calendar().businessDates( start, end );}

/** @see io.deephaven.time.calendar.BusinessCalendar#businessDates(java.lang.String,java.lang.String,boolean,boolean) */
public static java.time.LocalDate[] businessDates( java.lang.String start, java.lang.String end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().businessDates( start, end, startInclusive, endInclusive );}
public static java.lang.String[] businessDates( java.lang.String start, java.lang.String end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().businessDates( start, end, startInclusive, endInclusive );}

/** @see io.deephaven.time.calendar.BusinessCalendar#businessDates(java.time.Instant,java.time.Instant,boolean,boolean) */
public static java.time.LocalDate[] businessDates( java.time.Instant start, java.time.Instant end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().businessDates( start, end, startInclusive, endInclusive );}
Expand All @@ -58,7 +58,7 @@ public class StaticCalendarMethods {
public static java.time.LocalDate calendarDate( ) {return Calendars.calendar().calendarDate( );}

/** @see io.deephaven.time.calendar.Calendar#calendarDates(java.lang.String,java.lang.String) */
public static java.time.LocalDate[] calendarDates( java.lang.String start, java.lang.String end ) {return Calendars.calendar().calendarDates( start, end );}
public static java.lang.String[] calendarDates( java.lang.String start, java.lang.String end ) {return Calendars.calendar().calendarDates( start, end );}

/** @see io.deephaven.time.calendar.Calendar#calendarDates(java.time.Instant,java.time.Instant) */
public static java.time.LocalDate[] calendarDates( java.time.Instant start, java.time.Instant end ) {return Calendars.calendar().calendarDates( start, end );}
Expand All @@ -70,7 +70,7 @@ public class StaticCalendarMethods {
public static java.time.LocalDate[] calendarDates( java.time.ZonedDateTime start, java.time.ZonedDateTime end ) {return Calendars.calendar().calendarDates( start, end );}

/** @see io.deephaven.time.calendar.Calendar#calendarDates(java.lang.String,java.lang.String,boolean,boolean) */
public static java.time.LocalDate[] calendarDates( java.lang.String start, java.lang.String end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().calendarDates( start, end, startInclusive, endInclusive );}
public static java.lang.String[] calendarDates( java.lang.String start, java.lang.String end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().calendarDates( start, end, startInclusive, endInclusive );}

/** @see io.deephaven.time.calendar.Calendar#calendarDates(java.time.Instant,java.time.Instant,boolean,boolean) */
public static java.time.LocalDate[] calendarDates( java.time.Instant start, java.time.Instant end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().calendarDates( start, end, startInclusive, endInclusive );}
Expand Down Expand Up @@ -271,7 +271,7 @@ public class StaticCalendarMethods {
public static boolean isLastBusinessDayOfYear( java.time.ZonedDateTime time ) {return Calendars.calendar().isLastBusinessDayOfYear( time );}

/** @see io.deephaven.time.calendar.BusinessCalendar#minusBusinessDays(java.lang.String,int) */
public static java.time.LocalDate minusBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().minusBusinessDays( date, days );}
public static java.lang.String minusBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().minusBusinessDays( date, days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#minusBusinessDays(java.time.Instant,int) */
public static java.time.Instant minusBusinessDays( java.time.Instant time, int days ) {return Calendars.calendar().minusBusinessDays( time, days );}
Expand All @@ -283,7 +283,7 @@ public class StaticCalendarMethods {
public static java.time.ZonedDateTime minusBusinessDays( java.time.ZonedDateTime time, int days ) {return Calendars.calendar().minusBusinessDays( time, days );}

/** @see io.deephaven.time.calendar.Calendar#minusDays(java.lang.String,int) */
public static java.time.LocalDate minusDays( java.lang.String date, int days ) {return Calendars.calendar().minusDays( date, days );}
public static java.lang.String minusDays( java.lang.String date, int days ) {return Calendars.calendar().minusDays( date, days );}

/** @see io.deephaven.time.calendar.Calendar#minusDays(java.time.Instant,int) */
public static java.time.Instant minusDays( java.time.Instant time, int days ) {return Calendars.calendar().minusDays( time, days );}
Expand All @@ -295,7 +295,7 @@ public class StaticCalendarMethods {
public static java.time.ZonedDateTime minusDays( java.time.ZonedDateTime time, int days ) {return Calendars.calendar().minusDays( time, days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#minusNonBusinessDays(java.lang.String,int) */
public static java.time.LocalDate minusNonBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().minusNonBusinessDays( date, days );}
public static java.lang.String minusNonBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().minusNonBusinessDays( date, days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#minusNonBusinessDays(java.time.Instant,int) */
public static java.time.Instant minusNonBusinessDays( java.time.Instant time, int days ) {return Calendars.calendar().minusNonBusinessDays( time, days );}
Expand All @@ -307,7 +307,7 @@ public class StaticCalendarMethods {
public static java.time.ZonedDateTime minusNonBusinessDays( java.time.ZonedDateTime time, int days ) {return Calendars.calendar().minusNonBusinessDays( time, days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#nonBusinessDates(java.lang.String,java.lang.String) */
public static java.time.LocalDate[] nonBusinessDates( java.lang.String start, java.lang.String end ) {return Calendars.calendar().nonBusinessDates( start, end );}
public static java.lang.String[] nonBusinessDates( java.lang.String start, java.lang.String end ) {return Calendars.calendar().nonBusinessDates( start, end );}

/** @see io.deephaven.time.calendar.BusinessCalendar#nonBusinessDates(java.time.Instant,java.time.Instant) */
public static java.time.LocalDate[] nonBusinessDates( java.time.Instant start, java.time.Instant end ) {return Calendars.calendar().nonBusinessDates( start, end );}
Expand All @@ -319,7 +319,7 @@ public class StaticCalendarMethods {
public static java.time.LocalDate[] nonBusinessDates( java.time.ZonedDateTime start, java.time.ZonedDateTime end ) {return Calendars.calendar().nonBusinessDates( start, end );}

/** @see io.deephaven.time.calendar.BusinessCalendar#nonBusinessDates(java.lang.String,java.lang.String,boolean,boolean) */
public static java.time.LocalDate[] nonBusinessDates( java.lang.String start, java.lang.String end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().nonBusinessDates( start, end, startInclusive, endInclusive );}
public static java.lang.String[] nonBusinessDates( java.lang.String start, java.lang.String end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().nonBusinessDates( start, end, startInclusive, endInclusive );}

/** @see io.deephaven.time.calendar.BusinessCalendar#nonBusinessDates(java.time.Instant,java.time.Instant,boolean,boolean) */
public static java.time.LocalDate[] nonBusinessDates( java.time.Instant start, java.time.Instant end, boolean startInclusive, boolean endInclusive ) {return Calendars.calendar().nonBusinessDates( start, end, startInclusive, endInclusive );}
Expand Down Expand Up @@ -412,7 +412,7 @@ public class StaticCalendarMethods {
public static java.time.LocalDate pastNonBusinessDate( int days ) {return Calendars.calendar().pastNonBusinessDate( days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#plusBusinessDays(java.lang.String,int) */
public static java.time.LocalDate plusBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().plusBusinessDays( date, days );}
public static java.lang.String plusBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().plusBusinessDays( date, days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#plusBusinessDays(java.time.Instant,int) */
public static java.time.Instant plusBusinessDays( java.time.Instant time, int days ) {return Calendars.calendar().plusBusinessDays( time, days );}
Expand All @@ -424,7 +424,7 @@ public class StaticCalendarMethods {
public static java.time.ZonedDateTime plusBusinessDays( java.time.ZonedDateTime time, int days ) {return Calendars.calendar().plusBusinessDays( time, days );}

/** @see io.deephaven.time.calendar.Calendar#plusDays(java.lang.String,int) */
public static java.time.LocalDate plusDays( java.lang.String date, int days ) {return Calendars.calendar().plusDays( date, days );}
public static java.lang.String plusDays( java.lang.String date, int days ) {return Calendars.calendar().plusDays( date, days );}

/** @see io.deephaven.time.calendar.Calendar#plusDays(java.time.Instant,int) */
public static java.time.Instant plusDays( java.time.Instant time, int days ) {return Calendars.calendar().plusDays( time, days );}
Expand All @@ -436,7 +436,7 @@ public class StaticCalendarMethods {
public static java.time.ZonedDateTime plusDays( java.time.ZonedDateTime time, int days ) {return Calendars.calendar().plusDays( time, days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#plusNonBusinessDays(java.lang.String,int) */
public static java.time.LocalDate plusNonBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().plusNonBusinessDays( date, days );}
public static java.lang.String plusNonBusinessDays( java.lang.String date, int days ) {return Calendars.calendar().plusNonBusinessDays( date, days );}

/** @see io.deephaven.time.calendar.BusinessCalendar#plusNonBusinessDays(java.time.Instant,int) */
public static java.time.Instant plusNonBusinessDays( java.time.Instant time, int days ) {return Calendars.calendar().plusNonBusinessDays( time, days );}
Expand Down
Loading

0 comments on commit d11f342

Please sign in to comment.