From 68714b682e488ec975b8ac5adbeec417db1bc217 Mon Sep 17 00:00:00 2001 From: Shodhan Date: Thu, 25 Jan 2018 01:08:00 +0530 Subject: [PATCH 1/2] Updating natural-time-detal plugin Added support for decades, years, months, milliseconds and microseconds --- sorting/natural-time-delta.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sorting/natural-time-delta.js b/sorting/natural-time-delta.js index 365bdce..9a53c9d 100644 --- a/sorting/natural-time-delta.js +++ b/sorting/natural-time-delta.js @@ -21,7 +21,7 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort,{ "natural-time-delta-pre" : function(data){ var result = 0; - var pattern = /(\d+\s*weeks?\s*)?(\d+\s*days?\s*)?(\d+\s*hours?\s*)?(\d+\s*minutes?)?(\d+\s*seconds?)?/i + var pattern = /(\d+\s*decades?\s*)?(\d+\s*years?\s*)?(\d+\s*months?\s*)?(\d+\s*weeks?\s*)?(\d+\s*days?\s*)?(\d+\s*hours?\s*)?(\d+\s*minutes?\s*)?(\d+\s*seconds?\s*)?(\d+\s*milliseconds?\s*)?(\d+\s*microseconds?\s*)?/i var format_time_element = function(el, splitter, mul){ if (el === undefined){ return 0; @@ -33,11 +33,16 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort,{ matches.reverse(); var time_elements = [ + {"splitter" : "us", "name" : "microsecond", "mul" : 1 / 1000 / 1000}, + {"splitter" : "ms", "name" : "millisecond", "mul" : 1 / 1000}, {"splitter" : "s", "name" : "second", "mul" : 1}, {"splitter" : "m", "name" : "minute", "mul" : 1 * 60}, {"splitter" : "h", "name" : "hour", "mul" : 1 * 60 * 60}, {"splitter" : "d", "name" : "day", "mul" : 1 * 60 * 60 * 24}, {"splitter" : "w", "name" : "week", "mul" : 1 * 60 * 60 * 24 * 7}, + {"splitter" : "w", "name" : "month", "mul" : 1 * 60 * 60 * 24 * 7 * 30}, + {"splitter" : "w", "name" : "year", "mul" : 1 * 60 * 60 * 24 * 7 * 30 * 12}, + {"splitter" : "w", "name" : "decade", "mul" : 1 * 60 * 60 * 24 * 7 * 30 * 12 * 10}, ]; time_elements.forEach(function(el, i){ From 7e8d8d75af96af9629f7ebce513ac683e24f5cb5 Mon Sep 17 00:00:00 2001 From: Shodhan Date: Thu, 25 Jan 2018 10:52:59 +0530 Subject: [PATCH 2/2] Updated doc --- sorting/natural-time-delta.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sorting/natural-time-delta.js b/sorting/natural-time-delta.js index 9a53c9d..f08087f 100644 --- a/sorting/natural-time-delta.js +++ b/sorting/natural-time-delta.js @@ -1,11 +1,15 @@ /** * Created by Shodhan Save on Jan 23, 2018. +* Updated @ Jan 25, 2018 */ /** * This plug-in allows sorting of human readable time delta, viz., * "1 week", "2 weeks 3 days", "4 weeks 5 days 6hours", etc. -* Curently this plugin supports time range from seconds to weeks +* +* Curently this plugin supports time range from microseconds to decades. +* +* The plugin also takes care of singular and plural values lik week(s) * * @name Natural Time Delta * @summary Sort human readable time delta