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

Changed Duration format to correctly display negative values #746

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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Version 1.7.4.9000

### BUG FIXES

* [#719] (https://github.com/tidyverse/lubridate/issues/719) Negative durations will now properly be displayed with a negative sign.
* [#682](https://github.com/tidyverse/lubridate/issues/682) Fix quarter extraction with small `fiscal_start`s.


Expand Down
1 change: 1 addition & 0 deletions R/durations.r
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ format.Duration <- function(x, ...) {
out <- vector("character", length(x@.Data))
nnas <- !is.na(x@.Data)
out[nnas] <- compute_estimate(abs(x@.Data[nnas]))
out[nnas] <- ifelse(x@.Data[nnas] < 0, paste0("-", out[nnas]), out[nnas])
Copy link
Member

Choose a reason for hiding this comment

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

I think this negative sign should be handled in compute_estimate instead and that abs removed.

out[!nnas] <- NA
out
}
Expand Down