Convert time-slices to date-time, extract year, month, day of the year, or hour

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

tsl2year(tsl, return.null = T)

tsl2yday(tsl, return.null = T)

tsl2hour(tsl, return.null = T)

tsl2month(tsl, return.null = T)

Arguments

tsl

character vector with time-slices

format

character, format of the slices

tmz

time-zone

year

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

mday

day of month, for time slices without the information

return.null

logical, valid for the cased then all values are NA, then NULL will be returned if return.null = TRUE,

Value

Vector in Date-Time format

Functions

  • tsl2year: Extract year from time-slices

  • tsl2yday: Extract the day of the year from time-slices

  • tsl2hour: Extract hour from time-slices

  • tsl2month: Extract month from time-slices

Examples

tsl <- c("y2007_d365_h15", NA, "d151_h22", "d001", "m10_h12") tsl2dtm(tsl[1])
#> [1] "2007-12-31 15:00:00 UTC"
tsl2dtm(tsl[1:2])
#> Warning: 1 failed to parse.
#> [1] "2007-12-31 15:00:00 UTC" NA
tsl2dtm(tsl[2])
#> NULL
tsl2dtm(tsl[3])
#> NULL
tsl2dtm(tsl[4])
#> NULL
tsl2dtm(tsl[3], year = 2010)
#> [1] "2010-05-31 22:00:00 UTC"
tsl2dtm(tsl[4], year = 1900)
#> [1] "1900-01-01 UTC"
tsl2dtm(tsl[3:4], year = 1900)
#> NULL
tsl2year(tsl)
#> [1] 2007 NA NA NA NA
tsl
#> [1] "y2007_d365_h15" NA "d151_h22" "d001" #> [5] "m10_h12"
tsl2yday(tsl)
#> [1] 365 NA 151 1 NA
tsl
#> [1] "y2007_d365_h15" NA "d151_h22" "d001" #> [5] "m10_h12"
tsl2hour(tsl)
#> [1] 15 NA 22 NA 12
tsl
#> [1] "y2007_d365_h15" NA "d151_h22" "d001" #> [5] "m10_h12"
tsl2month(tsl)
#> [1] NA NA NA NA 10