Käynnissä

update this javascript function

Need the date sort part to work for AM/PM date times. Currently the time only works for 24 hours times.

-----------------------------------------------------------------------------------------------

var Sort = (function(){

var sort = {};

// Default alpha-numeric sort

// --------------------------

[url removed, login to view] = function(a,b) {

return (a==b)?0:(a<b)?-1:1;

};

sort['default'] = [url removed, login to view]; // IE chokes on [url removed, login to view]

// This conversion is generalized to work for either a decimal separator of , or .

sort.numeric_converter = function(separator) {

return function(val) {

if (typeof(val)=="string") {

multi = ([url removed, login to view]('-')==-1) ? 1 : -1;

val = multi * parseFloat([url removed, login to view](/^[^\d\.]*([\d., ]+).*/g,"$1").replace(new RegExp("[^\\\d"+separator+"]","g"),'').replace(/,/,'.')) || 0;

}

return val || 0;

};

};

// Numeric Sort

// ------------

[url removed, login to view] = function(a,b) {

return [url removed, login to view](a)[url removed, login to view](b);

};

[url removed, login to view] = sort.numeric_converter(".");

// Numeric Sort - comma decimal separator

// --------------------------------------

sort.numeric_comma = function(a,b) {

return [url removed, login to view](a)[url removed, login to view](b);

};

[url removed, login to view] = sort.numeric_converter(",");

// Case-insensitive Sort

// ---------------------

[url removed, login to view] = function(a,b) {

return [url removed, login to view]([url removed, login to view](a),[url removed, login to view](b));

};

[url removed, login to view] = function(val) {

if (val==null) { return ""; }

return (""+val).toLowerCase();

};

// Currency Sort

// -------------

[url removed, login to view] = [url removed, login to view]; // Just treat it as numeric!

sort.currency_comma = sort.numeric_comma;

// Date sort

// ---------

[url removed, login to view] = function(a,b) {

return [url removed, login to view]([url removed, login to view](a),[url removed, login to view](b));

};

// Convert 2-digit years to 4

sort.date.fixYear=function(yr) {

yr = +yr;

if (yr<50) { yr += 2000; }

else if (yr<100) { yr += 1900; }

return yr;

};

[url removed, login to view] = [

// YY[YY]-MM-DD

{ re:/(\d{2,4})-(\d{1,2})-(\d{1,2})/ , f:function(x){ return (new Date([url removed, login to view](x[1]),+x[2],+x[3])).getTime(); } }

// MM/DD/YY[YY] or MM-DD-YY[YY]

,{ re:/(\d{1,2})[\/-](\d{1,2})[\/-](\d{2,4})/ , f:function(x){ return (new Date([url removed, login to view](x[3]),+x[1],+x[2])).getTime(); } }

// Any catch-all format that new Date() can handle. This is not reliable except for long formats, for example: 31 Jan 2000 01:23:45 GMT

,{ re:/(.*\d{4}.*\d+:\d+\d+.*)/, f:function(x){ var d=new Date(x[1]); if(d){return [url removed, login to view]();} } }

];

[url removed, login to view] = function(val) {

val=[url removed, login to view](/[a-z,A-Z]/g,'');

var m,v, f = [url removed, login to view];

for (var i=0,L=[url removed, login to view]; i<L; i++) {

if (m=[url removed, login to view](f[i].re)) {

v=f[i].f(m);

if (typeof(v)!="undefined") { return v; }

}

}

return 9999999999999; // So non-parsed dates will be last, not first

};

return sort;

})();

Taidot: Javascript

Näytä lisää: javascript sort numeric alphanumeric, string match, string b, sort sort sort, sort sort, sort function c, regexp example, m string, match string, c sort function, javascript sort currency, yy, val , parsed, numeric, null, mm, function, d g, b v, currency javascript, catch can, hours dates, javascript null, update dates

Tietoa työnantajasta:
( 17 arvostelua ) Dallas, United States

Projektin tunnus: #499613

Myönnetty käyttäjälle:

fogtower

Please check PM for detail.

30 $ USD 0 päivässä
(9 arvostelua)
3.6

3 freelanceria on tarjonnut keskimäärin 43 $ tähän työhön

ranacseruet

I can do it easily...

70 $ USD 1 päivässä
(18 arvostelua)
4.3
akhd

I can do this overnight or sooner.

30 $ USD 1 päivässä
(4 arvostelua)
3.8