Converts a list of human readable rules to a functional that maps any datetime stamp to a time bin.

rules2timebins(rules)

Arguments

rules

A list of lists of rules, each sublist must contain 4 variables, start and end as the start and end times (24h) format of the time bin, days as a vector of days to apply this time bin to (1 for Sunday, ..., 7 for Saturday), and tag the name of the time bin.

Value

a function that maps any datetime stamp to the associated time bins.

Details

Unassigned time is by default tagged with Other

Examples

# NOT RUN {
rules = list(
    list(start='6:30',  end= '9:00',  days = 1:5, tag='MR'),
    list(start='15:00', end= '18:00', days = 2:5, tag='ER')
)
time_bins <- rules2timebins(rules)
time_bins(Sys.time())
# }