Skip to content

Commit

Permalink
Remove special-casing of dates for slider formatting and fix datetimes (
Browse files Browse the repository at this point in the history
  • Loading branch information
mikmart authored Jan 26, 2024
1 parent d6c259c commit 8dca7c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
17 changes: 0 additions & 17 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 4 additions & 6 deletions inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8dca7c4

Please sign in to comment.