Extends or contracts the time range of an mts_monitor object by adding/removing time steps at the start and end and filling any new time steps with missing values. The resulting time axis is guaranteed to be a regular, hourly axis with no gaps using the same timezone as the incoming mts_monitor object. This is useful when you want to place separate mts_monitor objects on the same time axis for plotting.

If either startdate or enddate is missing, the start or end of the timeseries in monitor will be used.

monitor_setTimeAxis(
  monitor = NULL,
  startdate = NULL,
  enddate = NULL,
  timezone = NULL
)

Arguments

monitor

mts_monitor object.

startdate

Desired start date (ISO 8601).

enddate

Desired end date (ISO 8601).

timezone

Olson timezone used to interpret startdate and enddate.

Value

The incoming mts_monitor time series object defined on a new time axis. (A list with meta and data dataframes.)

Note

If startdate or enddate is a POSIXct value, then timezone will be set to the timezone associated with startdate or enddate. In this common case, you don't need to specify timezone explicitly.

If neither startdate nor enddate is a POSIXct value AND no timezone is supplied, the timezone will be inferred from the most common timezone found in monitor.

Examples

library(AirMonitor)

# Default range
Carmel_Valley %>%
  monitor_timeRange()
#> [1] "2016-07-22 07:00:00 UTC" "2016-08-15 06:00:00 UTC"

# One-sided extend with user specified timezone
Carmel_Valley %>%
  monitor_setTimeAxis(enddate = 20160820, timezone = "UTC") %>%
  monitor_timeRange()
#> [1] "2016-07-22 07:00:00 UTC" "2016-08-20 00:00:00 UTC"

# Two-sided extend with user specified timezone
Carmel_Valley %>%
  monitor_setTimeAxis(20190720, 20190820, timezone = "UTC") %>%
  monitor_timeRange()
#> [1] "2019-07-20 UTC" "2019-08-20 UTC"

# Two-sided extend without timezone (uses monitor$meta$timezone)
Carmel_Valley %>%
  monitor_setTimeAxis(20190720, 20190820) %>%
  monitor_timeRange()
#> [1] "2019-07-20 07:00:00 UTC" "2019-08-20 07:00:00 UTC"