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

Date coercion #389

Closed
wants to merge 11 commits into from
Closed
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export(as.difftime)
export(as.duration)
export(as.interval)
export(as.period)
export(as_date)
export(ceiling_date)
export(date)
export(date_decimal)
Expand Down Expand Up @@ -267,6 +268,7 @@ exportMethods(as.character)
exportMethods(as.difftime)
exportMethods(as.interval)
exportMethods(as.numeric)
exportMethods(as_date)
exportMethods(c)
exportMethods(intersect)
exportMethods(reclass_timespan)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Version 1.5.0.9000 (development)
* [#373](https://github.com/hadley/lubridate/issues/373) New `date` and `date<-` additions to the `year`, `month` etc family of accessors.
* [#365](https://github.com/hadley/lubridate/issues/365) New very fast datetime constructor `make_datetime` (dropin replacement of `ISOdatetime`).
* [#344](https://github.com/hadley/lubridate/issues/344) `force_tz` and `with_tz` can handle data.frames component-wise
* [#355](https://github.com/hadley/lubridate/issues/355) `as_date` methods with
sensible defaults including POSIXt objects being converted to Date objects by
effectively ignoring sub-day time units in the time-zone of the POSIXt object.


### CHANGES

Expand Down
224 changes: 136 additions & 88 deletions R/coercion.r

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion man/am.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions man/as.duration.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions man/as.interval.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 33 additions & 33 deletions man/as.period.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions man/as_date.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions tests/testthat/test-Dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ test_that("is.Date works as expected",{
expect_that(is.Date(234), is_false())
expect_that(is.Date(as.POSIXct("2008-08-03 13:01:59", tz = "UTC")),
is_false())
expect_that(is.Date(as.POSIXlt("2008-08-03 13:01:59", tz = "UTC")),
expect_that(is.Date(as.POSIXlt("2008-08-03 13:01:59", tz = "UTC")),
is_false())
expect_that(is.Date(Sys.Date()), is_true())
expect_that(is.Date(minutes(1)), is_false())
expect_that(is.Date(dminutes(1)), is_false())
expect_that(is.Date(interval(
as.POSIXct("2008-08-03 13:01:59", tz = "UTC"),
as.POSIXct("2008-08-03 13:01:59", tz = "UTC"),
as.POSIXct("2009-08-03 13:01:59", tz = "UTC") )), is_false())
})

test_that("is.Date handles vectors",{
expect_that(is.Date(c(Sys.Date(), as.Date("2009-10-31"))),
is_true())
})

test_that("as_date works", {
dt1 <- as.POSIXct("2010-08-03 00:59:59.23")
dt2 <- as.POSIXct("2010-08-03 00:59:59.23", tz="Europe/London")
dt3 <- as.POSIXct("2010-11-03 00:59:59.23")
dt4 <- as.POSIXct("2010-11-03 00:59:59.23", tz="Europe/London")
expect_equal(as_date(dt1), as.Date("2010-08-03"))
expect_equal(as_date(dt2), as.Date("2010-08-03"))
expect_equal(as_date(dt3), as.Date("2010-11-03"))
expect_equal(as_date(dt4), as.Date("2010-11-03"))
})