Skip to content

Commit

Permalink
Merge pull request #218 from jread-usgs/master
Browse files Browse the repository at this point in the history
times in webdata
  • Loading branch information
Jordan S Read committed Nov 13, 2015
2 parents 46987c0 + 1482f75 commit 05d9fef
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/01-webdata-obj.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ setClass(

setMethod("initialize", signature = "webdata",
definition = function(.Object, times = .Object@times, url = .Object@url, variables = .Object@variables){
.Object@times = as.POSIXct(times)
.Object@times = geotime(times)
.Object@url = url
.Object@variables = variables
.Object@dataList = 'gov.usgs.cida.gdp.wps.algorithm.discovery.ListOpendapGrids'
Expand Down
4 changes: 3 additions & 1 deletion R/show-webdata.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
setMethod("show", "webdata", function(object){
cat('An object of class "webdata":\n')
cat('times:',as.character(times(object)),'\n')
cat(paste0('times: ',
strftime(times(object)[1] ,format = "%Y-%m-%dT%H:%M:%SZ", tz='UTC'),
', ', strftime(times(object)[2] ,format = "%Y-%m-%dT%H:%M:%SZ", tz='UTC'),'\n'))
cat('url:',url(object),'\n')
cat('variables:', paste(variables(object), collapse=', '))
})
3 changes: 2 additions & 1 deletion R/times-webdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ setMethod(f = "times<-",signature(.Object = "webdata"),
})

geotime <- function(value){

if (is.character(value)){
geotime.character(value)
} else if ("POSIXct" %in% class(value)){
Expand All @@ -59,7 +60,7 @@ geotime.POSIXct = function(value){
}

geotime.character = function(value){
geotime.POSIXct(as.POSIXct(value))
geotime.POSIXct(do.call(c, lapply(value,as.POSIXct)))
}

#'@rdname times-webdata
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-webdata_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ context("Test setting fields of webdata object")
test_that("setters work", {
wd <- webdata('prism',times = as.POSIXct(c('2001-01-01','2002-02-05')))
times(wd)[1] <- as.POSIXct('2000-01-01')
expect_equal(times(wd)[1],as.POSIXct('2000-01-01', tz='UTC'))
expect_equal(times(wd)[1],as.POSIXct('2000-01-01'))
url(wd) <- 'www.badurlppppp.com'
expect_is(url(wd), "character")
})

0 comments on commit 05d9fef

Please sign in to comment.