parse date in js

This commit is contained in:
pvictor 2020-02-14 17:25:52 +01:00
parent 7450f3eb52
commit b0f4b1d588
1 changed files with 4 additions and 6 deletions

View File

@ -32,7 +32,8 @@ parse_df <- function(data, add_names = FALSE) {
FUN = function(x) { FUN = function(x) {
if (inherits(x, "Date")) { if (inherits(x, "Date")) {
# as.numeric(x) * 86400000 # as.numeric(x) * 86400000
format(x) # format(x)
js_date(x)
} else if (inherits(x, "POSIXt")) { } else if (inherits(x, "POSIXt")) {
as.numeric(x) * 1000 as.numeric(x) * 1000
} else if (inherits(x, "factor")) { } else if (inherits(x, "factor")) {
@ -67,7 +68,7 @@ parse_df <- function(data, add_names = FALSE) {
#' @importFrom htmlwidgets JS #' @importFrom htmlwidgets JS
js_date <- function(x) { js_date <- function(x) {
JS(sprintf("new Date('%s').getTime()", x)) lapply(sprintf("new Date('%s').getTime()", x), JS)
} }
parse_timeline_data <- function(.list) { parse_timeline_data <- function(.list) {
@ -78,10 +79,7 @@ parse_timeline_data <- function(.list) {
val <- lapply(.list, `[[`, i) val <- lapply(.list, `[[`, i)
l <- list( l <- list(
x = val$x, x = val$x,
y = list( y = js_date(c(val$start, val$end))
js_date(val$start),
js_date(val$end)
)
) )
if (!is.null(val$fill)) { if (!is.null(val$fill)) {
l$fillColor <- val$fill l$fillColor <- val$fill