Adjust the date or time of a POSIXt
vector to a specific date or hour
Source: R/flat_posixt.R
flat_posixt_date.Rd
flat_posixt_*
functions adjust the date or time of a
POSIXt
vector to a specific date or hour, with
UTC
as the default timezone.
These functions are particularly useful for performing time arithmetic on
time objects that lack a date reference (e.g., hms
objects).
Arguments
- x
A
posixt
vector.- base
A
Date
(forflat_posixt_date()
orhms
(forflat_posixt_hour()
) value (Default:as.Date("1970-01-01")
(Unix Epoch) orhms::parse_hm("00:00")
).- force_tz
A
logical
flag indicating whether to force the timezone of the output totz
(Default:TRUE
).- tz
A
character
string indicating the timezone to use whenforce_tz
isTRUE
(Default:"UTC"
).
Value
A posixt
vector.
See also
Other utility functions:
change_date()
,
extract_seconds()
,
fix_hms()
,
get_last_week()
,
round_time()
Examples
as.POSIXct("2020-01-01 05:55:55", tz = "America/Sao_Paulo") |>
flat_posixt_date()
#> [1] "1970-01-01 05:55:55 UTC"
#> [1] "1970-01-01 05:55:55 UTC" # Expected
c(
as.POSIXct("2020-01-01 05:55:55", tz = "America/Sao_Paulo"),
as.POSIXct("2020-01-01 18:40:05", tz = "America/Sao_Paulo")
) |>
flat_posixt_date()
#> [1] "1970-01-01 05:55:55 UTC" "1970-01-01 18:40:05 UTC"
#> [1] "1970-01-01 05:55:55 UTC" "1970-01-01 18:40:05 UTC" # Expected
as.POSIXct("2020-01-01 05:55:55", tz = "America/Sao_Paulo") |>
flat_posixt_hour(base = hms::parse_hm("00:01"))
#> [1] "2020-01-01 00:01:00 UTC"
#> [1] "2020-01-01 00:01:00 UTC" # Expected
c(
as.POSIXct("2020-01-01 05:55:55", tz = "America/Sao_Paulo"),
as.POSIXct("2020-01-01 18:40:05", tz = "America/Sao_Paulo")
) |>
flat_posixt_hour(base = hms::parse_hm("00:01"))
#> [1] "2020-01-01 00:01:00 UTC" "2020-01-01 00:01:00 UTC"
#> [1] "2020-01-01 00:01:00 UTC" "2020-01-01 00:01:00 UTC" # Expected