Skip to contents

This function calculates the overlap in time, in specified units, between two time periods defined by start and end times. It is specifically designed for handling time overlaps related to day and night hours.

Usage

calculate_daynight_times(
  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 <- calculate_daynight_times(
  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'
)
} # }