Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove special-casing of dates for slider formatting and fix datetimes #1122

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading