Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore tz argument in as_date() #817

Merged
merged 6 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 1.7.4.9000

### NEW FEATURES

* [#674](https://github.com/tidyverse/lubridate/issues/674) `as_date()` now ignores the `tz` argument
* [#361](https://github.com/tidyverse/lubridate/issues/361) Accessors (`year()`, `month()`, `mday()` etc) now all return integers
* [#713](https://github.com/tidyverse/lubridate/issues/713) `as_datetime()` always returns a `POSIXct()`
* Format and print methods for 0-length objects are more consistent.
Expand Down
8 changes: 6 additions & 2 deletions R/coercion.r
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,14 @@ setMethod(f = "as_date", signature = "numeric",
#' @export
setMethod("as_date", "character",
function(x, tz = NULL, format = NULL) {
if (!is.null(tz)) {
warning("`tz` argument is ignored by `as_date()`", call. = FALSE)
}

if (is.null(format))
as_date(as_datetime(x, tz = "UTC"))
as_date(.parse_iso_dt(x, tz = "UTC"))
else
as_date(strptime(x, format, tz))
as_date(strptime(x, format, tz = "UTC"))
})

#' @rdname as_date
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-Dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ test_that("as_date works", {
expect_equal(as_date("2010-11-03 00:59:59.23"), as_date("2010-11-03"))

## tz is ignored
expect_equal(as_date("2010-08-03 00:59:59.23", tz = "Europe/Amsterdam"), as_date("2010-08-03"))
expect_equal(as_date("2010-11-03 00:59:59.23", tz = "Europe/Amsterdam"), as_date("2010-11-03"))
expect_equal(as_date("2010-08-03 00:59:59.23"), as_date("2010-08-03"))

## can supply custom format
expect_equal(as_date("03/04/2015", format = "%d/%m/%Y"), as_date("2015-04-03"))

## Zulu time is part of the instant spec, so we compute on the instant object
## and not on the textual representation.
Expand Down