Skip to content

Commit

Permalink
Merge pull request #20 from lsilvest/master
Browse files Browse the repository at this point in the history
make explicity setting 'tz=""' behave like if missing
  • Loading branch information
eddelbuettel committed May 2, 2017
2 parents 33732ca + baede39 commit 6de0550
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
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.

0 comments on commit 6de0550

Please sign in to comment.