Skip to contents

This function calculates the overlap in time, in specified units, between two time periods defined by start and end times.

Usage

time_in_period(
  period1_start,
  period1_finish,
  period2_start,
  period2_finish,
  units = "hours"
)

Arguments

period1_start

A POSIXct object representing the start time of the first period.

period1_finish

A POSIXct object representing the finish time of the first period.

period2_start

A POSIXct object representing the start time of the second period.

period2_finish

A POSIXct object representing the finish time of the second period.

units

A string representing the units in which to output the time, defaults to 'hours'.

Value

A numeric representing the time overlap between two periods in specified units.

Examples

if (FALSE) { # \dontrun{
overlap_hours <- time_in_period(
  period1_start = as.POSIXct('2023-07-17 06:00:00'),
  period1_finish = as.POSIXct('2023-07-17 18:00:00'),
  period2_start = as.POSIXct('2023-07-17 12:00:00'),
  period2_finish = as.POSIXct('2023-07-17 20:00:00'),
  units = 'hours'
)
} # }