Skip to content
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

Provide upperBin and lowerBin signatures that accept Durations #5148

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 186 additions & 22 deletions engine/time/src/main/java/io/deephaven/time/DateTimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3152,8 +3152,8 @@ public static ZonedDateTime atMidnight(@Nullable final ZonedDateTime dateTime) {

/**
* Returns an {@link Instant} value, which is at the starting (lower) end of a time range defined by the interval
* nanoseconds. For example, a 5*MINUTE intervalNanos value would return the instant value for the start of the
* five-minute window that contains the input instant.
* nanoseconds. For example, a five-minute {@code intervalNanos} value would return the instant value for the start
* of the five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
Expand All @@ -3170,10 +3170,30 @@ public static Instant lowerBin(@Nullable final Instant instant, long intervalNan
return epochNanosToInstant(Numeric.lowerBin(epochNanos(instant), intervalNanos));
}

/**
* Returns an {@link Instant} value, which is at the starting (lower) end of a time range defined by the interval
* nanoseconds. For example, a five-minute {@code interval} value would return the instant value for the start of
* the five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param interval size of the window
* @return {@code null} if either input is {@code null}; otherwise, an {@link Instant} representing the start of the
* window
*/
@ScriptApi
@Nullable
public static Instant lowerBin(@Nullable final Instant instant, Duration interval) {
if (instant == null || interval == null) {
return null;
}

return lowerBin(instant, interval.toNanos());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the starting (lower) end of a time range defined by the
* interval nanoseconds. For example, a 5*MINUTE intervalNanos value would return the zoned date time value for the
* start of the five-minute window that contains the input zoned date time.
* interval nanoseconds. For example, a five-minute {@code intervalNanos} value would return the zoned date time
* value for the start of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
Expand All @@ -3190,16 +3210,36 @@ public static ZonedDateTime lowerBin(@Nullable final ZonedDateTime dateTime, lon
return epochNanosToZonedDateTime(Numeric.lowerBin(epochNanos(dateTime), intervalNanos), dateTime.getZone());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the starting (lower) end of a time range defined by the
* interval nanoseconds. For example, a five-minute {@code interval} value would return the zoned date time value
* for the start of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param interval size of the window
* @return {@code null} if either input is {@code null}; otherwise, a {@link ZonedDateTime} representing the start
* of the window
*/
@ScriptApi
@Nullable
public static ZonedDateTime lowerBin(@Nullable final ZonedDateTime dateTime, Duration interval) {
if (dateTime == null || interval == null) {
return null;
}

return lowerBin(dateTime, interval.toNanos());
}

/**
* Returns an {@link Instant} value, which is at the starting (lower) end of a time range defined by the interval
* nanoseconds. For example, a 5*MINUTE intervalNanos value would return the instant value for the start of the
* five-minute window that contains the input instant.
* nanoseconds. For example, a five-minute {@code intervalNanos} value would return the instant value for the start
* of the five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
* @param offset The window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by
* one minute.
* @return {@code null} if either input is {@code null}; otherwise, an {@link Instant} representing the start of the
* @return {@code null} if any input is {@code null}; otherwise, an {@link Instant} representing the start of the
* window
*/
@ScriptApi
Expand All @@ -3212,17 +3252,38 @@ public static Instant lowerBin(@Nullable final Instant instant, long intervalNan
return epochNanosToInstant(Numeric.lowerBin(epochNanos(instant) - offset, intervalNanos) + offset);
}

/**
* Returns an {@link Instant} value, which is at the starting (lower) end of a time range defined by the interval
* nanoseconds. For example, a five-minute {@code interval} value would return the instant value for the start of
* the five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param interval size of the window
* @param offset The window start offset. For example, a value of 'PT1m' would offset all windows by one minute.
* @return {@code null} if any input is {@code null}; otherwise, an {@link Instant} representing the start of the
* window
*/
@ScriptApi
@Nullable
public static Instant lowerBin(@Nullable final Instant instant, Duration interval, Duration offset) {
if (instant == null || interval == null || offset == null) {
return null;
}

return lowerBin(instant, interval.toNanos(), offset.toNanos());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the starting (lower) end of a time range defined by the
* interval nanoseconds. For example, a 5*MINUTE intervalNanos value would return the zoned date time value for the
* start of the five-minute window that contains the input zoned date time.
* interval nanoseconds. For example, a five-minute {@code intervalNanos} value would return the zoned date time
* value for the start of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
* @param offset The window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by
* one minute.
* @return {@code null} if either input is {@code null}; otherwise, a {@link ZonedDateTime} representing the start
* of the window
* @return {@code null} if any input is {@code null}; otherwise, a {@link ZonedDateTime} representing the start of
* the window
*/
@ScriptApi
@Nullable
Expand All @@ -3235,10 +3296,31 @@ public static ZonedDateTime lowerBin(@Nullable final ZonedDateTime dateTime, lon
dateTime.getZone());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the starting (lower) end of a time range defined by the
* interval nanoseconds. For example, a five-minute {@code interval} intervalNanos value would return the zoned date
* time value for the start of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param interval size of the window
* @param offset The window start offset. For example, a value of MINUTE would offset all windows by one minute.
* @return {@code null} if any input is {@code null}; otherwise, a {@link ZonedDateTime} representing the start of
* the window
*/
@ScriptApi
@Nullable
public static ZonedDateTime lowerBin(@Nullable final ZonedDateTime dateTime, Duration interval, Duration offset) {
if (dateTime == null || interval == null || offset == null) {
return null;
}

return lowerBin(dateTime, interval.toNanos(), offset.toNanos());
}

/**
* Returns an {@link Instant} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a 5*MINUTE intervalNanos value would return the instant value for the end of the
* five-minute window that contains the input instant.
* nanoseconds. For example, a five-minute {@code intervalNanos} value would return the instant value for the end of
* the five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
Expand All @@ -3255,10 +3337,30 @@ public static Instant upperBin(@Nullable final Instant instant, long intervalNan
return epochNanosToInstant(Numeric.upperBin(epochNanos(instant), intervalNanos));
}

/**
* Returns an {@link Instant} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a five-minute {@code interval} value would return the instant value for the end of the
* five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param interval size of the window
* @return {@code null} if either input is {@code null}; otherwise, an {@link Instant} representing the end of the
* window
*/
@ScriptApi
@Nullable
public static Instant upperBin(@Nullable final Instant instant, Duration interval) {
if (instant == null || interval == null) {
return null;
}

return upperBin(instant, interval.toNanos());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a 5*MINUTE intervalNanos value would return the zoned date time value for the end of
* the five-minute window that contains the input zoned date time.
* nanoseconds. For example, a five-minute {@code intervalNanos} value would return the zoned date time value for
* the end of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
Expand All @@ -3275,16 +3377,36 @@ public static ZonedDateTime upperBin(@Nullable final ZonedDateTime dateTime, lon
return epochNanosToZonedDateTime(Numeric.upperBin(epochNanos(dateTime), intervalNanos), dateTime.getZone());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a five-minute {@code interval} value would return the zoned date time value for the end
* of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param interval size of the window
* @return {@code null} if either input is {@code null}; otherwise, a {@link ZonedDateTime} representing the end of
* the window
*/
@ScriptApi
@Nullable
public static ZonedDateTime upperBin(@Nullable final ZonedDateTime dateTime, Duration interval) {
if (dateTime == null || interval == null) {
return null;
}

return upperBin(dateTime, interval.toNanos());
}

/**
* Returns an {@link Instant} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a 5*MINUTE intervalNanos value would return the instant value for the end of the
* five-minute window that contains the input instant.
* nanoseconds. For example, a five-minute {@code intervalNanos} value would return the instant value for the end of
* the five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
* @param offset The window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by
* one minute.
* @return {@code null} if either input is {@code null}; otherwise, an {@link Instant} representing the end of the
* @return {@code null} if any input is {@code null}; otherwise, an {@link Instant} representing the end of the
* window
*/
@ScriptApi
Expand All @@ -3298,17 +3420,38 @@ public static Instant upperBin(@Nullable final Instant instant, long intervalNan
return epochNanosToInstant(Numeric.upperBin(epochNanos(instant) - offset, intervalNanos) + offset);
}

/**
* Returns an {@link Instant} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a five-minute {@code interval} value would return the instant value for the end of the
* five-minute window that contains the input instant.
*
* @param instant instant for which to evaluate the start of the containing window
* @param interval size of the window
* @param offset The window start offset. For example, a value of 'PT1m' would offset all windows by one minute.
* @return {@code null} if any input is {@code null}; otherwise, an {@link Instant} representing the end of the
* window
*/
@ScriptApi
@Nullable
public static Instant upperBin(@Nullable final Instant instant, Duration interval, Duration offset) {
if (instant == null || interval == null || offset == null) {
return null;
}

return upperBin(instant, interval.toNanos(), offset.toNanos());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a 5*MINUTE intervalNanos value would return the zoned date time value for the end of
* the five-minute window that contains the input zoned date time.
* nanoseconds. For example, a five-minute {@code intervalNanos} value would return the zoned date time value for
* the end of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param intervalNanos size of the window in nanoseconds
* @param offset The window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by
* one minute.
* @return {@code null} if either input is {@code null}; otherwise, a {@link ZonedDateTime} representing the end of
* the window
* @return {@code null} if any input is {@code null}; otherwise, a {@link ZonedDateTime} representing the end of the
* window
*/
@ScriptApi
@Nullable
Expand All @@ -3322,6 +3465,27 @@ public static ZonedDateTime upperBin(@Nullable final ZonedDateTime dateTime, lon
dateTime.getZone());
}

/**
* Returns a {@link ZonedDateTime} value, which is at the ending (upper) end of a time range defined by the interval
* nanoseconds. For example, a five-minute {@code interval} value would return the zoned date time value for the end
* of the five-minute window that contains the input zoned date time.
*
* @param dateTime zoned date time for which to evaluate the start of the containing window
* @param interval size of the window
* @param offset The window start offset. For example, a value of 'PT1m' would offset all windows by one minute.
* @return {@code null} if any input is {@code null}; otherwise, a {@link ZonedDateTime} representing the end of the
* window
*/
@ScriptApi
@Nullable
public static ZonedDateTime upperBin(@Nullable final ZonedDateTime dateTime, Duration interval, Duration offset) {
if (dateTime == null || interval == null || offset == null) {
return null;
}

return upperBin(dateTime, interval.toNanos(), offset.toNanos());
}

// endregion

// region Format
Expand Down
Loading
Loading