From 8dca7c48ce0ab394b5a9445a32f5b3ea4ba63d30 Mon Sep 17 00:00:00 2001 From: Mikko Marttila <13412395+mikmart@users.noreply.github.com> Date: Fri, 26 Jan 2024 03:18:07 +0000 Subject: [PATCH] Remove special-casing of dates for slider formatting and fix datetimes (#1122) --- R/format.R | 17 ----------------- inst/htmlwidgets/datatables.js | 10 ++++------ 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/R/format.R b/R/format.R index e0277829..bb1143e0 100644 --- a/R/format.R +++ b/R/format.R @@ -127,23 +127,6 @@ formatSignif = function( #' \code{params = list('ko-KR', list(year = 'numeric', month = 'long', day = #' 'numeric'))} formatDate = function(table, columns, method = 'toDateString', params = NULL, rows = NULL) { - if (!inherits(table, 'datatables')) - stop("Invalid table argument; a table object created from datatable() was expected") - x = table$x - if (x$filter != 'none') { - if (inherits(columns, 'formula')) columns = all.vars(columns) - colnames = base::attr(x, 'colnames', exact = TRUE) - rownames = base::attr(x, 'rownames', exact = TRUE) - if (is.null(params)) params = list() - cols = sprintf("%d", name2int(columns, colnames, rownames)) - x$filterDateFmt = as.list(x$filterDateFmt) - for (col in cols) x$filterDateFmt[[col]] = list( - method = method, params = toJSON(params) - ) - table$x = x - } - # the code above is used to ensure the date(time) filter displays the same format or - # timezone as the column value formatColumns(table, columns, tplDate, method, params, rows = rows) } diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index dd8f7788..6a3c3d5c 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -630,13 +630,11 @@ HTMLWidgets.widget({ filter.val(v); } }); - var formatDate = function(d, isoFmt) { + var formatDate = function(d) { d = scaleBack(d, scale); if (type === 'number') return d; if (type === 'integer') return parseInt(d); var x = new Date(+d); - var fmt = ('filterDateFmt' in data) ? data.filterDateFmt[i] : undefined; - if (fmt !== undefined && isoFmt === false) return x[fmt.method].apply(x, fmt.params); if (type === 'date') { var pad0 = function(x) { return ('0' + x).substr(-2, 2); @@ -686,13 +684,13 @@ HTMLWidgets.widget({ if (colDef && typeof colDef.render === 'function') { var restore = function(v) { v = scaleBack(v, scale); - return type !== 'date' ? v : new Date(+v); + return inArray(type, ['date', 'time']) ? new Date(+v) : v; } $span1.text(colDef.render(restore(v1), 'display')); $span2.text(colDef.render(restore(v2), 'display')); } else { - $span1.text(formatDate(v1, false)); - $span2.text(formatDate(v2, false)); + $span1.text(formatDate(v1)); + $span2.text(formatDate(v2)); } }; updateSliderText(r1, r2);