From dfe9f93e44ef92b15ca40225dd4bbc053eee04f8 Mon Sep 17 00:00:00 2001 From: Ellis Valentiner Date: Wed, 27 Sep 2017 11:39:06 -0400 Subject: [PATCH 1/9] Trigger build From 2b1e844eb847bedacb0385e86df5e323d2f34fc0 Mon Sep 17 00:00:00 2001 From: Ellis Valentiner Date: Wed, 27 Sep 2017 12:49:21 -0400 Subject: [PATCH 2/9] Fix R CMD build warning --- .Rbuildignore | 1 + README.md | 8 ++++---- docs/articles/intro.html | 7 ++----- docs/index.html | 8 ++++---- docs/reference/days_ago.html | 2 +- docs/reference/days_hence.html | 2 +- docs/reference/tomorrow.html | 2 +- docs/reference/yesterday.html | 2 +- vignettes/intro.Rmd | 9 ++++++--- 9 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 8de87b9..978c1b5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,3 +5,4 @@ README.Rmd ^_pkgdown\.yml$ ^codecov\.yml$ ^\.travis\.yml$ +^vignettes/* diff --git a/README.md b/README.md index e4f9fc4..8f22d77 100644 --- a/README.md +++ b/README.md @@ -30,16 +30,16 @@ Usage library(lubridateExtras) yesterday() -#> [1] "2017-09-23" +#> [1] "2017-09-26" tomorrow() -#> [1] "2017-09-25" +#> [1] "2017-09-28" days_ago(7) # equivalent to lubridate::today() - lubridate::days(7) -#> [1] "2017-09-17" +#> [1] "2017-09-20" days_hence(7) # equivalent to lubridate::today() + lubridate::days(7) -#> [1] "2017-10-01" +#> [1] "2017-10-04" ``` Why lubridateExtras? diff --git a/docs/articles/intro.html b/docs/articles/intro.html index 6052a03..03d4632 100644 --- a/docs/articles/intro.html +++ b/docs/articles/intro.html @@ -64,9 +64,6 @@

Introduction to lubridateExtras

-
suppressPackageStartupMessages(library(dplyr))
-suppressPackageStartupMessages(library(lubridate))
-library(lubridateExtras)

lubridateExtras provides functions to improve code readability and increase laziness.

@@ -74,11 +71,11 @@

Suppose you want to review transactions from the past 7 days.

Without lubridateExtras, this might look like this:

transactions %>%
-  filter(date >= today() - days(7))
+ filter(date >= today() - days(7))

Even in this straightforward example it can be difficult to remember: does the >= operator evaluate before or after the - operator?

lubridateExtra aims to remove this sort of ambiguity and make the intent clearer through convenience functions. With lubridateExtras, we could rewrite this as follows:

transactions %>%
-  filter(date >= days_ago(7))
+ filter(date >= days_ago(7))

This accomplishes the exact same thing.

diff --git a/docs/index.html b/docs/index.html index 217f602..7312cab 100644 --- a/docs/index.html +++ b/docs/index.html @@ -86,16 +86,16 @@

library(lubridateExtras)
 
 yesterday()
-#> [1] "2017-09-23"
+#> [1] "2017-09-26"
 
 tomorrow()
-#> [1] "2017-09-25"
+#> [1] "2017-09-28"
 
 days_ago(7)  # equivalent to lubridate::today() - lubridate::days(7)
-#> [1] "2017-09-17"
+#> [1] "2017-09-20"
 
 days_hence(7)  # equivalent to lubridate::today() + lubridate::days(7)
-#> [1] "2017-10-01"
+#> [1] "2017-10-04"

diff --git a/docs/reference/days_ago.html b/docs/reference/days_ago.html index d3fce2a..191e14c 100644 --- a/docs/reference/days_ago.html +++ b/docs/reference/days_ago.html @@ -110,7 +110,7 @@

Value

Examples

-
days_ago(3)
#> [1] "2017-09-21"
days_ago(1) == yesterday()
#> [1] TRUE
+
days_ago(3)
#> [1] "2017-09-24"
days_ago(1) == yesterday()
#> [1] TRUE

diff --git a/docs/reference/days_ago.html b/docs/reference/days_ago.html index 191e14c..41f385e 100644 --- a/docs/reference/days_ago.html +++ b/docs/reference/days_ago.html @@ -110,7 +110,7 @@

Value

Examples

-
days_ago(3)
#> [1] "2017-09-24"
days_ago(1) == yesterday()
#> [1] TRUE
+
days_ago(3)
#> [1] "2017-09-25"
days_ago(1) == yesterday()
#> [1] TRUE

diff --git a/docs/reference/hms.html b/docs/reference/hms.html index 3517485..7024180 100644 --- a/docs/reference/hms.html +++ b/docs/reference/hms.html @@ -6,7 +6,7 @@ -Extract HMS — hms • lubridateExtras +Extract time-of-day values — hms • lubridateExtras @@ -80,11 +80,11 @@
-

Extract HMS

+

Extract time-of-day values

hms(x)
@@ -101,7 +101,7 @@

Ar

Value

-

the hms component

+

hms object

Examples

diff --git a/docs/reference/index.html b/docs/reference/index.html index cd1248d..09960f1 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -118,7 +118,7 @@

hms

-

Extract HMS

+

Extract time-of-day values

diff --git a/man/hms.Rd b/man/hms.Rd new file mode 100644 index 0000000..9e1d630 --- /dev/null +++ b/man/hms.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/instants.R +\name{hms} +\alias{hms} +\title{Extract time-of-day values} +\usage{ +hms(x) +} +\arguments{ +\item{x}{a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, +timeDate, xts, its, ti, jul, timeSeries, or fts object.} +} +\value{ +hms object +} +\description{ +Extract time-of-day values +} +\examples{ +hms("2017-10-22 15:01:00") +} From b554c366d2cfe7f089fa7aea179c0970ae294215 Mon Sep 17 00:00:00 2001 From: Ellis Valentiner Date: Sun, 22 Oct 2017 16:07:39 -0400 Subject: [PATCH 7/9] Add tests --- DESCRIPTION | 1 + tests/testthat.R | 4 +++ tests/testthat/test_instances.R | 54 +++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test_instances.R diff --git a/DESCRIPTION b/DESCRIPTION index 521e1d5..74bb631 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,3 +18,4 @@ Remotes: tidyverse/lubridate, tidyverse/hms RoxygenNote: 6.0.1 +Suggests: testthat diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..5e0ffcd --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(lubridateExtras) + +test_check("lubridateExtras") diff --git a/tests/testthat/test_instances.R b/tests/testthat/test_instances.R new file mode 100644 index 0000000..a67e12a --- /dev/null +++ b/tests/testthat/test_instances.R @@ -0,0 +1,54 @@ +library(lubridateExtras) +context("Instances") +Sys.setenv(TZ = "America/New_York") + +test_that("yesterday", { + expect_equal(yesterday(), Sys.Date()-1) +}) + +test_that("tomorrow", { + expect_equal(tomorrow(), Sys.Date()+1) +}) + +test_that("days_ago", { + expect_equal(days_ago(0), Sys.Date()) + expect_equal(days_ago(1), yesterday()) + expect_equal(days_ago(2), Sys.Date()-2) + expect_equal(days_ago(7), Sys.Date()-7) + expect_equal(days_ago(-1), tomorrow()) +}) + +test_that("days_hence", { + expect_equal(days_hence(0), Sys.Date()) + expect_equal(days_hence(1), tomorrow()) + expect_equal(days_hence(2), Sys.Date()+2) + expect_equal(days_hence(7), Sys.Date()+7) + expect_equal(days_hence(-1), yesterday()) +}) + +test_that("this_month", { + expect_equal(this_month(), as.Date(strftime(Sys.Date(), format = "%Y-%m-01"))) +}) + +test_that("last_month", { + expect_equal(last_month(), this_month()-months(1)) +}) + +test_that("next_month", { + expect_equal(next_month(), this_month()+months(1)) +}) + +test_that("is.weekday", { + expect_equal(is.weekday("2017-10-23"), TRUE) + expect_equal(is.weekday("2017-10-22"), FALSE) +}) + +test_that("is.weekend", { + expect_equal(is.weekend("2017-10-23"), FALSE) + expect_equal(is.weekend("2017-10-22"), TRUE) +}) + +test_that("hms", { + expect_equal(hms("2017-10-22 15:01:00"), hms::hms(seconds = 0, minutes = 1, hours = 15)) + expect_equal(hms("2017-10-22 16:06:59"), hms::hms(seconds = 59, minutes = 6, hours = 16)) +}) From c7067f3a3113a081a5f6a506142b56277152d4a5 Mon Sep 17 00:00:00 2001 From: Ellis Valentiner Date: Sun, 22 Oct 2017 17:19:58 -0400 Subject: [PATCH 8/9] Make checks pass --- DESCRIPTION | 12 ++++++++---- docs/articles/index.html | 2 +- docs/articles/intro.html | 1 - docs/index.html | 2 +- docs/reference/index.html | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1879c58..7b92fba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: lubridateExtras Type: Package -Title: Convenience functions for the lubridate package -Version: 0.1.0 +Title: Convenience Functions for Manipulating Datetimes +Version: 0.1.1 Authors@R: c( person("Ellis", "Valentiner", email = "ellis.valentiner@gmail.com", role = c("aut", "cre")), person("Geoffrey", "Hannigan", email = "hanni035@umn.edu", role = c("ctb"))) @@ -15,9 +15,13 @@ Depends: Imports: lubridate (>= 1.6.0), hms (>= 0.3) +Suggests: + knitr (>= 1.17), + testthat (>= 1.0.2) Remotes: tidyverse/lubridate, - tidyverse/hms + tidyverse/hms, + yihui/knitr, + lib/testthat VignetteBuilder: knitr RoxygenNote: 6.0.1 -Suggests: testthat diff --git a/docs/articles/index.html b/docs/articles/index.html index e5bc482..dfaffd1 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@
diff --git a/docs/articles/intro.html b/docs/articles/intro.html index 6b5b01d..eb132e3 100644 --- a/docs/articles/intro.html +++ b/docs/articles/intro.html @@ -69,7 +69,6 @@

Introduction to lubridateExtras

## The following object is masked from 'package:lubridate':
 ## 
 ##     hms
-

lubridateExtras provides functions to improve code readability and increase laziness.

Example

diff --git a/docs/index.html b/docs/index.html index 7394295..936ada8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ -Convenience functions for the lubridate package • lubridateExtras +Convenience Functions for Manipulating Datetimes • lubridateExtras diff --git a/docs/reference/index.html b/docs/reference/index.html index 09960f1..0d90592 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -82,7 +82,7 @@ From 925f9af69d101786612183075d05799521d33c2f Mon Sep 17 00:00:00 2001 From: Ellis Valentiner Date: Mon, 23 Oct 2017 10:27:10 -0400 Subject: [PATCH 9/9] Remove Set timezone in tests (causes fail on Windows) Fix remote for testthat --- DESCRIPTION | 2 +- tests/testthat/test_instances.R | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7b92fba..e057049 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,6 @@ Remotes: tidyverse/lubridate, tidyverse/hms, yihui/knitr, - lib/testthat + r-lib/testthat VignetteBuilder: knitr RoxygenNote: 6.0.1 diff --git a/tests/testthat/test_instances.R b/tests/testthat/test_instances.R index a67e12a..5ad5b2f 100644 --- a/tests/testthat/test_instances.R +++ b/tests/testthat/test_instances.R @@ -1,6 +1,5 @@ library(lubridateExtras) context("Instances") -Sys.setenv(TZ = "America/New_York") test_that("yesterday", { expect_equal(yesterday(), Sys.Date()-1)