# NOT RUN {
# Basics:
sample_time()
sample_time(size = 10)
# Specific ranges:
sort(sample_time(from = (Sys.time() - 60), size = 10)) # within last minute
sort(sample_time(from = (Sys.time() - 1 * 60 * 60), size = 10)) # within last hour
sort(sample_time(from = Sys.time(), to = (Sys.time() + 1 * 60 * 60),
size = 10, replace = FALSE)) # within next hour
sort(sample_time(from = "2020-12-31 00:00:00 CET", to = "2020-12-31 00:00:01 CET",
size = 10, replace = TRUE)) # within 1 sec range
# Local time (POSIXlt) objects (as list):
(lt_sample <- sample_time(as_POSIXct = FALSE))
unlist(lt_sample)
# Time zones:
sample_time(size = 3, tz = "UTC")
sample_time(size = 3, tz = "US/Pacific")
# Note: Oddity with sample():
sort(sample_time(from = "2020-12-31 00:00:00 CET", to = "2020-12-31 00:00:00 CET",
size = 10, replace = TRUE)) # range of 0!
# see sample(9:9, size = 10, replace = TRUE)
# }
Run the code above in your browser using DataLab