File: asJSON.difftime.R

package info (click to toggle)
r-cran-jsonlite 1.7.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,320 kB
  • sloc: ansic: 3,792; sh: 9; makefile: 2
file content (14 lines) | stat: -rw-r--r-- 387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
setMethod("asJSON", "ts", function(x, ...) {
  asJSON(as.vector(x), ...)
})

setOldClass(c("hms", "difftime"))
setMethod("asJSON", "hms", function(x, hms = c("string", "secs"), ...) {
  hms <- match.arg(hms)
  output <- switch(hms,
                   string = as.character(x),
                   secs = as.numeric(x, units = "secs")
  )
  output[is.na(x)] <- NA
  asJSON(output, ...)
})