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

make explicity setting 'tz=""' behave like if missing #20

Merged
merged 1 commit into from
May 2, 2017
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
8 changes: 4 additions & 4 deletions R/nanotime.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ setMethod("show",
##' @export
format.nanotime <- function(x, tz="", ...)
{
if (missing(tz)) {
if (tz=="") {
if (!is.null(tzone <- attr(x, "tzone")))
tz <- tzone
else
Expand All @@ -186,8 +186,8 @@ index2char.nanotime <- function(x, ...) {

##' @rdname nanotime
##' @export
as.POSIXct.nanotime <- function(x, tz, ...) {
if (missing(tz)) {
as.POSIXct.nanotime <- function(x, tz="", ...) {
if (tz=="") {
if (!is.null(tzone <- attr(x, "tzone")))
tz <- tzone
else
Expand All @@ -200,7 +200,7 @@ as.POSIXct.nanotime <- function(x, tz, ...) {

##' @rdname nanotime
##' @export
as.POSIXlt.nanotime <- function(x, tz, ...) {
as.POSIXlt.nanotime <- function(x, tz="", ...) {
as.POSIXlt(as.POSIXct(x, tz=tz))
}

Expand Down
12 changes: 7 additions & 5 deletions inst/unitTests/test_nanotime.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ test_format_tz <- function() {
oldTz <- getOption("nanotimeTz")
options(nanotimeFormat=NULL)

a <- nanotime("1970-01-01T00:00:00.000000000+00:00")
a_utc = "1970-01-01T00:00:00.000000000+00:00"
nt <- nanotime(a_utc)
a_ny <- "1969-12-31T19:00:00.000000000-05:00"

options(nanotimeTz=NULL)
checkEquals(format(a, tz="America/New_York"), a_ny)
checkEquals(format(nt, tz="America/New_York"), a_ny)

options(nanotimeTz="UTC")
checkEquals(format(a, tz="America/New_York"), a_ny)
checkEquals(format(nt, tz="America/New_York"), a_ny)

attr(a, "tzone") <- "UTC"
checkEquals(format(a, tz="America/New_York"), a_ny)
attr(nt, "tzone") <- "UTC"
checkEquals(format(nt, tz="America/New_York"), a_ny)
checkEquals(format(nt, tz=""), a_utc)

options(nanotimeFormat=oldFormat)
options(nanotimeTz=oldTz)
Expand Down
4 changes: 2 additions & 2 deletions man/nanotime.Rd

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