Skip to content

Commit a7379fc

Browse files
committed
cranked up test coverage and found a few missing exports
1 parent 42af4fa commit a7379fc

17 files changed

+225
-37
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type: Package
22
Package: dint
33
Title: A Toolkit for Year-Quarter, Year-Month and Year-Isoweek
44
Dates
5-
Version: 2.0.0.9004
5+
Version: 2.0.0.9005
66
Authors@R:
77
person(given = "Stefan",
88
family = "Fleck",

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ S3method(unique,date_yw)
116116
S3method(xtfrm,date_xx)
117117
export("%y+%")
118118
export("%y-%")
119+
export(Sys.date_ym)
120+
export(Sys.date_yq)
121+
export(Sys.date_yw)
119122
export(as_date_y)
120123
export(as_date_ym)
121124
export(as_date_yq)
@@ -157,6 +160,7 @@ export(get_month)
157160
export(get_quarter)
158161
export(get_year)
159162
export(is_Date)
163+
export(is_POSIXlt)
160164
export(is_date_xx)
161165
export(is_date_y)
162166
export(is_date_ym)

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dint 2.0.0.9000
22

3-
* added *ggplot2* scales for dint data types
3+
* added **ggplot2** scales for dint data types
44
* added predicates to check wether dates correspond to the boundaries of
55
years or quarters (`is_quarter_bounds()`, `is_year_bounds()`,
66
`is_first_of_quarter()`, etc...)
@@ -10,6 +10,8 @@
1010
(the result is an `integer`)
1111
* added `as_yearmon()` and `as_yearqtr()` for converting to *zoo* S3 classes
1212
* Removed functions that were deprecated with dint 2.0.0
13+
* added `Sys.date_yq()`, `Sys.date_ym()` and `Sys.date_yw()` to get the current
14+
quarter, month or isoweek.
1315
* lots of small fixes
1416

1517

R/date_xx.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,20 @@ as.POSIXct.date_xx <- function(x, tz = "", ...){
150150

151151

152152

153-
153+
#' @rdname as.Date.date_xx
154+
#' @export
154155
Sys.date_yq <- function() as_date_yq(Sys.Date())
155156

156157

157158

158-
159+
#' @rdname as.Date.date_xx
160+
#' @export
159161
Sys.date_ym <- function() as_date_ym(Sys.Date())
160162

161163

162164

163-
165+
#' @rdname as.Date.date_xx
166+
#' @export
164167
Sys.date_yw <- function() as_date_yw(Sys.Date())
165168

166169

R/predicates.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ is_last_of_quarter <- function(
5151

5252

5353

54+
5455
#' @export
5556
#' @rdname period_bounds
5657
is_year_bounds <- function(
@@ -62,15 +63,17 @@ is_year_bounds <- function(
6263

6364

6465

66+
6567
#' @export
6668
#' @rdname period_bounds
67-
6869
is_first_of_year <- function(x){
6970
r <- as.POSIXlt(x, tz = tz(x))
7071
r$mon == 0L & r$mday == 1L
7172
}
7273

7374

75+
76+
7477
#' @export
7578
#' @rdname period_bounds
7679
is_last_of_year <- function(x){
@@ -80,6 +83,7 @@ is_last_of_year <- function(x){
8083

8184

8285

86+
8387
#' @export
8488
#' @rdname period_bounds
8589
is_Date <- function(
@@ -91,10 +95,15 @@ is_Date <- function(
9195

9296

9397

98+
#' @export
99+
#' @rdname period_bounds
94100
is_POSIXlt <- function(x){
95101
inherits(x, "POSIXlt")
96102
}
97103

104+
105+
106+
98107
# utils -------------------------------------------------------------------
99108

100109
as_md_integer <- function(

R/utils.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ make_date <- function(y, m, d){
1616
if (requireNamespace("lubridate", quietly = TRUE)){
1717
lubridate::make_date(y, m, d)
1818
} else {
19-
as.Date(ISOdate(y, m, d))
19+
as.Date(ISOdate(y, m, d)) # nocov
2020
}
2121
}
2222

@@ -29,8 +29,7 @@ substr_right <- function(x, n){
2929
}
3030

3131

32-
33-
32+
# nocov start
3433
dyn_register_s3_method <- function(
3534
pkg,
3635
generic,
@@ -61,7 +60,7 @@ dyn_register_s3_method <- function(
6160
}
6261
)
6362
}
64-
63+
# nocov end
6564

6665

6766

man/as.Date.date_xx.Rd

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/period_bounds.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scale_date_xx.Rd

Lines changed: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_accessors.R

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test_that("get_* returns integers", {
55
d <- Sys.Date()
66
ym <- date_ym(2018, 1)
77
yq <- date_yq(2018, 1)
8-
8+
y <- date_y(2018)
99

1010
expect_true(is.integer(get_month(d)))
1111
expect_true(is.integer(get_month(ym)))
@@ -19,4 +19,18 @@ test_that("get_* returns integers", {
1919
expect_true(is.integer(get_year(ym)))
2020
expect_true(is.integer(get_year(yq)))
2121

22+
expect_error(get_month(y))
23+
expect_error(get_quarter(y))
24+
})
25+
26+
27+
28+
test_that("lubridate accessors work", {
29+
if (!requireNamespace("lubridate", quietly = TRUE)){
30+
skip("test requires lubridate")
31+
}
32+
ym <- date_ym(2018, 1)
33+
expect_identical(lubridate::year(ym), get_year(ym))
34+
expect_identical(lubridate::month(ym), get_month(ym))
35+
expect_identical(lubridate::quarter(ym), get_quarter(ym))
2236
})

0 commit comments

Comments
 (0)