Skip to content

Commit 252fa3e

Browse files
committed
Move default behavior into passed-in configuration settings.
1 parent f031b22 commit 252fa3e

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ _ReSharper*/
5050
packages/
5151
.vs
5252
#/.nuget/NuGet.exe
53+
54+
# JetBrains Rider exclusion
55+
/.idea

Griddly/Scripts/griddly.js

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
return val;
5252
case "Date":
53-
return String(val).replace(/[^0-9a-zA-Z-\/]/g, "");
53+
return $.fn.griddly.defaults.getCleanedDate(val);
5454
default:
5555
return val;
5656
}
@@ -122,12 +122,7 @@
122122

123123
return val;
124124
case "Date":
125-
val = parseForValidDate(val);
126-
127-
if (val == null || !isFinite(val))
128-
return null;
129-
else
130-
return (val.getMonth() + 1) + "/" + val.getDate() + "/" + val.getFullYear();
125+
return $.fn.griddly.defaults.getFormattedDate(val);
131126
default:
132127
return val;
133128
}
@@ -347,26 +342,7 @@
347342
switch (datatype)
348343
{
349344
case "Date":
350-
var date;
351-
var pos;
352-
353-
if (typeof (value) === "string" && (pos = value.indexOf("T")) != -1)
354-
{
355-
value = value.substr(0, pos);
356-
357-
// Strip time, we only want date
358-
var parts = value.split('-');
359-
360-
// new Date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])
361-
date = new Date(parts[0], parts[1] - 1, parts[2]); // Note: months are 0-based
362-
}
363-
else
364-
date = new Date(value);
365-
366-
date.setHours(0, 0, 0, 0);
367-
368-
value = date.toLocaleDateString();
369-
345+
value = $.fn.griddly.defaults.getFilterDate(value);
370346
break;
371347
case "Currency":
372348
value = parseFloat(value).toFixed(2);
@@ -2044,6 +2020,35 @@
20442020
return this;
20452021
};
20462022

2023+
const defaultCleanedDate = str => String(str).replace(/[^0-9a-zA-Z-\/]/g, "");
2024+
const defaultFormatedDate = str => {
2025+
var val = parseForValidDate(str);
2026+
return (val == null || !isFinite(val))
2027+
? null
2028+
: (val.getMonth() + 1) + "/" + val.getDate() + "/" + val.getFullYear();
2029+
};
2030+
const defaultFilterDate = strOrDate => {
2031+
var date;
2032+
var pos;
2033+
2034+
if (typeof (strOrDate) === "string" && (pos = strOrDate.indexOf("T")) != -1)
2035+
{
2036+
strOrDate = strOrDate.substr(0, pos);
2037+
2038+
// Strip time, we only want date
2039+
var parts = strOrDate.split('-');
2040+
2041+
// new Date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])
2042+
date = new Date(parts[0], parts[1] - 1, parts[2]); // Note: months are 0-based
2043+
}
2044+
else
2045+
date = new Date(strOrDate);
2046+
2047+
date.setHours(0, 0, 0, 0);
2048+
2049+
return date.toLocaleDateString();
2050+
};
2051+
20472052
$.fn.griddly.defaults = $.extend({},
20482053
{
20492054
pageNumber: 0,
@@ -2065,7 +2070,10 @@
20652070
serializeSkipEmpty: true,
20662071
filtersSelector: "input[name], select[name]",
20672072
exportCustomFunction: null,
2068-
exportFunction: null
2073+
exportFunction: null,
2074+
getCleanedDate: defaultCleanedDate,
2075+
getFormattedDate: defaultFormatedDate,
2076+
getFilterDate: defaultFilterDate
20692077
}, $.fn.griddlyGlobalDefaults);
20702078

20712079
var GriddlyFilterBar = function (element, options)

0 commit comments

Comments
 (0)