R/read.R

Defines functions read_opening_hours

Documented in read_opening_hours

#' Read Opening Hours
#'
#' @param x A non-missing character vector of opening hours.
#'
#' @return A tibble of the Open and Close times by vector element.
#' @export
#'
#' @examples
#' read_opening_hours(character(0))
#' read_opening_hours("9:00-17:00")
read_opening_hours <- function(x) {
  chk_character(x)
  chk_not_any_na(x)

  if (!length(x)) {
    return(empty_read())
  }
  if (!vld_named(x)) {
    names(x) <- 1:length(x)
  }
  chk_unique(names(x))

  x <- tibble::tibble(Name = names(x), String = unname(x))
  x$OpeningHours <- lapply(x$String, parse)
  tibble::as_tibble(x)
}
poissonconsulting/openinghours documentation built on July 28, 2020, 4:36 p.m.