Skip to content

Commit 50d337c

Browse files
authored
Merge pull request #1 from ellisvalentiner/development
v0.1.0
2 parents 5149e44 + b0cb75f commit 50d337c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3075
-10
lines changed

.Rbuildignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
README.Rmd
4+
^docs$
5+
^_pkgdown\.yml$
6+
^codecov\.yml$
7+
^\.travis\.yml$

.gitignore

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
# History files
22
.Rhistory
33
.Rapp.history
4-
54
# Session Data files
65
.RData
7-
86
# Example code in package build process
97
*-Ex.R
10-
118
# Output files from R CMD build
129
/*.tar.gz
13-
1410
# Output files from R CMD check
1511
/*.Rcheck/
16-
1712
# RStudio files
1813
.Rproj.user/
19-
2014
# produced vignettes
2115
vignettes/*.html
2216
vignettes/*.pdf
23-
2417
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
2518
.httr-oauth
26-
2719
# knitr and R markdown default cache directories
2820
/*_cache/
2921
/cache/
30-
3122
# Temporary files created by R markdown
3223
*.utf8.md
3324
*.knit.md
25+
.Rproj.user
26+
# macOS
27+
.DS_Store

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
2+
3+
language: r
4+
sudo: false
5+
cache: packages
6+
latex: false
7+
8+
env:
9+
global:
10+
- _R_CHECK_FORCE_SUGGESTS_=false
11+
- MAKEFLAGS="-j 2"
12+
13+
include:
14+
- r: release
15+
- r: oldrel
16+
- r: devel
17+
18+
before_script:
19+
- mkdir -p ~/.R; echo 'PKG_CXXFLAGS := ${PKG_CXXFLAGS} -Wall -Wextra -pedantic -Werror' > ~/.R/Makevars
20+
21+
after_success:
22+
- Rscript -e 'covr::codecov()'

DESCRIPTION

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Package: lubridateExtras
2+
Type: Package
3+
Title: Convenience functions for the lubridate package
4+
Version: 0.1.0
5+
Authors@R: person("Ellis", "Valentiner", email = "ellis.valentiner@gmail.com",
6+
role = c("aut", "cre"))
7+
Description: Provides extra functionality to lubridate. Largely consisting of
8+
convenience functions.
9+
License: MIT + file LICENSE
10+
Encoding: UTF-8
11+
LazyData: true
12+
Imports:
13+
lubridate (>= 1.6.0)
14+
Remotes:
15+
tidyverse/lubridate
16+
RoxygenNote: 6.0.1

NAMESPACE

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(days_ago)
4+
export(days_hence)
5+
export(is.weekday)
6+
export(is.weekend)
7+
export(last_month)
8+
export(next_month)
9+
export(this_month)
10+
export(tomorrow)
11+
export(yesterday)
12+
import(lubridate)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# lubridateExtras 0.1.0
3+
4+
## 2017-09-24
5+
6+
* Initial release notes

R/imports.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#' @import lubridate
2+
NULL

R/instants.R

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#' The previous day
2+
#'
3+
#' @export yesterday
4+
#' @param tzone a character vector specifying which time zone you would like to
5+
#' find the previous date of. tzone defaults to the system time zone set on your
6+
#' computer.
7+
#' @return the previous date as a Date object
8+
#'
9+
#' @examples
10+
#' yesterday()
11+
#' yesterday("GMT")
12+
yesterday <- function(tzone = "") {
13+
as_date(now(tzone) - days(1))
14+
}
15+
16+
#' The next day
17+
#'
18+
#' @export tomorrow
19+
#' @param tzone a character vector specifying which time zone you would like to
20+
#' find the previous date of. tzone defaults to the system time zone set on your
21+
#' computer.
22+
#' @return the previous date as a Date object
23+
#'
24+
#' @examples
25+
#' tomorrow()
26+
#' tomorrow("GMT")
27+
tomorrow <- function(tzone = "") {
28+
as_date(now(tzone) + days(1))
29+
}
30+
31+
#' The date x days ago
32+
#'
33+
#' @export days_ago
34+
#' @param days an integer specifying the number of days to subtract from the current
35+
#' @param tzone a character vector specifying which time zone you would like to
36+
#' find the previous date of. tzone defaults to the system time zone set on your
37+
#' computer.
38+
#' @return the date, x days ago
39+
#'
40+
#' @examples
41+
#' days_ago(3)
42+
#' days_ago(1) == yesterday()
43+
days_ago <- function(days = 0, tzone = "") {
44+
as_date(today(tzone = tzone) - days(x = days))
45+
}
46+
47+
#' The date x days hence
48+
#'
49+
#' @export days_hence
50+
#' @param days an integer specifying the number of days to add from the current
51+
#' @param tzone a character vector specifying which time zone you would like to
52+
#' find the previous date of. tzone defaults to the system time zone set on your
53+
#' computer.
54+
#' @return the date, x days hence
55+
#'
56+
#' @examples
57+
#' days_hence(3)
58+
#' days_hence(1) == tomorrow()
59+
days_hence <- function(days = 0, tzone = "") {
60+
as_date(today(tzone = tzone) + days(x = days))
61+
}
62+
63+
#' The current month
64+
#'
65+
#' @export this_month
66+
#' @param tzone a character vector specifying which time zone you would like to
67+
#' find the current month of. tzone defaults to the system time zone set on your
68+
#' computer.
69+
#' @return the current month as a Date object
70+
this_month <- function(tzone = "") {
71+
floor_date(x = today(tzone = tzone), unit = "month")
72+
}
73+
74+
#' The previous month
75+
#'
76+
#' @export last_month
77+
#' @param tzone a character vector specifying which time zone you would like to
78+
#' find the previous month of. tzone defaults to the system time zone set on your
79+
#' computer.
80+
#' @return the previous month as a Date object
81+
last_month <- function(tzone = "") {
82+
floor_date(x = today(tzone = tzone), unit = "month") - months(1)
83+
}
84+
85+
#' The next month
86+
#'
87+
#' @export next_month
88+
#' @param tzone a character vector specifying which time zone you would like to
89+
#' find the next month of. tzone defaults to the system time zone set on your
90+
#' computer.
91+
#' @return the next month as a Date object
92+
next_month <- function(tzone = "") {
93+
floor_date(x = today(tzone = tzone), unit = "month") + months(1)
94+
}
95+
96+
#' Is x a weekend?
97+
#'
98+
#' @export is.weekend
99+
#' @param x a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg,
100+
#' timeDate, xts, its, ti, jul, timeSeries, or fts object.
101+
#' @return boolean indicating whether x is a weekend
102+
#'
103+
#' @examples
104+
#' is.weekend("2017-08-29") # FALSE
105+
#' is.weekend("2017-09-02") # TRUE
106+
is.weekend <- function(x) {
107+
wday(x = as_date(x), label = FALSE, abbr = FALSE) %in% c(1, 7)
108+
}
109+
110+
#' Is x a weekday?
111+
#'
112+
#' @export is.weekday
113+
#' @param x a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg,
114+
#' timeDate, xts, its, ti, jul, timeSeries, or fts object.
115+
#' @return boolean indicating whether x is a weekday
116+
#'
117+
#' @examples
118+
#' is.weekend("2017-08-29") # FALSE
119+
#' is.weekend("2017-09-02") # TRUE
120+
is.weekday <- function(x) {
121+
wday(x = as_date(x), label = FALSE, abbr = FALSE) %in% 2:6
122+
}

README.Rmd

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
output:
3+
github_document:
4+
html_preview: false
5+
---
6+
7+
<!-- README.md is generated from README.Rmd. Please edit that file -->
8+
9+
```{r, echo = FALSE}
10+
knitr::opts_chunk$set(
11+
collapse = TRUE,
12+
comment = "#>",
13+
fig.path = "README-"
14+
)
15+
options(tibble.print_min = 5, tibble.print_max = 5)
16+
```
17+
18+
# lubridateExtras <img src="man/figures/logo.svg" align="right" height="120" width="139" />
19+
20+
Convenience functions for the lubridate package
21+
22+
<!-- Placeholder for build status, CRAN status, and coverage status -->
23+
24+
## Overview
25+
26+
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.
27+
28+
## Installation
29+
30+
```{r, eval = FALSE}
31+
# lubridateExtras is not currently on CRAN
32+
# Please install the development version from GitHub:
33+
# install.packages("devtools")
34+
devtools::install_github("ellisvalentiner/lubridateExtras")
35+
```
36+
37+
If you encounter a clear bug, please file a minimal reproducible example on [github](https://github.com/ellisvalentiner/lubridateExtras/issues).
38+
39+
## Usage
40+
41+
```{r}
42+
library(lubridateExtras)
43+
44+
yesterday()
45+
46+
tomorrow()
47+
48+
days_ago(7) # equivalent to lubridate::today() - lubridate::days(7)
49+
50+
days_hence(7) # equivalent to lubridate::today() + lubridate::days(7)
51+
```
52+
53+
## Why lubridateExtras?
54+
55+
Some people are probably asking the question: why lubridateExtras?
56+
57+
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.

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,50 @@
1-
# lubridateExtras
1+
2+
<!-- README.md is generated from README.Rmd. Please edit that file -->
3+
lubridateExtras <img src="man/figures/logo.svg" align="right" height="120" width="139" />
4+
=========================================================================================
5+
6+
Convenience functions for the lubridate package
7+
8+
<!-- Placeholder for build status, CRAN status, and coverage status -->
9+
Overview
10+
--------
11+
12+
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.
13+
14+
Installation
15+
------------
16+
17+
``` r
18+
# lubridateExtras is not currently on CRAN
19+
# Please install the development version from GitHub:
20+
# install.packages("devtools")
21+
devtools::install_github("ellisvalentiner/lubridateExtras")
22+
```
23+
24+
If you encounter a clear bug, please file a minimal reproducible example on [github](https://github.com/ellisvalentiner/lubridateExtras/issues).
25+
26+
Usage
27+
-----
28+
29+
``` r
30+
library(lubridateExtras)
31+
32+
yesterday()
33+
#> [1] "2017-09-23"
34+
35+
tomorrow()
36+
#> [1] "2017-09-25"
37+
38+
days_ago(7) # equivalent to lubridate::today() - lubridate::days(7)
39+
#> [1] "2017-09-17"
40+
41+
days_hence(7) # equivalent to lubridate::today() + lubridate::days(7)
42+
#> [1] "2017-10-01"
43+
```
44+
45+
Why lubridateExtras?
46+
--------------------
47+
48+
Some people are probably asking the question: why lubridateExtras?
49+
50+
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.

_pkgdown.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
url: https://ellisvalentiner.github.com/lubridateExtras
2+
3+
template:
4+
params:
5+
bootswatch: lumen
6+
7+
home:
8+
strip_header: true
9+
10+
navbar:
11+
type: default
12+
left:
13+
- text: Intro
14+
href: articles/intro.html
15+
- text: Reference
16+
href: reference/index.html
17+
- text: News
18+
href: news/index.html
19+
right:
20+
- icon: fa-github fa-lg
21+
href: https://github.com/ellisvalentiner/lubridateExtras

codecov.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
comment: false
2+
3+
coverage:
4+
status:
5+
patch:
6+
default:
7+
target: 0
8+
threshold: 100
9+
project:
10+
default:
11+
target: 70
12+
threshold: 100

0 commit comments

Comments
 (0)