Split a datetime object in a date component (get_date()
) and
time of day (get_hour()
) component, centred around a specific
hour of the day. They are used by stat_hourglass()
.
Arguments
- x
A datetime object (e.g.,
as.POSIXct()
) to extract day of time from- hour_center
The hour at which the time of day is centred. Default is 0, meaning midnight. -12 centres around noon of the preceding day, +12 centres around noon of the next day.
- ...
Ignored
Value
Returns a period
(lubridate::as.period()
) in case of get_hour()
.
Returns a datetime object in case of get_date()
Examples
my_datetime <- as.POSIXct("2020-02-02 02:20:02 UTC", tz = "UTC")
get_hour(my_datetime)
#> [1] "2H 20M 2S"
get_hour(my_datetime, -12)
#> [1] "-21H -39M -58S"
get_date(my_datetime)
#> [1] "2020-02-02 UTC"
get_date(my_datetime, -12)
#> [1] "2020-02-03 UTC"
## This will return the original `my_date`
get_date(my_datetime) + get_hour(my_datetime)
#> [1] "2020-02-02 02:20:02 UTC"
## This will too
get_date(my_datetime, -12) + get_hour(my_datetime, -12)
#> [1] "2020-02-02 02:20:02 UTC"