Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 186 additions & 1 deletion R/instants.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,51 @@ tomorrow <- function(tzone = "") {
as_date(now(tzone = tzone) + days(1))
}

#' The time x seconds before now
#'
#' @param seconds integer number of seconds
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return The datetime, x seconds ago
#' @export seconds_ago
#'
#' @examples
seconds_ago <- function(seconds = 0, tzone = "") {
as_datetime(now() - seconds(x = seconds), tz = tzone)
}

#' The time x minutes before now
#'
#' @param minutes integer number of minutes
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return
#' @export minutes_ago
#'
#' @examples
minutes_ago <- function(minutes = 0, tzone = "") {
as_datetime(now() - minutes(x = minutes), tz = tzone)
}

#' the time x hours ago
#'
#' @param hours integer number of hours
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return
#' @export hours_ago
#'
#' @examples
hours_ago <- function(hours = 0, tzone = "") {
as_datetime(now() - hours(x = hours), tz = tzone)
}

#' The date x days ago
#'
#' @export days_ago
Expand All @@ -49,14 +94,106 @@ days_ago <- function(days = 0, tzone = "") {
as_date(today(tzone = tzone) - days(x = days))
}

#' The date x weeks ago
#'
#' @param weeks an integer specifying the number of weeks to subtract from the
#' current
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return the date, x weeks ago
#' @export weeks_ago
#'
#' @examples
weeks_ago <- function(weeks = 0, tzone = "") {
as_date(today(tzone = tzone) - weeks(x = weeks))
}


#' The date x months ago
#'
#' @param months an integer specifying th enumber of weeks to subtract from the current
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return the date, x months ago
#' @export months_ago
#'
#' @examples
months_ago <- function(months = 0, tzone = "") {
as_date(today(tzone = tzone) - months(x = months))
}

#' The date x years ago
#'
#' @param years an integer specifying the number of days to subtract from the
#' current
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return The date, x years ago
#' @export years_ago
#'
#' @examples
years_ago <- function(years = 0, tzone = "") {
as_date(today(tzone = tzone) - years(x = years))
}

#' The time x seconds before now
#'
#' @param seconds integer number of seconds
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return The datetime, x seconds from now
#' @export seconds_hence
#'
#' @examples
seconds_hence <- function(seconds = 0, tzone = "") {
as_datetime(now() + seconds(x = seconds), tz = tzone)
}

#' The time x minutes before now
#'
#' @param minutes integer number of minutes
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return The date time, x minutes from now
#' @export minutes_hence
#'
#' @examples
minutes_hence <- function(minutes = 0, tzone = "") {
as_datetime(now() + minutes(x = minutes), tz = tzone)
}

#' the time x hours hence
#'
#' @param hours integer number of hours
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return The datetime, x hours from now
#' @export hours_hence
#'
#' @examples
hours_hence <- function(hours = 0, tzone = "") {
as_datetime(now() + hours(x = hours), tz = tzone)
}
#' The date x days hence
#'
#' @export days_hence
#' @param days an integer specifying the number of days to add from the current
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#' @return the date, x days hence
#' @return the datetime, x days from now
#'
#' @examples
#' days_hence(3)
Expand All @@ -76,6 +213,54 @@ this_month <- function(tzone = "") {
floor_date(x = today(tzone = tzone), unit = "month")
}

#' The date x weeks hence
#'
#' @param weeks an integer specifying the number of weeks to add to the
#' current
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return the date, x weeks from now
#' @export weeks_hence
#'
#' @examples
weeks_hence <- function(weeks = 0, tzone = "") {
as_date(today(tzone = tzone) + weeks(x = weeks))
}


#' The date x months hence
#'
#' @param months an integer specifying the number of weeks to add to the current
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return the date, x months from now
#' @export months_hence
#'
#' @examples
months_hence <- function(months = 0, tzone = "") {
as_date(today(tzone = tzone) + months(x = months))
}

#' The date x years hence
#'
#' @param years an integer specifying the number of days to add to the
#' current
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#'
#' @return The date, x years form now
#' @export years_hence
#'
#' @examples
years_hence <- function(years = 0, tzone = "") {
as_date(today(tzone = tzone) + years(x = years))
}

#' The previous month
#'
#' @export last_month
Expand Down