Skip to content

Commit

Permalink
v0.1.2 (#11)
Browse files Browse the repository at this point in the history
* Add lint tests

* Add functions for `this_week`, `last_week`, and `next_week`
  • Loading branch information
ellisvalentiner authored May 6, 2018
1 parent fcccb21 commit 33c67bb
Show file tree
Hide file tree
Showing 27 changed files with 266 additions and 184 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cache: packages
latex: false
r_packages:
- covr
r_github_packages:
- jimhester/lintr

env:
global:
Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ Imports:
hms (>= 0.3)
Suggests:
knitr (>= 1.17),
lintr (>= 1.0.1.9000),
testthat (>= 1.0.2)
Remotes:
tidyverse/lubridate,
tidyverse/hms,
yihui/knitr,
jimhester/lintr,
tidyverse/lubridate,
r-lib/testthat
VignetteBuilder: knitr
RoxygenNote: 6.0.1
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ export(hms)
export(is.weekday)
export(is.weekend)
export(last_month)
export(last_week)
export(next_month)
export(next_week)
export(this_month)
export(this_week)
export(tomorrow)
export(yesterday)
import(lubridate)
66 changes: 52 additions & 14 deletions R/instants.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#'
#' @export yesterday
#' @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.
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#' @return the previous date as a Date object
#'
#' @seealso \code{\link{tomorrow}}
#'
#' @examples
#' yesterday()
#' yesterday("UTC")
Expand All @@ -17,10 +19,12 @@ yesterday <- function(tzone = "") {
#'
#' @export tomorrow
#' @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.
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#' @return the previous date as a Date object
#'
#' @seealso \code{\link{yesterday}}
#'
#' @examples
#' tomorrow()
#' tomorrow("UTC")
Expand All @@ -31,10 +35,11 @@ tomorrow <- function(tzone = "") {
#' The date x days ago
#'
#' @export days_ago
#' @param days an integer specifying the number of days to subtract from the current
#' @param days 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.
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#' @return the date, x days ago
#'
#' @examples
Expand All @@ -49,8 +54,8 @@ days_ago <- function(days = 0, tzone = "") {
#' @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.
#' find the previous date of. tzone defaults to the system time zone set on
#' your computer.
#' @return the date, x days hence
#'
#' @examples
Expand All @@ -64,8 +69,8 @@ days_hence <- function(days = 0, tzone = "") {
#'
#' @export this_month
#' @param tzone a character vector specifying which time zone you would like to
#' find the current month of. tzone defaults to the system time zone set on your
#' computer.
#' find the current month of. tzone defaults to the system time zone set on
#' your computer.
#' @return the current month as a Date object
this_month <- function(tzone = "") {
floor_date(x = today(tzone = tzone), unit = "month")
Expand All @@ -75,8 +80,8 @@ this_month <- function(tzone = "") {
#'
#' @export last_month
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous month of. tzone defaults to the system time zone set on your
#' computer.
#' find the previous month of. tzone defaults to the system time zone set on
#' your computer.
#' @return the previous month as a Date object
last_month <- function(tzone = "") {
floor_date(x = today(tzone = tzone), unit = "month") - months(1)
Expand All @@ -93,6 +98,39 @@ next_month <- function(tzone = "") {
floor_date(x = today(tzone = tzone), unit = "month") + months(1)
}

#' The current week
#'
#' @export this_week
#' @param tzone a character vector specifying which time zone you would like to
#' find the current week of. tzone defaults to the system time zone set on
#' your computer.
#' @return the current week as a Date object
this_week <- function(tzone = "") {
floor_date(x = today(tzone = tzone), unit = "week")
}

#' The previous week
#'
#' @export last_week
#' @param tzone a character vector specifying which time zone you would like to
#' find the previous week of. tzone defaults to the system time zone set on
#' your computer.
#' @return the previous week as a Date object
last_week <- function(tzone = "") {
floor_date(x = today(tzone = tzone), unit = "week") - weeks(1)
}

#' The next week
#'
#' @export next_week
#' @param tzone a character vector specifying which time zone you would like to
#' find the next week of. tzone defaults to the system time zone set on your
#' computer.
#' @return the next month as a Date object
next_week <- function(tzone = "") {
floor_date(x = today(tzone = tzone), unit = "week") + weeks(1)
}

#' Is x a weekend?
#'
#' @export is.weekend
Expand Down Expand Up @@ -130,5 +168,5 @@ is.weekday <- function(x) {
#' @examples
#' hms("2017-10-22 15:01:00")
hms <- function(x) {
hms::as.hms(strftime(x, format="%H:%M:%S"))
hms::as.hms(strftime(x, format = "%H:%M:%S"))
}
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->
lubridateExtras <img src="man/figures/logo.svg" align="right" height="120" width="139" />
=========================================================================================

# lubridateExtras <img src="man/figures/logo.svg" align="right" height="120" width="139" />

Convenience functions for the lubridate package

<!-- Placeholder for build status, CRAN status, and coverage status -->
Overview
--------

Lubridate makes it easier to work with date-time data in R and provides new capabilities. LubridateExtras builds on top of lubridate to provide a number of convenience functions, primarily focused on abstracting patterns in ways that improve code readability and reduce copying and pasting code.
## Overview

Lubridate makes it easier to work with date-time data in R and provides
new capabilities. LubridateExtras builds on top of lubridate to provide
a number of convenience functions, primarily focused on abstracting
patterns in ways that improve code readability and reduce copying and
pasting code.

Installation
------------
## Installation

``` r
# lubridateExtras is not currently on CRAN
Expand All @@ -21,33 +24,35 @@ Installation
devtools::install_github("ellisvalentiner/lubridateExtras")
```

If you encounter a clear bug, please file a minimal reproducible example on [github](https://github.com/ellisvalentiner/lubridateExtras/issues).
If you encounter a clear bug, please file a minimal reproducible example
on [github](https://github.com/ellisvalentiner/lubridateExtras/issues).

Usage
-----
## Usage

``` r
library(lubridateExtras)

yesterday()
#> [1] "2017-10-21"
#> [1] "2018-02-20"

tomorrow()
#> [1] "2017-10-23"
#> [1] "2018-02-22"

days_ago(7) # equivalent to lubridate::today() - lubridate::days(7)
#> [1] "2017-10-15"
#> [1] "2018-02-14"

days_hence(7) # equivalent to lubridate::today() + lubridate::days(7)
#> [1] "2017-10-29"
#> [1] "2018-02-28"

hms("2017-10-22 15:33:00") # extracts the time-of-day component
#> 15:33:00
```

Why lubridateExtras?
--------------------
## Why lubridateExtras?

Some people are probably asking the question: why lubridateExtras?

lubridateExtras does not do anything that you cannot do with lubridate but similarly you don't need lubridate at all to work with date/times in R! If you like the syntactic sugar of lubridateExtras then use it, otherwise stick with what works for you.
lubridateExtras does not do anything that you cannot do with lubridate
but similarly you don’t need lubridate at all to work with date/times in
R\! If you like the syntactic sugar of lubridateExtras then use it,
otherwise stick with what works for you.
6 changes: 6 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ navbar:
right:
- icon: fa-github fa-lg
href: https://github.com/ellisvalentiner/lubridateExtras

reference:
- title: similar functions
contents:
- yesterday
- tomorrow
14 changes: 6 additions & 8 deletions docs/articles/intro.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 26 additions & 39 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 33c67bb

Please sign in to comment.