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

Adding difftime to date truncates the difftime to full dates #192

Merged
merged 4 commits into from Feb 18, 2019

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Feb 18, 2019

For full hms support. Do we need a lossy cast warning?

@krlmlr krlmlr requested a review from hadley February 18, 2019 13:51
@hadley
Copy link
Member

hadley commented Feb 18, 2019

Yes, we need a warning here.

R/type-date-time.R Outdated Show resolved Hide resolved
@@ -427,24 +427,34 @@ vec_arith.difftime.POSIXct <- function(op, x, y) {
#' @method vec_arith.Date difftime
#' @export
vec_arith.Date.difftime <- function(op, x, y) {
# Exit early to avoid warning
if (!(op %in% c("+", "-"))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like moving this up front. Instead could we make a wrapper function, something like this:

round_warn <- function(x, to) {
  x_floor <- floor(x)
  report_lossy_cast(x, to, x != x_floor)
  x_floor
}

Then could call instead vec_arith_base()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind the fallthrough I've added?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine.

@hadley hadley merged commit cc7c416 into r-lib:master Feb 18, 2019
@krlmlr krlmlr deleted the f-hms-compat branch June 13, 2019 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants