timeslices: Common formats of time-slices.

tsl_formatsR Documentation

Common formats of time-slices.

Description

This set of functions converts date-time objects to model's time-slices in a given format, and vice versa, maps time-slices to date-time, and extracts year, month, day of the year, hour.

Usage

tsl_formats

tsl_sets

dtm2tsl(dtm, format = "d365_h24", d366.as.na = grepl("d365", format))

tsl2dtm(
  tsl,
  format = tsl_guess_format(tsl),
  tmz = "UTC",
  year = NULL,
  mday = NULL
)

Arguments

dtm

vector of timepoints in Date format

format

character, format of the slices

d366.as.na

logical, if

tsl

character vector with time-slices

tmz

time-zone

year

year, used when time-slices don't store year

mday

day of month, for time slices without the information

Format

A character vector with formats:

d365

daily time-slices, 365 a year (leap year's 366th day is disregarded)

d365_h24

time slices with year-day numbers and hours, 8760 in total

...

etc.

An object of class list of length 1.

Value

Character vector with time-slices names

Vector in Date-Time format

Examples

dtm2tsl(lubridate::now())
dtm2tsl(lubridate::ymd("2020-12-31"))
dtm2tsl(lubridate::ymd("2020-12-31"), d366.as.na = FALSE)
dtm2tsl(lubridate::now(tzone = "UTC"), format = "d365")
dtm2tsl(lubridate::ymd("2020-12-31"), format = "d365")
dtm2tsl(lubridate::ymd("2020-12-31"), format = "d365", d366.as.na = FALSE)
dtm2tsl(lubridate::ymd("2020-12-31"), format = "d366")
tsl <- c("y2007_d365_h15", NA, "d151_h22", "d001", "m10_h12")
tsl2dtm(tsl[1])
tsl2dtm(tsl[1:2])
tsl2dtm(tsl[2])
tsl2dtm(tsl[3])
tsl2dtm(tsl[4])
tsl2dtm(tsl[3], year = 2010)
tsl2dtm(tsl[4], year = 1900)
tsl2dtm(tsl[3:4], year = 1900)

olugovoy/energyRt documentation built on Nov. 21, 2024, 2:24 a.m.