From 5bce1613b867cd8029a2a434c23304c5ad8916a1 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Tue, 3 Oct 2017 22:54:41 +0200 Subject: [PATCH] [Fix #543] Make `wday` work on character inputs --- NEWS.md | 1 + R/accessors-day.r | 1 + tests/testthat/test-accessors.R | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4aa758f4..6c06a6f8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -25,6 +25,7 @@ Version 1.6.0.9000 ### BUG FIXES +* [#543](https://github.com/tidyverse/lubridate/issues/543) Make `wday` work on character inputs as it is the case with all other day accessors. * [#566](https://github.com/tidyverse/lubridate/issues/566) Comparing durations and periods no-longer infloops. * [#556](https://github.com/tidyverse/lubridate/issues/556) Fix incorrect scoring of `y` format when it's the last in format order (as in `mdy`). * [#559](https://github.com/tidyverse/lubridate/issues/559) Parsing of alpha-months in English locales now drops correctly to low level C parsing. Thus, parsing with multiple orders containing `m` and `b` formats now works correctly. diff --git a/R/accessors-day.r b/R/accessors-day.r index 6c9776cc..253aac47 100644 --- a/R/accessors-day.r +++ b/R/accessors-day.r @@ -105,6 +105,7 @@ qday <- function(x) #' @export qday.default <- function(x) { + x <- as_date(x) as.integer(x - floor_date(x, "quarter")) + 1 } diff --git a/tests/testthat/test-accessors.R b/tests/testthat/test-accessors.R index 9d130313..fed5c68e 100644 --- a/tests/testthat/test-accessors.R +++ b/tests/testthat/test-accessors.R @@ -66,6 +66,15 @@ test_that("empty argument date() works", { expect_silent(date()) }) +test_that("day accessors work on character inputs", { + x <- "2017-05-07 GMT" + d <- ymd(x) + expect_equal(wday(x), wday(d)) + expect_equal(mday(x), mday(d)) + expect_equal(qday(x), qday(d)) + expect_equal(yday(x), yday(d)) +}) + test_that("wday works with various start values", { days <- days2 <-