Title: | Manipulate Date, POSIXct and hms Vectors |
---|---|
Description: | Manipulates date ('Date'), date time ('POSIXct') and time ('hms') vectors. Date/times are considered discrete and are floored whenever encountered. Times are wrapped and time zones are maintained unless explicitly altered by the user. |
Authors: | Joe Thorley [aut] , Ayla Pearson [aut, cre] , Poisson Consulting [cph, fnd] |
Maintainer: | Ayla Pearson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.2.9001 |
Built: | 2024-11-18 03:53:28 UTC |
Source: | https://github.com/poissonconsulting/dttr2 |
Checks an object's time zone as returned by dtt_tz()
.
check_tz(x, tz = dtt_tz(x), x_name = substitute(x), error = TRUE)
check_tz(x, tz = dtt_tz(x), x_name = substitute(x), error = TRUE)
x |
The object to check. |
tz |
A string of the time zone to check that x's matches. |
x_name |
A string of the name of the object. |
error |
A flag indicating whether to throw an informative error or immediately generate an informative message if the check fails. |
An invisible copy of x (if it doesn't throw an error).
Other check:
chk_time()
check_tz(Sys.time(), "UTC", error = FALSE)
check_tz(Sys.time(), "UTC", error = FALSE)
Checks if scalar hms object using vld_time()
.
chk_time(x, x_name = NULL)
chk_time(x, x_name = NULL)
x |
The object to check. |
x_name |
A string of the name of object x or NULL. |
NULL
, invisibly. Called for the side effect of throwing an error
if the condition is not met.
Other check:
check_tz()
chk_time(hms::as_hms("10:00:10")) try(chk_time(1))
chk_time(hms::as_hms("10:00:10")) try(chk_time(1))
A dtt (short for date time) object is an object of class Date (date), POSIXct (datetime) or hms (time).
Add time units to a date time vector.
dtt_add_units(x, units, n = 1L) dtt_add_years(x, n = 1L, ...) dtt_add_months(x, n = 1L, ...) dtt_add_days(x, n = 1L, ...) dtt_add_hours(x, n = 1L, ...) dtt_add_minutes(x, n = 1L, ...) dtt_add_seconds(x, n = 1L, ...)
dtt_add_units(x, units, n = 1L) dtt_add_years(x, n = 1L, ...) dtt_add_months(x, n = 1L, ...) dtt_add_days(x, n = 1L, ...) dtt_add_hours(x, n = 1L, ...) dtt_add_minutes(x, n = 1L, ...) dtt_add_seconds(x, n = 1L, ...)
x |
A date/time vector. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
n |
An integer of the number of units. |
... |
Unused. |
The modified date time vector.
Other add:
dtt_date_add_time()
dtt_add_units(as.Date("1999-12-31"), "days")
dtt_add_units(as.Date("1999-12-31"), "days")
Adjusts the time zone so that clock (but not the actual) time is altered
for a date time vector.
Equivalent to lubridate::with_tz()
.
dtt_adjust_tz(x, tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_adjust_tz(x, tz = dtt_default_tz(), ...)
dtt_adjust_tz(x, tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_adjust_tz(x, tz = dtt_default_tz(), ...)
x |
A POSIXct vector. |
tz |
A string of the time zone. |
... |
Unused. |
The date time vector with the new time zone and time.
dtt_adjust_tz(POSIXct)
: Adjust the time zone for a POSIXct vector
Other tz:
dtt_set_tz()
,
dtt_sys_tz()
,
dtt_tz()
dtt_adjust_tz(as.POSIXct("1970-01-01", tz = "Etc/GMT+8"), tz = "UTC")
dtt_adjust_tz(as.POSIXct("1970-01-01", tz = "Etc/GMT+8"), tz = "UTC")
Adjust Units
dtt_adjust_units(x, from = "seconds", to = "seconds")
dtt_adjust_units(x, from = "seconds", to = "seconds")
x |
An integer or numeric vector |
from |
A string of the original units. |
to |
A string of the new units. |
A numeric vector.
Other units:
dtt_units()
,
dtt_units_per_unit()
dtt_adjust_units(60, to = "minutes")
dtt_adjust_units(60, to = "minutes")
Aggregates a date/time vector
dtt_aggregate(x, units, ...) ## S3 method for class 'Date' dtt_aggregate(x, units = "days", ...) ## S3 method for class 'POSIXct' dtt_aggregate(x, units = "seconds", ...) ## S3 method for class 'hms' dtt_aggregate(x, units = "seconds", ...)
dtt_aggregate(x, units, ...) ## S3 method for class 'Date' dtt_aggregate(x, units = "days", ...) ## S3 method for class 'POSIXct' dtt_aggregate(x, units = "seconds", ...) ## S3 method for class 'hms' dtt_aggregate(x, units = "seconds", ...)
x |
A date/time vector. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
... |
Unused. |
The possible units values are 'seconds', 'minutes', 'hours', 'days', 'months' or 'years'.
The floored date/time vector.
dtt_aggregate(Date)
: Aggregate a Date vector
dtt_aggregate(POSIXct)
: Aggregate a POSIXct vector
dtt_aggregate(hms)
: Aggregate a hms vector
dtt_aggregate(as.Date(c("1992-01-01", "1991-02-02", "1991-03-03")), "years")
dtt_aggregate(as.Date(c("1992-01-01", "1991-02-02", "1991-03-03")), "years")
Completes date/time vector.
dtt_complete(x, ...) ## S3 method for class 'Date' dtt_complete( x, from = min(x), to = max(x), units = "days", unique = TRUE, sort = TRUE, ... ) ## S3 method for class 'POSIXct' dtt_complete( x, from = min(x), to = max(x), units = "seconds", unique = TRUE, sort = TRUE, ... ) ## S3 method for class 'hms' dtt_complete( x, from = min(x), to = max(x), units = "seconds", unique = TRUE, sort = TRUE, ... )
dtt_complete(x, ...) ## S3 method for class 'Date' dtt_complete( x, from = min(x), to = max(x), units = "days", unique = TRUE, sort = TRUE, ... ) ## S3 method for class 'POSIXct' dtt_complete( x, from = min(x), to = max(x), units = "seconds", unique = TRUE, sort = TRUE, ... ) ## S3 method for class 'hms' dtt_complete( x, from = min(x), to = max(x), units = "seconds", unique = TRUE, sort = TRUE, ... )
x |
A date/time vector. |
... |
Unused. |
from |
A date/time scalar of the start. |
to |
A date/time scalar of the end. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
unique |
A flag specifying whether to only return unique values. |
sort |
A flag specifying whether to sort the vector. |
The completed date/time vector.
dtt_complete(Date)
: Complete a Date sequence vector
dtt_complete(POSIXct)
: Complete a POSIXct sequence vector
dtt_complete(hms)
: Complete a hms sequence vector
Other complete:
dtt_completed()
dtt_complete(as.Date(c("2001-01-01", "2001-01-03", "2001-01-01")))
dtt_complete(as.Date(c("2001-01-01", "2001-01-03", "2001-01-01")))
Tests whether a date time is complete.
dtt_completed(x, ...) ## S3 method for class 'Date' dtt_completed(x, units = "days", unique = TRUE, sorted = TRUE, ...) ## S3 method for class 'POSIXct' dtt_completed(x, units = "seconds", unique = TRUE, sorted = TRUE, ...) ## S3 method for class 'hms' dtt_completed(x, units = "seconds", unique = TRUE, sorted = TRUE, ...)
dtt_completed(x, ...) ## S3 method for class 'Date' dtt_completed(x, units = "days", unique = TRUE, sorted = TRUE, ...) ## S3 method for class 'POSIXct' dtt_completed(x, units = "seconds", unique = TRUE, sorted = TRUE, ...) ## S3 method for class 'hms' dtt_completed(x, units = "seconds", unique = TRUE, sorted = TRUE, ...)
x |
A date/time vector. |
... |
Unused. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
unique |
A flag indicating whether the values must be unique. |
sorted |
A flag indicating whether the values must be sorted. |
A flag indicating whether complete.
dtt_completed(Date)
: Test if Date vector is complete
dtt_completed(POSIXct)
: Test if POSIXct vector is complete
dtt_completed(hms)
: Test if POSIXct vector is complete
Other complete:
dtt_complete()
Coerces vectors to floored Date vectors.
dtt_date(x, ...) dtt_date(x) <- value ## S3 method for class 'integer' dtt_date(x, origin = as.Date("1970-01-01"), ...) ## S3 method for class 'double' dtt_date(x, origin = as.Date("1970-01-01"), ...) ## S3 method for class 'character' dtt_date(x, ...) ## S3 method for class 'Date' dtt_date(x, ...) ## S3 method for class 'POSIXct' dtt_date(x, ...) ## S3 method for class 'hms' dtt_date(x, ...) ## S3 replacement method for class 'Date' dtt_date(x) <- value ## S3 replacement method for class 'POSIXct' dtt_date(x) <- value dtt_set_date(x, value)
dtt_date(x, ...) dtt_date(x) <- value ## S3 method for class 'integer' dtt_date(x, origin = as.Date("1970-01-01"), ...) ## S3 method for class 'double' dtt_date(x, origin = as.Date("1970-01-01"), ...) ## S3 method for class 'character' dtt_date(x, ...) ## S3 method for class 'Date' dtt_date(x, ...) ## S3 method for class 'POSIXct' dtt_date(x, ...) ## S3 method for class 'hms' dtt_date(x, ...) ## S3 replacement method for class 'Date' dtt_date(x) <- value ## S3 replacement method for class 'POSIXct' dtt_date(x) <- value dtt_set_date(x, value)
x |
A vector. |
... |
Unused. |
value |
A date vector. |
origin |
Origin date. |
A floored Date vector.
dtt_date(integer)
: Coerce integer vector to a floored Date vector
dtt_date(double)
: Coerce double vector to a floored Date vector
dtt_date(character)
: Coerce character vector to a floored Date vector
dtt_date(Date)
: Coerce Date vector to a floored Date vector
dtt_date(POSIXct)
: Coerce POSIXct vector to a floored Date vector
dtt_date(hms)
: Coerce hms vector to a floored Date vector
dtt_date(Date) <- value
: Set date values for a Date vector
dtt_date(POSIXct) <- value
: Set date values for a POSIXct vector
Other floor:
dtt_date_time()
,
dtt_excel_to_date()
,
dtt_floor()
,
dtt_floored()
,
dtt_set_time()
dtt_date(1L) dtt_date(-1) dtt_date("2000-01-01") as.Date(as.POSIXct("2019-05-01", tz = "Etc/GMT-8")) dtt_date(as.POSIXct("2019-05-01", tz = "Etc/GMT-8")) dtt_date(hms::as_hms("23:59:59")) dtt_date(hms::as_hms("24:00:00"))
dtt_date(1L) dtt_date(-1) dtt_date("2000-01-01") as.Date(as.POSIXct("2019-05-01", tz = "Etc/GMT-8")) dtt_date(as.POSIXct("2019-05-01", tz = "Etc/GMT-8")) dtt_date(hms::as_hms("23:59:59")) dtt_date(hms::as_hms("24:00:00"))
Adds times to Dates vector and sets timezone in a single function.
dtt_date_add_time(x, time, tz = dtt_default_tz())
dtt_date_add_time(x, time, tz = dtt_default_tz())
x |
A Date vector. |
time |
A hms vector of the time. |
tz |
A string of the time zone. |
A POSIXct vector.
Other add:
dtt_add_units()
dtt_date_add_time( as.Date("2001-03-05"), hms::as_hms("06:07:08"), tz = "Etc/GMT+9" )
dtt_date_add_time( as.Date("2001-03-05"), hms::as_hms("06:07:08"), tz = "Etc/GMT+9" )
Create date object from vectors of year, month and day values.
dtt_date_from_ints(year = 1972L, month = 1L, day = 1L)
dtt_date_from_ints(year = 1972L, month = 1L, day = 1L)
year |
An integer of the year. The default value is 1972. |
month |
An integer of the month between 1 and 12. The default value is the 1st month. |
day |
An integer of the day between 1 and 31. The default value is the 1st day. |
This can be very helpful when needing to create a date column in a data frame from year, month and days columns. Vectors must all be the same length or be of length one.
A floored Date vector.
Other creates:
dtt_date_time_from_ints()
,
dtt_time_from_ints()
dtt_date_from_ints( year = 1991, month = 07, day = 23 ) dtt_date_from_ints( year = c(1991, 1992, 1993), month = c(07, 07, 07), day = c(23, 24, 21) ) year_vals <- c(1991, 1992, 1993) month_vals <- c(07, 07, 07) day_vals <- c(23, 24, 21) dtt_date_from_ints(year_vals, month_vals, day_vals) year_vals <- 2022 month_vals <- 1:12 day_vals <- 15 dtt_date_from_ints(year_vals, month_vals, day_vals) dtt_date_from_ints(year_vals, month_vals)
dtt_date_from_ints( year = 1991, month = 07, day = 23 ) dtt_date_from_ints( year = c(1991, 1992, 1993), month = c(07, 07, 07), day = c(23, 24, 21) ) year_vals <- c(1991, 1992, 1993) month_vals <- c(07, 07, 07) day_vals <- c(23, 24, 21) dtt_date_from_ints(year_vals, month_vals, day_vals) year_vals <- 2022 month_vals <- 1:12 day_vals <- 15 dtt_date_from_ints(year_vals, month_vals, day_vals) dtt_date_from_ints(year_vals, month_vals)
Coerces vectors to floored POSIXct vectors.
dtt_date_time(x, ...) ## S3 method for class 'integer' dtt_date_time(x, tz = dtt_default_tz(), ...) ## S3 method for class 'double' dtt_date_time(x, tz = dtt_default_tz(), ...) ## S3 method for class 'character' dtt_date_time(x, tz = dtt_default_tz(), ...) ## S3 method for class 'Date' dtt_date_time(x, time = hms::as_hms("00:00:00"), tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_date_time(x, tz = dtt_tz(x), ...) ## S3 method for class 'hms' dtt_date_time(x, date = dtt_date("1970-01-01"), tz = dtt_default_tz(), ...)
dtt_date_time(x, ...) ## S3 method for class 'integer' dtt_date_time(x, tz = dtt_default_tz(), ...) ## S3 method for class 'double' dtt_date_time(x, tz = dtt_default_tz(), ...) ## S3 method for class 'character' dtt_date_time(x, tz = dtt_default_tz(), ...) ## S3 method for class 'Date' dtt_date_time(x, time = hms::as_hms("00:00:00"), tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_date_time(x, tz = dtt_tz(x), ...) ## S3 method for class 'hms' dtt_date_time(x, date = dtt_date("1970-01-01"), tz = dtt_default_tz(), ...)
x |
A vector. |
... |
Unused. |
tz |
A string of the time zone. |
time |
A hms vector of the time. |
date |
A Date vector of the date. |
A floored POSIXct vector.
dtt_date_time(integer)
: Coerce integer vector to a floored POSIXct vector
dtt_date_time(double)
: Coerce double vector to a floored POSIXct vector
dtt_date_time(character)
: Coerce character vector to a floored POSIXct vector
dtt_date_time(Date)
: Coerce Date vector to a floored POSIXct vector
dtt_date_time(POSIXct)
: Coerce POSIXct vector to a floored POSIXct vector
dtt_date_time(hms)
: Coerce hms vector to a floored POSIXct vector
Other floor:
dtt_date()
,
dtt_excel_to_date()
,
dtt_floor()
,
dtt_floored()
,
dtt_set_time()
dtt_date_time(1L) dtt_date_time(-1) dtt_date_time(1, tz = "Etc/GMT+8") dtt_date_time(as.Date("2000-01-02")) dtt_date_time(as.Date("2000-01-02"), time = hms::as_hms("04:05:06"))
dtt_date_time(1L) dtt_date_time(-1) dtt_date_time(1, tz = "Etc/GMT+8") dtt_date_time(as.Date("2000-01-02")) dtt_date_time(as.Date("2000-01-02"), time = hms::as_hms("04:05:06"))
Create date object from vectors of year, month and day values.
dtt_date_time_from_ints( year = 1972L, month = 1L, day = 1L, hour = 0L, minute = 0L, second = 0L, tz = dtt_default_tz() )
dtt_date_time_from_ints( year = 1972L, month = 1L, day = 1L, hour = 0L, minute = 0L, second = 0L, tz = dtt_default_tz() )
year |
An integer of the year. The default value is 1972. |
month |
An integer of the month between 1 and 12. The default value is the 1st month. |
day |
An integer of the day between 1 and 31. The default value is the 1st day. |
hour |
An integer of the hour between 0 and 23.The default value is hour zero. |
minute |
An integer of the minute between 0 to 59. The default value is minute zero. |
second |
An integer of the second between 0 to 59. The default value is second zero. |
tz |
A string of the time zone. |
This can be very helpful when needing to create a date time column in a data frame from year, month, day, hour, minute, and second columns. Vectors must all be the same length or be of length one.
A POSIXct vector
Other creates:
dtt_date_from_ints()
,
dtt_time_from_ints()
dtt_date_time_from_ints( year = 1991, month = 07, day = 23, hour = 06, minute = 25, second = 0, tz = "Etc/GMT+8" ) dtt_date_time_from_ints( year = c(1991, 1992, 1993), month = c(07, 07, 07), day = c(23, 24, 21), hour = c(06, 05, 07), minute = c(25, 24, 15), second = c(0, 0, 0), tz = "Etc/GMT+8" ) year <- c(1991, 1992, 1993) month <- c(07, 08, 09) day <- c(23, 24, 21) hour <- c(06, 05, 07) minute <- c(25, 24, 15) second <- 30 dtt_date_time_from_ints(year, month, day, hour, minute, second) dtt_date_time_from_ints(year, month, day)
dtt_date_time_from_ints( year = 1991, month = 07, day = 23, hour = 06, minute = 25, second = 0, tz = "Etc/GMT+8" ) dtt_date_time_from_ints( year = c(1991, 1992, 1993), month = c(07, 07, 07), day = c(23, 24, 21), hour = c(06, 05, 07), minute = c(25, 24, 15), second = c(0, 0, 0), tz = "Etc/GMT+8" ) year <- c(1991, 1992, 1993) month <- c(07, 08, 09) day <- c(23, 24, 21) hour <- c(06, 05, 07) minute <- c(25, 24, 15) second <- 30 dtt_date_time_from_ints(year, month, day, hour, minute, second) dtt_date_time_from_ints(year, month, day)
Gets and sets day values for date/time vectors.
dtt_day(x, ...) dtt_day(x) <- value ## S3 method for class 'Date' dtt_day(x, ...) ## S3 method for class 'POSIXct' dtt_day(x, ...) ## S3 replacement method for class 'Date' dtt_day(x) <- value ## S3 replacement method for class 'POSIXct' dtt_day(x) <- value dtt_days(x, ...) dtt_days(x) <- value dtt_set_day(x, value)
dtt_day(x, ...) dtt_day(x) <- value ## S3 method for class 'Date' dtt_day(x, ...) ## S3 method for class 'POSIXct' dtt_day(x, ...) ## S3 replacement method for class 'Date' dtt_day(x) <- value ## S3 replacement method for class 'POSIXct' dtt_day(x) <- value dtt_days(x, ...) dtt_days(x) <- value dtt_set_day(x, value)
x |
A date/time vector. |
... |
Unused. |
value |
A integer vector of the day value(s). |
An integer vector (or the modified date/time vector).
dtt_day(Date)
: Get integer vector of day values for a Date vector
dtt_day(POSIXct)
: Get integer vector of day values for a POSIXct vector
dtt_day(Date) <- value
: Set day values for a Date vector
dtt_day(POSIXct) <- value
: Set day values for a POSIXct vector
Other set date:
dtt_months()
,
dtt_years()
x <- as.Date("1990-01-02") dtt_day(x) dtt_day(x) <- 27L x x <- as.POSIXct("1990-01-02 23:40:51") dtt_day(x) dtt_day(x) <- 27L x
x <- as.Date("1990-01-02") dtt_day(x) dtt_day(x) <- 27L x x <- as.POSIXct("1990-01-02 23:40:51") dtt_day(x) dtt_day(x) <- 27L x
Gets decimal day values for date/time vectors.
dtt_day_decimal(x, ...) ## S3 method for class 'Date' dtt_day_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_day_decimal(x, ...)
dtt_day_decimal(x, ...) ## S3 method for class 'Date' dtt_day_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_day_decimal(x, ...)
x |
A date/time vector. |
... |
Unused. |
A numeric vector.
dtt_day_decimal(Date)
: Get numeric vector of decimal year values for a
Date vector
dtt_day_decimal(POSIXct)
: Get numeric vector of decimal year values for a
POSIXct vector
Other decimal:
dtt_doy_decimal()
,
dtt_hour_decimal()
,
dtt_minute_decimal()
,
dtt_month_decimal()
,
dtt_year_decimal()
x <- as.POSIXct("1990-01-03 10:00:01") dtt_day_decimal(x)
x <- as.POSIXct("1990-01-03 10:00:01") dtt_day_decimal(x)
Days in the Month
dtt_days_in_month(x)
dtt_days_in_month(x)
x |
A Date or POSIXct vector. |
A integer vector of 28 to 31 indicating the days in the month.
Other days:
dtt_days_in_year()
,
dtt_doy()
,
dtt_doy_to_date()
dtt_days_in_month(as.Date(c("2000-02-11", "2001-02-01")))
dtt_days_in_month(as.Date(c("2000-02-11", "2001-02-01")))
Days in the Year
dtt_days_in_year(x)
dtt_days_in_year(x)
x |
A Date or POSIXct vector. |
A integer vector of 365 and 366 indicates the days of the year.
Other days:
dtt_days_in_month()
,
dtt_doy()
,
dtt_doy_to_date()
dtt_days_in_year(as.Date(c("2000-10-11", "2001-01-01")))
dtt_days_in_year(as.Date(c("2000-10-11", "2001-01-01")))
Dayte
dtt_dayte(x, ...) ## S3 method for class 'Date' dtt_dayte(x, start = 1L, ...) ## S3 method for class 'POSIXct' dtt_dayte(x, start = 1L, ...)
dtt_dayte(x, ...) ## S3 method for class 'Date' dtt_dayte(x, start = 1L, ...) ## S3 method for class 'POSIXct' dtt_dayte(x, start = 1L, ...)
x |
A date/time vector. |
... |
Unused. |
start |
An integer scalar of the starting month or a Date scalar of the starting date. |
A Date vector with the year set to year.
A Date vector of the daytes.
dtt_dayte(Date)
: Dayte a Date vector
dtt_dayte(POSIXct)
: Dayte a POSIXct vector
Other dayte:
dtt_dayte_time()
,
dtt_daytt()
dtt_dayte(as.Date(c("2001-01-01", "2015-12-13")))
dtt_dayte(as.Date(c("2001-01-01", "2015-12-13")))
Dayte Time
dtt_dayte_time(x, ...) ## S3 method for class 'Date' dtt_dayte_time(x, start = 1L, tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_dayte_time(x, start = 1L, ...)
dtt_dayte_time(x, ...) ## S3 method for class 'Date' dtt_dayte_time(x, start = 1L, tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_dayte_time(x, start = 1L, ...)
x |
A date/time vector. |
... |
Unused. |
start |
An integer scalar of the starting month or a Date scalar of the starting date. |
tz |
A string of the time zone. |
A Date vector with the year set to year.
A POSIXct vector of the dayte times.
dtt_dayte_time(Date)
: Dayte Time a Date vector
dtt_dayte_time(POSIXct)
: Dayte Time a POSIXct vector
Other dayte:
dtt_dayte()
,
dtt_daytt()
dtt_dayte_time( as.POSIXct( c("2001-01-01 12:13:14", "2015-12-13"), tz = "Etc/GMT+10" ) )
dtt_dayte_time( as.POSIXct( c("2001-01-01 12:13:14", "2015-12-13"), tz = "Etc/GMT+10" ) )
Dayte Time
dtt_daytt(x, start = 1L)
dtt_daytt(x, start = 1L)
x |
A Date or POSIXct vector. |
start |
An integer vector of the starting month or a Date vector of the starting date. |
A Date or POSIXct vector with the year for February 29th as 1972.
Other dayte:
dtt_dayte()
,
dtt_dayte_time()
Decade
dtt_decade(x, ...) ## S3 method for class 'Date' dtt_decade(x, ...)
dtt_decade(x, ...) ## S3 method for class 'Date' dtt_decade(x, ...)
x |
A date/time vector. |
... |
Unused. |
A integer vector of the decade.
dtt_decade(Date)
: Decade a Date vector
dtt_decade(as.Date(c("2001-01-01", "2015-12-13")))
dtt_decade(as.Date(c("2001-01-01", "2015-12-13")))
Gets the time difference in secs, minutes, hours, days or weeks. Uses difftime() but floors x and y first after coercing to POSIXct and adjusts the timezone of y to match that of x.
dtt_diff(x, y, units = "secs", as_difftime = FALSE)
dtt_diff(x, y, units = "secs", as_difftime = FALSE)
x |
An object that can be coerced to a POSIXct using dtt_date_time(). |
y |
An object that can be coerced to a POSIXct using dtt_date_time(). |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
as_difftime |
A flag specifying whether to return a difftime vector. |
A numeric vector of the time difference.
dtt_diff( as.Date(c("2001-01-02", "2000-12-31")), as.Date("2001-01-01"), "hours" ) dtt_diff(as.Date("2001-01-02"), as.Date("2001-01-01"), "weeks")
dtt_diff( as.Date(c("2001-01-02", "2000-12-31")), as.Date("2001-01-01"), "hours" ) dtt_diff(as.Date("2001-01-02"), as.Date("2001-01-01"), "weeks")
Day of the Year
dtt_doy(x, ...)
dtt_doy(x, ...)
x |
A Date or POSIXct vector. |
... |
Unused. |
A integer vector between 1 and 366 of the day of the year.
Other days:
dtt_days_in_month()
,
dtt_days_in_year()
,
dtt_doy_to_date()
dtt_doy(Sys.Date())
dtt_doy(Sys.Date())
Day of the Year Decimal
dtt_doy_decimal(x, ...)
dtt_doy_decimal(x, ...)
x |
A Date or POSIXct vector. |
... |
Unused. |
A numeric vector between 0 and 366 of the day of the year.
Other decimal:
dtt_day_decimal()
,
dtt_hour_decimal()
,
dtt_minute_decimal()
,
dtt_month_decimal()
,
dtt_year_decimal()
dtt_doy_decimal(Sys.Date())
dtt_doy_decimal(Sys.Date())
Day of the Year to Date
dtt_doy_to_date(x, year = 1972L)
dtt_doy_to_date(x, year = 1972L)
x |
An integer vector of the Day of the Year. |
year |
An integer scalar or vector of the year. |
A Date vector.
Other days:
dtt_days_in_month()
,
dtt_days_in_year()
,
dtt_doy()
dtt_doy_to_date(3)
dtt_doy_to_date(3)
Converts Excel dates encoded as serial numbers to date class.
dtt_excel_to_date(x, modern = TRUE, ...)
dtt_excel_to_date(x, modern = TRUE, ...)
x |
A vector of numbers to convert. |
modern |
A flag specifying whether to use the modern or old Excel date system. |
... |
Unused. |
Defaults to the modern Excel date encoding system. Excel for Mac 2008 and earlier Mac versions of Excel use a different date system. If the date 2016-01-01 is represented by 42370, it's the modern system. If it's 40908, it's the old system.
A floored Date vector.
Other floor:
dtt_date()
,
dtt_date_time()
,
dtt_floor()
,
dtt_floored()
,
dtt_set_time()
dtt_excel_to_date(42370) dtt_excel_to_date(40908, modern = FALSE)
dtt_excel_to_date(42370) dtt_excel_to_date(40908, modern = FALSE)
Converts Excel serial date times to date time class.
dtt_excel_to_date_time(x, tz = dtt_default_tz(), modern = TRUE, ...)
dtt_excel_to_date_time(x, tz = dtt_default_tz(), modern = TRUE, ...)
x |
A vector of numbers to convert. |
tz |
A string of the time zone. |
modern |
A flag specifying whether to use the modern or old Excel date system. |
... |
Unused. |
Defaults to the modern Excel date encoding system. Excel for Mac 2008 and earlier Mac versions of Excel use a different date system. If the date 2016-01-01 is represented by 42370, it's the modern system. If it's 40908, it's the old system.
A floored POSIXct vector.
dtt_excel_to_date_time(42370.1234) dtt_excel_to_date_time(c(1000.1145, 43397.84578)) dtt_excel_to_date_time(45324.1234, tz = "UTC") dtt_excel_to_date_time(42370.1234, modern = FALSE)
dtt_excel_to_date_time(42370.1234) dtt_excel_to_date_time(c(1000.1145, 43397.84578)) dtt_excel_to_date_time(45324.1234, tz = "UTC") dtt_excel_to_date_time(42370.1234, modern = FALSE)
Converts Feb 29 to Feb 28th
dtt_feb29_to_28(x)
dtt_feb29_to_28(x)
x |
A Date or POSIXct vector. |
The modified Date or POSIXct vector.
Other leap year:
dtt_leap_year()
dtt_feb29_to_28(as.Date("2004-02-29"))
dtt_feb29_to_28(as.Date("2004-02-29"))
Floors a date/time vector
dtt_floor(x, units, ...) ## S3 method for class 'Date' dtt_floor(x, units = "days", ...) ## S3 method for class 'POSIXct' dtt_floor(x, units = "seconds", ...) ## S3 method for class 'hms' dtt_floor(x, units = "seconds", ...)
dtt_floor(x, units, ...) ## S3 method for class 'Date' dtt_floor(x, units = "days", ...) ## S3 method for class 'POSIXct' dtt_floor(x, units = "seconds", ...) ## S3 method for class 'hms' dtt_floor(x, units = "seconds", ...)
x |
A date/time vector. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
... |
Unused. |
The floored date/time vector.
dtt_floor(Date)
: Floor a Date vector
dtt_floor(POSIXct)
: Floor a POSIXct vector
dtt_floor(hms)
: Floor a hms vector
Other floor:
dtt_date()
,
dtt_date_time()
,
dtt_excel_to_date()
,
dtt_floored()
,
dtt_set_time()
dtt_floor(hms::as_hms("23:59:59"), "hours")
dtt_floor(hms::as_hms("23:59:59"), "hours")
Test whether a date time vector is floored.
dtt_floored(x, ...) ## S3 method for class 'Date' dtt_floored(x, units = "days", ...) ## S3 method for class 'POSIXct' dtt_floored(x, units = "seconds", ...) ## S3 method for class 'hms' dtt_floored(x, units = "seconds", ...)
dtt_floored(x, ...) ## S3 method for class 'Date' dtt_floored(x, units = "days", ...) ## S3 method for class 'POSIXct' dtt_floored(x, units = "seconds", ...) ## S3 method for class 'hms' dtt_floored(x, units = "seconds", ...)
x |
A Date, POSIXct or hms vector. |
... |
Unused. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
A flag indicating whether floored.
dtt_floored(Date)
: Test if Date vector is floored
dtt_floored(POSIXct)
: Test if POSIXct vector is floored
dtt_floored(hms)
: Test if hms vector is floored
Other floor:
dtt_date()
,
dtt_date_time()
,
dtt_excel_to_date()
,
dtt_floor()
,
dtt_set_time()
dtt_floored(as.Date("2002-02-01"))
dtt_floored(as.Date("2002-02-01"))
Gets decimal hour values for date/time vectors.
dtt_hour_decimal(x, ...) ## S3 method for class 'Date' dtt_hour_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_hour_decimal(x, ...) ## S3 method for class 'hms' dtt_hour_decimal(x, ...)
dtt_hour_decimal(x, ...) ## S3 method for class 'Date' dtt_hour_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_hour_decimal(x, ...) ## S3 method for class 'hms' dtt_hour_decimal(x, ...)
x |
A date/time vector. |
... |
Unused. |
A numeric vector.
dtt_hour_decimal(Date)
: Get numeric vector of decimal hour values for a
Date vector
dtt_hour_decimal(POSIXct)
: Get numeric vector of decimal hour values for a
POSIXct vector
dtt_hour_decimal(hms)
: Get numeric vector of decimal hour values for a
hms vector
Other decimal:
dtt_day_decimal()
,
dtt_doy_decimal()
,
dtt_minute_decimal()
,
dtt_month_decimal()
,
dtt_year_decimal()
x <- as.POSIXct("1990-01-02 23:40:51") dtt_hour_decimal(x) x <- hms::as_hms("23:40:51") dtt_hour_decimal(x)
x <- as.POSIXct("1990-01-02 23:40:51") dtt_hour_decimal(x) x <- hms::as_hms("23:40:51") dtt_hour_decimal(x)
Gets and sets hour values for date/time vectors.
dtt_hours(x, ...) dtt_hours(x) <- value dtt_hour(x, ...) dtt_hour(x) <- value ## S3 method for class 'Date' dtt_hour(x, ...) ## S3 method for class 'POSIXct' dtt_hour(x, ...) ## S3 method for class 'hms' dtt_hour(x, ...) ## S3 replacement method for class 'POSIXct' dtt_hour(x) <- value ## S3 replacement method for class 'hms' dtt_hour(x) <- value dtt_set_hour(x, value)
dtt_hours(x, ...) dtt_hours(x) <- value dtt_hour(x, ...) dtt_hour(x) <- value ## S3 method for class 'Date' dtt_hour(x, ...) ## S3 method for class 'POSIXct' dtt_hour(x, ...) ## S3 method for class 'hms' dtt_hour(x, ...) ## S3 replacement method for class 'POSIXct' dtt_hour(x) <- value ## S3 replacement method for class 'hms' dtt_hour(x) <- value dtt_set_hour(x, value)
x |
A date/time vector. |
... |
Unused. |
value |
A integer vector of the hour value(s). |
An integer vector (or the modified date/time vector).
dtt_hour(Date)
: Get integer vector of hour values for a Date vector
dtt_hour(POSIXct)
: Get integer vector of hour values for a POSIXct vector
dtt_hour(hms)
: Get integer vector of hour values for a hms vector
dtt_hour(POSIXct) <- value
: Set hour values for a POSIXct vector
dtt_hour(hms) <- value
: Set hour values for a hms vector
Other set time:
dtt_minutes()
,
dtt_seconds()
x <- as.POSIXct("1990-01-02 23:40:51") dtt_hour(x) dtt_hour(x) <- 01L x x <- hms::as_hms("23:40:51") dtt_hour(x) dtt_hour(x) <- 01L x
x <- as.POSIXct("1990-01-02 23:40:51") dtt_hour(x) dtt_hour(x) <- 01L x x <- hms::as_hms("23:40:51") dtt_hour(x) dtt_hour(x) <- 01L x
Is Date
dtt_is_date(x)
dtt_is_date(x)
x |
An R object. |
A flag indicating whether R is a Date vector.
Other is:
dtt_is_date_time()
,
is_date_time()
Is Date Time
dtt_is_date_time(x)
dtt_is_date_time(x)
x |
An R object. |
A flag indicating whether R is a POSIXct vector.
Other is:
dtt_is_date()
,
is_date_time()
Is Date or DateTime Object
dtt_is_dtt(x)
dtt_is_dtt(x)
x |
An R object. |
A flag indicating whether R is a Date or POSIXct vector.
Tests whether each year is a leap year.
dtt_leap_year(x)
dtt_leap_year(x)
x |
A date/time vector. |
A logical vector indicating whether each year is a leap year.
Other leap year:
dtt_feb29_to_28()
dtt_leap_year(as.Date("1999-03-04", "2000-02-01"))
dtt_leap_year(as.Date("1999-03-04", "2000-02-01"))
Gets decimal minute values for date/time vectors.
dtt_minute_decimal(x, ...) ## S3 method for class 'Date' dtt_minute_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_minute_decimal(x, ...) ## S3 method for class 'hms' dtt_minute_decimal(x, ...)
dtt_minute_decimal(x, ...) ## S3 method for class 'Date' dtt_minute_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_minute_decimal(x, ...) ## S3 method for class 'hms' dtt_minute_decimal(x, ...)
x |
A date/time vector. |
... |
Unused. |
A numeric vector.
dtt_minute_decimal(Date)
: Get numeric vector of decimal minute values
for a Date vector
dtt_minute_decimal(POSIXct)
: Get numeric vector of decimal minute values
for a POSIXct vector
dtt_minute_decimal(hms)
: Get numeric vector of decimal minute values
for a hms vector
Other decimal:
dtt_day_decimal()
,
dtt_doy_decimal()
,
dtt_hour_decimal()
,
dtt_month_decimal()
,
dtt_year_decimal()
x <- as.POSIXct("1990-01-02 23:40:51") dtt_minute_decimal(x) x <- hms::as_hms("23:40:51") dtt_minute_decimal(x)
x <- as.POSIXct("1990-01-02 23:40:51") dtt_minute_decimal(x) x <- hms::as_hms("23:40:51") dtt_minute_decimal(x)
Gets and sets minute values for date/time vectors.
dtt_minutes(x, ...) dtt_minutes(x) <- value dtt_minute(x, ...) dtt_minute(x) <- value ## S3 method for class 'Date' dtt_minute(x, ...) ## S3 method for class 'POSIXct' dtt_minute(x, ...) ## S3 method for class 'hms' dtt_minute(x, ...) ## S3 replacement method for class 'POSIXct' dtt_minute(x) <- value ## S3 replacement method for class 'hms' dtt_minute(x) <- value dtt_set_minute(x, value)
dtt_minutes(x, ...) dtt_minutes(x) <- value dtt_minute(x, ...) dtt_minute(x) <- value ## S3 method for class 'Date' dtt_minute(x, ...) ## S3 method for class 'POSIXct' dtt_minute(x, ...) ## S3 method for class 'hms' dtt_minute(x, ...) ## S3 replacement method for class 'POSIXct' dtt_minute(x) <- value ## S3 replacement method for class 'hms' dtt_minute(x) <- value dtt_set_minute(x, value)
x |
A date/time vector. |
... |
Unused. |
value |
A integer vector of the minute value(s). |
An integer vector (or the modified date/time vector).
dtt_minute(Date)
: Get integer vector of minute values for a Date vector
dtt_minute(POSIXct)
: Get integer vector of minute values for a POSIXct
vector
dtt_minute(hms)
: Get integer vector of minute values for a hms vector
dtt_minute(POSIXct) <- value
: Set minute values for a POSIXct vector
dtt_minute(hms) <- value
: Set minute values for a hms vector
Other set time:
dtt_hours()
,
dtt_seconds()
x <- as.POSIXct("1990-01-02 23:40:51") dtt_minute(x) dtt_minute(x) <- 27L x x <- hms::as_hms("23:40:51") dtt_minute(x) dtt_minute(x) <- 27L x
x <- as.POSIXct("1990-01-02 23:40:51") dtt_minute(x) dtt_minute(x) <- 27L x x <- hms::as_hms("23:40:51") dtt_minute(x) dtt_minute(x) <- 27L x
Gets decimal month values for date/time vectors.
dtt_month_decimal(x, ...) ## S3 method for class 'Date' dtt_month_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_month_decimal(x, ...)
dtt_month_decimal(x, ...) ## S3 method for class 'Date' dtt_month_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_month_decimal(x, ...)
x |
A date/time vector. |
... |
Unused. |
A numeric vector.
dtt_month_decimal(Date)
: Get numeric vector of decimal year values for a
Date vector
dtt_month_decimal(POSIXct)
: Get numeric vector of decimal year values for a
POSIXct vector
Other decimal:
dtt_day_decimal()
,
dtt_doy_decimal()
,
dtt_hour_decimal()
,
dtt_minute_decimal()
,
dtt_year_decimal()
x <- as.POSIXct("1990-01-03 10:00:01") dtt_month_decimal(x)
x <- as.POSIXct("1990-01-03 10:00:01") dtt_month_decimal(x)
Gets and sets month values for date/time vectors.
dtt_months(x, ...) dtt_months(x) <- value dtt_month(x, ...) dtt_month(x) <- value ## S3 method for class 'Date' dtt_month(x, ...) ## S3 method for class 'POSIXct' dtt_month(x, ...) ## S3 replacement method for class 'Date' dtt_month(x) <- value ## S3 replacement method for class 'POSIXct' dtt_month(x) <- value dtt_set_month(x, value)
dtt_months(x, ...) dtt_months(x) <- value dtt_month(x, ...) dtt_month(x) <- value ## S3 method for class 'Date' dtt_month(x, ...) ## S3 method for class 'POSIXct' dtt_month(x, ...) ## S3 replacement method for class 'Date' dtt_month(x) <- value ## S3 replacement method for class 'POSIXct' dtt_month(x) <- value dtt_set_month(x, value)
x |
A date/time vector. |
... |
Unused. |
value |
A integer vector of the month value(s). |
An integer vector (or the modified date/time vector).
dtt_month(Date)
: Get integer vector of month values for a Date vector
dtt_month(POSIXct)
: Get integer vector of month values for a POSIXct vector
dtt_month(Date) <- value
: Set month values for a Date vector
dtt_month(POSIXct) <- value
: Set month values for a POSIXct vector
Other set date:
dtt_day()
,
dtt_years()
x <- as.Date("1990-01-02") dtt_month(x) dtt_month(x) <- 11L x x <- as.POSIXct("1990-01-02 23:40:51") dtt_month(x) dtt_month(x) <- 11L x
x <- as.Date("1990-01-02") dtt_month(x) dtt_month(x) <- 11L x x <- as.POSIXct("1990-01-02 23:40:51") dtt_month(x) dtt_month(x) <- 11L x
Returns a factor of the user specified seasons.
dtt_season( x, start = c(Spring = 3L, Summer = 6L, Autumn = 9L, Winter = 12L), first = NULL )
dtt_season( x, start = c(Spring = 3L, Summer = 6L, Autumn = 9L, Winter = 12L), first = NULL )
x |
A Date or POSIXct vector |
start |
A uniquely named integer vector of the first month of each season or a uniquely named Date vector of the first date of each season. |
first |
A string of the name of first season or NULL in which case the first season is that which includes Jan 1st. |
If the first month of the first season isn't January (1L), then the last season is considered to wrap into the following year.
A factor of the seasons.
dates <- as.Date(c("2001-01-01", "2001-02-28", "2012-09-01", "2012-12-01")) dtt_season(dates) dtt_season(dates, start = c(Monsoon = 2L, `Dry Period` = 6L)) dtt_season( dates, start = c(First = dtt_date("2000-01-01"), Second = dtt_date("2000-06-01")) )
dates <- as.Date(c("2001-01-01", "2001-02-28", "2012-09-01", "2012-12-01")) dtt_season(dates) dtt_season(dates, start = c(Monsoon = 2L, `Dry Period` = 6L)) dtt_season( dates, start = c(First = dtt_date("2000-01-01"), Second = dtt_date("2000-06-01")) )
Gets and sets second values for date/time vectors.
dtt_seconds(x, ...) dtt_seconds(x) <- value dtt_second(x, ...) dtt_second(x) <- value ## S3 method for class 'Date' dtt_second(x, ...) ## S3 method for class 'POSIXct' dtt_second(x, ...) ## S3 method for class 'hms' dtt_second(x, ...) ## S3 replacement method for class 'POSIXct' dtt_second(x) <- value ## S3 replacement method for class 'hms' dtt_second(x) <- value dtt_set_second(x, value)
dtt_seconds(x, ...) dtt_seconds(x) <- value dtt_second(x, ...) dtt_second(x) <- value ## S3 method for class 'Date' dtt_second(x, ...) ## S3 method for class 'POSIXct' dtt_second(x, ...) ## S3 method for class 'hms' dtt_second(x, ...) ## S3 replacement method for class 'POSIXct' dtt_second(x) <- value ## S3 replacement method for class 'hms' dtt_second(x) <- value dtt_set_second(x, value)
x |
A date/time vector. |
... |
Unused. |
value |
A integer vector of the second value(s). |
An integer vector (or the modified date/time vector).
dtt_second(Date)
: Get integer vector of second values for a Date vector
dtt_second(POSIXct)
: Get integer vector of second values for a POSIXct
vector
dtt_second(hms)
: Get integer vector of second values for a time vector
dtt_second(POSIXct) <- value
: Set second values for a POSIXct vector
dtt_second(hms) <- value
: Set second values for a hms vector
Other set time:
dtt_hours()
,
dtt_minutes()
x <- as.POSIXct("1990-01-02 23:40:51") dtt_second(x) dtt_second(x) <- 27L x x <- hms::as_hms("23:40:51") dtt_second(x) dtt_second(x) <- 27L x
x <- as.POSIXct("1990-01-02 23:40:51") dtt_second(x) dtt_second(x) <- 27L x x <- hms::as_hms("23:40:51") dtt_second(x) dtt_second(x) <- 27L x
Creates a date/time sequence vector. from and to are first floored and then a sequence is created by units. If length_out is defined then that number of units are added to from.
dtt_seq(from, to, units, length_out = NULL, ...) ## S3 method for class 'Date' dtt_seq(from, to = from, units = "days", length_out = NULL, ...) ## S3 method for class 'POSIXct' dtt_seq(from, to = from, units = "seconds", length_out = NULL, ...) ## S3 method for class 'hms' dtt_seq( from, to = from, units = "seconds", length_out = NULL, wrap = TRUE, ... )
dtt_seq(from, to, units, length_out = NULL, ...) ## S3 method for class 'Date' dtt_seq(from, to = from, units = "days", length_out = NULL, ...) ## S3 method for class 'POSIXct' dtt_seq(from, to = from, units = "seconds", length_out = NULL, ...) ## S3 method for class 'hms' dtt_seq( from, to = from, units = "seconds", length_out = NULL, wrap = TRUE, ... )
from |
A date/time scalar of the start. |
to |
A date/time scalar of the end. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
length_out |
An integer of the number of units from from. |
... |
Unused. |
wrap |
A flag specifying whether to wrap hms vectors from 23:59:59 to 00:00:00 |
The date/time vector.
dtt_seq(Date)
: Create a Date sequence vector
dtt_seq(POSIXct)
: Create a POSIXct sequence vector
dtt_seq(hms)
: Create a hms sequence vector
dtt_seq(as.Date("2001-01-01"), as.Date("2001-01-05"))
dtt_seq(as.Date("2001-01-01"), as.Date("2001-01-05"))
Coerces vectors to floored (and wrapped) hms vectors.
dtt_set_time(x, value) dtt_time(x, ...) dtt_time(x) <- value ## S3 method for class 'integer' dtt_time(x, ...) ## S3 method for class 'double' dtt_time(x, ...) ## S3 method for class 'character' dtt_time(x, ...) ## S3 method for class 'Date' dtt_time(x, ...) ## S3 method for class 'hms' dtt_time(x, ...) ## S3 method for class 'POSIXct' dtt_time(x, ...) ## S3 method for class 'POSIXlt' dtt_time(x, ...) ## S3 replacement method for class 'Date' dtt_time(x) <- value ## S3 replacement method for class 'POSIXct' dtt_time(x) <- value
dtt_set_time(x, value) dtt_time(x, ...) dtt_time(x) <- value ## S3 method for class 'integer' dtt_time(x, ...) ## S3 method for class 'double' dtt_time(x, ...) ## S3 method for class 'character' dtt_time(x, ...) ## S3 method for class 'Date' dtt_time(x, ...) ## S3 method for class 'hms' dtt_time(x, ...) ## S3 method for class 'POSIXct' dtt_time(x, ...) ## S3 method for class 'POSIXlt' dtt_time(x, ...) ## S3 replacement method for class 'Date' dtt_time(x) <- value ## S3 replacement method for class 'POSIXct' dtt_time(x) <- value
x |
A vector. |
value |
A time vector. |
... |
Unused. |
A floored hms vector.
dtt_time(integer)
: Coerce integer vector to a floored hms vector
dtt_time(double)
: Coerce double vector to a floored hms vector
dtt_time(character)
: Coerce character vector to a floored hms vector
dtt_time(Date)
: Coerce Date vector to a floored hms vector
dtt_time(hms)
: Coerce hms vector to a floored hms vector
dtt_time(POSIXct)
: Coerce POSIXct vector to a floored hms vector
dtt_time(POSIXlt)
: Coerce POSIXlt vector to a floored hms vector
dtt_time(Date) <- value
: Set time values for a Date vector
dtt_time(POSIXct) <- value
: Set time values for a POSIXct vector
Other floor:
dtt_date()
,
dtt_date_time()
,
dtt_excel_to_date()
,
dtt_floor()
,
dtt_floored()
dtt_time(1L) dtt_time(1.999) dtt_time(-0.001) dtt_time(Sys.Date()) dtt_time(as.POSIXct("2001-01-01 02:30:40")) dtt_time(as.POSIXct("2001-01-01 02:30:40", tz = "Etc/GMT-8"))
dtt_time(1L) dtt_time(1.999) dtt_time(-0.001) dtt_time(Sys.Date()) dtt_time(as.POSIXct("2001-01-01 02:30:40")) dtt_time(as.POSIXct("2001-01-01 02:30:40", tz = "Etc/GMT-8"))
Sets the time zone for a date time vector without adjusting the clock time.
Equivalent to lubridate::force_tz()
.
dtt_set_tz(x, tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_set_tz(x, tz = dtt_default_tz(), ...)
dtt_set_tz(x, tz = dtt_default_tz(), ...) ## S3 method for class 'POSIXct' dtt_set_tz(x, tz = dtt_default_tz(), ...)
x |
A date/time vector. |
tz |
A string of the new time zone. |
... |
Unused. |
The date time vector with the new time zone.
dtt_set_tz(POSIXct)
: Set the time zone for a POSIXct vector
Other tz:
dtt_adjust_tz()
,
dtt_sys_tz()
,
dtt_tz()
dtt_set_tz(as.POSIXct("1970-01-01", tz = "Etc/GMT+8"), tz = "UTC")
dtt_set_tz(as.POSIXct("1970-01-01", tz = "Etc/GMT+8"), tz = "UTC")
Study Year
dtt_study_year(x, start = 1L, full = TRUE)
dtt_study_year(x, start = 1L, full = TRUE)
x |
A Date or POSIXct vector. |
start |
An integer vector of the starting month or a Date vector of the starting date. |
full |
A flag specifying whether to return a character vector of the study years (or an integer vector of the first year) |
A character vector of the study year or an integer vector of the first year.
dtt_study_year( as.Date(c("2000-03-31", "2000-04-01", "2001-04-01")), start = 4L ) dtt_study_year( as.Date(c("2000-03-31", "2000-04-01", "2001-04-01")), start = 4L, full = FALSE )
dtt_study_year( as.Date(c("2000-03-31", "2000-04-01", "2001-04-01")), start = 4L ) dtt_study_year( as.Date(c("2000-03-31", "2000-04-01", "2001-04-01")), start = 4L, full = FALSE )
Subtract time units from a date time vector.
dtt_subtract_units(x, n = 1L, units = dtt_units(x)) dtt_subtract_years(x, n = 1L) dtt_subtract_months(x, n = 1L) dtt_subtract_days(x, n = 1L) dtt_subtract_hours(x, n = 1L) dtt_subtract_minutes(x, n = 1L) dtt_subtract_seconds(x, n = 1L)
dtt_subtract_units(x, n = 1L, units = dtt_units(x)) dtt_subtract_years(x, n = 1L) dtt_subtract_months(x, n = 1L) dtt_subtract_days(x, n = 1L) dtt_subtract_hours(x, n = 1L) dtt_subtract_minutes(x, n = 1L) dtt_subtract_seconds(x, n = 1L)
x |
A date/time vector. |
n |
An integer of the number of units. |
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
The modified date time vector.
dtt_subtract_units(as.Date("1999-12-31"), 2L, "days")
dtt_subtract_units(as.Date("1999-12-31"), 2L, "days")
Get System Date
dtt_sys_date(tz = dtt_default_tz())
dtt_sys_date(tz = dtt_default_tz())
tz |
A string of the time zone. |
A floored Date scalar.
Other sys:
dtt_sys_date_time()
,
dtt_sys_time()
## Not run: dtt_set_default_tz("Etc/GMT+12") dtt_sys_date() dtt_set_default_tz("Etc/GMT-12") dtt_sys_date() dtt_sys_date(tz = "Etc/GMT+12") ## End(Not run)
## Not run: dtt_set_default_tz("Etc/GMT+12") dtt_sys_date() dtt_set_default_tz("Etc/GMT-12") dtt_sys_date() dtt_sys_date(tz = "Etc/GMT+12") ## End(Not run)
Get System Date Time
dtt_sys_date_time(tz = dtt_default_tz())
dtt_sys_date_time(tz = dtt_default_tz())
tz |
A string of the time zone. |
A floored POSIXct scalar.
Other sys:
dtt_sys_date()
,
dtt_sys_time()
## Not run: dtt_set_default_tz("UTC") dtt_sys_date_time() dtt_set_default_tz("Etc/GMT+8") dtt_sys_date_time() dtt_sys_date_time(tz = "UTC") ## End(Not run)
## Not run: dtt_set_default_tz("UTC") dtt_sys_date_time() dtt_set_default_tz("Etc/GMT+8") dtt_sys_date_time() dtt_sys_date_time(tz = "UTC") ## End(Not run)
Get System Time
dtt_sys_time(tz = dtt_default_tz())
dtt_sys_time(tz = dtt_default_tz())
tz |
A string of the time zone. |
A floored hms scalar.
Other sys:
dtt_sys_date()
,
dtt_sys_date_time()
## Not run: dtt_sys_time() ## End(Not run)
## Not run: dtt_sys_time() ## End(Not run)
Get, Set or Reset Default Time Zone
dtt_sys_tz() dtt_set_sys_tz(tz = NULL) dtt_reset_sys_tz() dtt_default_tz() dtt_set_default_tz(tz = NULL) dtt_reset_default_tz()
dtt_sys_tz() dtt_set_sys_tz(tz = NULL) dtt_reset_sys_tz() dtt_default_tz() dtt_set_default_tz(tz = NULL) dtt_reset_default_tz()
tz |
A string of the time zone. |
A string of the current or old time zone.
dtt_set_default_tz()
: Set Default Time Zone
dtt_reset_default_tz()
: Reset Default Time Zone
Other tz:
dtt_adjust_tz()
,
dtt_set_tz()
,
dtt_tz()
## Not run: dtt_default_tz() old <- dtt_set_default_tz("Etc/GMT+8") dtt_default_tz() dtt_reset_default_tz() dtt_default_tz() dtt_set_default_tz(old) dtt_default_tz() ## End(Not run)
## Not run: dtt_default_tz() old <- dtt_set_default_tz("Etc/GMT+8") dtt_default_tz() dtt_reset_default_tz() dtt_default_tz() dtt_set_default_tz(old) dtt_default_tz() ## End(Not run)
Pass vectors of hour, minute and second values to create a time object.
dtt_time_from_ints(hour = 0L, minute = 0L, second = 0L)
dtt_time_from_ints(hour = 0L, minute = 0L, second = 0L)
hour |
An integer of the hour between 0 and 23.The default value is hour zero. |
minute |
An integer of the minute between 0 to 59. The default value is minute zero. |
second |
An integer of the second between 0 to 59. The default value is second zero. |
This can be very helpful when needing to create a time column in a data frame from hour, minute and second columns. Vectors must all be the same length or be of length one.
A floored hms vector.
Other creates:
dtt_date_from_ints()
,
dtt_date_time_from_ints()
dtt_time_from_ints() dtt_time_from_ints( hour = 10, minute = 15, second = 30 ) dtt_time_from_ints( hour = c(10, 11), minute = c(15, 15), second = c(30, 0) ) hour <- c(9, 10, 11) minute <- c(15, 30, 45) second <- 0 dtt_time_from_ints(hour, minute, second)
dtt_time_from_ints() dtt_time_from_ints( hour = 10, minute = 15, second = 30 ) dtt_time_from_ints( hour = c(10, 11), minute = c(15, 15), second = c(30, 0) ) hour <- c(9, 10, 11) minute <- c(15, 30, 45) second <- 0 dtt_time_from_ints(hour, minute, second)
Gets, sets or the time zone for a date time vector.
dtt_tz(x, ...) ## S3 method for class 'POSIXct' dtt_tz(x, ...)
dtt_tz(x, ...) ## S3 method for class 'POSIXct' dtt_tz(x, ...)
x |
A date/time vector. |
... |
Unused. |
A string of the time zone.
dtt_tz(POSIXct)
: Get the time zone for a POSIXct vector.
Other tz:
dtt_adjust_tz()
,
dtt_set_tz()
,
dtt_sys_tz()
dtt_tz(as.POSIXct("1970-01-01", tz = "Etc/GMT+8"))
dtt_tz(as.POSIXct("1970-01-01", tz = "Etc/GMT+8"))
Gets the smallest units for a date time vector. The possible values are 'seconds', 'minutes', 'hours', 'days', 'months' or 'years'.
dtt_units(x, ...) ## S3 method for class 'Date' dtt_units(x, ...) ## S3 method for class 'POSIXct' dtt_units(x, ...) ## S3 method for class 'hms' dtt_units(x, ...)
dtt_units(x, ...) ## S3 method for class 'Date' dtt_units(x, ...) ## S3 method for class 'POSIXct' dtt_units(x, ...) ## S3 method for class 'hms' dtt_units(x, ...)
x |
A Date, POSIXct or hms vector. |
... |
Unused. |
A string indicating the date time units.
dtt_units(Date)
: Get time units for a Date vector
dtt_units(POSIXct)
: Get time units for a POSIXct vector
dtt_units(hms)
: Get time units for a hms vector
Other units:
dtt_adjust_units()
,
dtt_units_per_unit()
dtt_units(as.Date("2000-01-01")) dtt_units(as.Date("2000-02-01")) dtt_units(as.Date("2000-01-02"))
dtt_units(as.Date("2000-01-01")) dtt_units(as.Date("2000-02-01")) dtt_units(as.Date("2000-01-02"))
Units per Unit
dtt_units_per_unit(units = "seconds", unit = "days")
dtt_units_per_unit(units = "seconds", unit = "days")
units |
A string of the time units. The possible values are "secs", "minutes", "hours", "days" or "weeks". |
unit |
A string of the time unit. |
A number of the units per unit
Other units:
dtt_adjust_units()
,
dtt_units()
dtt_units_per_unit("hours")
dtt_units_per_unit("hours")
Gets the week days for the locale.
dtt_wday(x, abbr = FALSE, ...) ## Default S3 method: dtt_wday(x, abbr = FALSE, ...)
dtt_wday(x, abbr = FALSE, ...) ## Default S3 method: dtt_wday(x, abbr = FALSE, ...)
x |
A date/time vector. |
abbr |
A flag specifying whether to abbreviate the week days. |
... |
Unused. |
An character vector of the week days.
dtt_wday(default)
: Get character vector of week days for a Date vector
x <- as.Date("1990-01-02") dtt_wday(x) x <- as.POSIXct("1990-01-02 23:40:51") dtt_wday(x, abbr = TRUE)
x <- as.Date("1990-01-02") dtt_wday(x) x <- as.POSIXct("1990-01-02 23:40:51") dtt_wday(x, abbr = TRUE)
Wrap
dtt_wrap(x, ...)
dtt_wrap(x, ...)
x |
A date/time vector. |
... |
Unused. |
dtt_wrap(hms::as_hms("24:00:00"))
dtt_wrap(hms::as_hms("24:00:00"))
Gets decimal year values for date/time vectors.
dtt_year_decimal(x, ...) ## S3 method for class 'Date' dtt_year_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_year_decimal(x, ...)
dtt_year_decimal(x, ...) ## S3 method for class 'Date' dtt_year_decimal(x, ...) ## S3 method for class 'POSIXct' dtt_year_decimal(x, ...)
x |
A date/time vector. |
... |
Unused. |
A numeric vector.
dtt_year_decimal(Date)
: Get numeric vector of decimal year values for a
Date vector
dtt_year_decimal(POSIXct)
: Get numeric vector of decimal year values for a
POSIXct vector
Other decimal:
dtt_day_decimal()
,
dtt_doy_decimal()
,
dtt_hour_decimal()
,
dtt_minute_decimal()
,
dtt_month_decimal()
x <- as.Date("1990-01-02") dtt_year_decimal(x)
x <- as.Date("1990-01-02") dtt_year_decimal(x)
Gets and sets year values for date/time vectors.
dtt_years(x, ...) dtt_years(x) <- value dtt_set_year(x, value) dtt_year(x, ...) dtt_year(x) <- value ## S3 method for class 'Date' dtt_year(x, ...) ## S3 method for class 'POSIXct' dtt_year(x, ...) ## S3 replacement method for class 'Date' dtt_year(x) <- value ## S3 replacement method for class 'POSIXct' dtt_year(x) <- value
dtt_years(x, ...) dtt_years(x) <- value dtt_set_year(x, value) dtt_year(x, ...) dtt_year(x) <- value ## S3 method for class 'Date' dtt_year(x, ...) ## S3 method for class 'POSIXct' dtt_year(x, ...) ## S3 replacement method for class 'Date' dtt_year(x) <- value ## S3 replacement method for class 'POSIXct' dtt_year(x) <- value
x |
A date/time vector. |
... |
Unused. |
value |
A integer vector of the year value(s). |
An integer vector (or the modified date/time vector).
dtt_year(Date)
: Get integer vector of year values for a Date vector
dtt_year(POSIXct)
: Get integer vector of year values for a POSIXct vector
dtt_year(Date) <- value
: Set year values for a Date vector
dtt_year(POSIXct) <- value
: Set year values for a POSIXct vector
Other set date:
dtt_day()
,
dtt_months()
x <- as.Date("1990-01-02") dtt_year(x) dtt_year(x) <- 11L x x <- as.POSIXct("1990-01-02 23:40:51") dtt_year(x) dtt_year(x) <- 2022L x
x <- as.Date("1990-01-02") dtt_year(x) dtt_year(x) <- 11L x x <- as.POSIXct("1990-01-02 23:40:51") dtt_year(x) dtt_year(x) <- 2022L x
Tests whether an object is a Date, POSIXct, or hms vector.
is.POSIXct(x) is_date_time(x) is.Date(x) is_date(x) is.hms(x) is_time(x)
is.POSIXct(x) is_date_time(x) is.Date(x) is_date(x) is.hms(x) is_time(x)
x |
An object |
A flag indicating whether x inherits from Date, POSIXct or hms.
Other is:
dtt_is_date()
,
dtt_is_date_time()
A missing Date object
NA_Date_
NA_Date_
An object of class Date
of length 1.
A missing hms object
NA_hms_
NA_hms_
An object of class hms
(inherits from difftime
) of length 1.
A missing POSIXct object
NA_POSIXct_
NA_POSIXct_
An object of class POSIXct
(inherits from POSIXt
) of length 1.
Validates that an object is scalar hms::hms object
using
inherits(x, class) && length(x) == 1L && !anyNA(x)
.
vld_time(x)
vld_time(x)
x |
The object to check. |
A flag indicating whether the condition was met.
vld_time(1) vld_time(hms::as_hms("10:12:59"))
vld_time(1) vld_time(hms::as_hms("10:12:59"))