MCPcopy Create free account
hub / github.com/breck7/scroll / __mlHelper

Function __mlHelper

external/.datatables.js:11335–11419  ·  view source on GitHub ↗
(localeString)

Source from the content-addressed store, hash-verified

11333 // Wrapper for date, datetime and time which all operate the same way with the exception of
11334 // the output string for auto locale support
11335 function __mlHelper(localeString) {
11336 return function (from, to, locale, def) {
11337 // Luxon and Moment support
11338 // Argument shifting
11339 if (arguments.length === 0) {
11340 locale = "en"
11341 to = null // means toLocaleString
11342 from = null // means iso8601
11343 } else if (arguments.length === 1) {
11344 locale = "en"
11345 to = from
11346 from = null
11347 } else if (arguments.length === 2) {
11348 locale = to
11349 to = from
11350 from = null
11351 }
11352
11353 var typeName = "datetime" + (to ? "-" + to : "")
11354
11355 // Add type detection and sorting specific to this date format - we need to be able to identify
11356 // date type columns as such, rather than as numbers in extensions. Hence the need for this.
11357 if (!DataTable.ext.type.order[typeName]) {
11358 DataTable.type(typeName, {
11359 detect: function (d) {
11360 // The renderer will give the value to type detect as the type!
11361 return d === typeName ? typeName : false
11362 },
11363 order: {
11364 pre: function (d) {
11365 // The renderer gives us Moment, Luxon or Date obects for the sorting, all of which have a
11366 // `valueOf` which gives milliseconds epoch
11367 return d.valueOf()
11368 }
11369 },
11370 className: "dt-right"
11371 })
11372 }
11373
11374 return function (d, type) {
11375 // Allow for a default value
11376 if (d === null || d === undefined) {
11377 if (def === "--now") {
11378 // We treat everything as UTC further down, so no changes are
11379 // made, as such need to get the local date / time as if it were
11380 // UTC
11381 var local = new Date()
11382 d = new Date(Date.UTC(local.getFullYear(), local.getMonth(), local.getDate(), local.getHours(), local.getMinutes(), local.getSeconds()))
11383 } else {
11384 d = ""
11385 }
11386 }
11387
11388 if (type === "type") {
11389 // Typing uses the type name for fast matching
11390 return typeName
11391 }
11392

Callers 1

.datatables.jsFile · 0.85

Calls 5

__mldObjFunction · 0.85
__mldFunction · 0.85
_escapeHtmlFunction · 0.85
typeMethod · 0.80
valueOfMethod · 0.80

Tested by

no test coverage detected