@@ -339,7 +339,7 @@ difftime_approx_ceiling_time_delta <- function(difftime, time_type) {
339339 )
340340}
341341
342- # ' Difference between two time value vectors in terms of number of time "steps"
342+ # ' Difference between two finite `time_value` vectors in terms of number of time "steps"
343343# '
344344# ' @param x a time_value (vector) of time type `time_type`
345345# ' @param y a time_value (vector) of time type `time_type`
@@ -352,15 +352,18 @@ time_minus_time_in_n_steps <- function(x, y, time_type) {
352352 time_delta_to_n_steps(x - y , time_type )
353353}
354354
355- # ' Advance/retreat time_values by specified number of time "steps"
355+ # ' Advance/retreat time_value(s) by bare-integerish number(s) of time "steps"
356356# '
357357# ' Here, a "step" is based on the `time_type`, not just the class of `x`.
358358# '
359359# ' @param x a time_value (vector) of time type `time_type`
360- # ' @param y integerish (vector)
360+ # ' @param y bare integerish (vector)
361361# ' @param time_type as in [`validate_slide_window_arg()`]
362362# ' @return a time_value (vector) of time type `time_type`
363363# '
364+ # ' @seealso [`time_plus_slide_window_arg`] if you're working with a `y` that is
365+ # ' a slide window arg, which is scalar but otherwise more general (class-wise,
366+ # ' Inf-wise) than an integerish vector.
364367# ' @keywords internal
365368time_plus_n_steps <- function (x , y , time_type ) {
366369 x + y * unit_time_delta(time_type , " fast" )
@@ -370,3 +373,32 @@ time_plus_n_steps <- function(x, y, time_type) {
370373time_minus_n_steps <- function (x , y , time_type ) {
371374 x - y * unit_time_delta(time_type , " fast" )
372375}
376+
377+ # ' Advance/retreat time_value(s) by specified amount (slide window arg)
378+ # '
379+ # ' @param x a time_value (vector) of time type `time_type`
380+ # ' @param y a (scalar) slide window arg; should pass [`validate_slide_window_arg()`]
381+ # ' @param time_type as in [`validate_slide_window_arg()`]
382+ # ' @param max_time_value when `y == Inf`, what should be the result of adding `y`?
383+ # ' @param min_time_value when `y == Inf`, what should be the result of subtracting `y`?
384+ # ' @return a time_value (vector) of time type `time_type`
385+ # '
386+ # ' @keywords internal
387+ # ' @seealso [`time_plus_n_steps`], if you're working with an integerish vector
388+ # ' number of time steps `y` (output from other `*n_steps` functions) instead.
389+ time_plus_slide_window_arg <- function (x , y , time_type , max_time_value ) {
390+ if (y == Inf ) {
391+ rep(max_time_value , vec_size(x ))
392+ } else {
393+ time_plus_n_steps(x , y , time_type )
394+ }
395+ }
396+
397+ # ' @rdname time_plus_slide_window_arg
398+ time_minus_slide_window_arg <- function (x , y , time_type , min_time_value ) {
399+ if (y == Inf ) {
400+ rep(min_time_value , vec_size(x ))
401+ } else {
402+ time_minus_n_steps(x , y , time_type )
403+ }
404+ }
0 commit comments