From 32f290dc13bbd111b4b62904a074c23a74386964 Mon Sep 17 00:00:00 2001 From: Daniel Barrett Date: Wed, 5 Feb 2014 11:44:01 -0600 Subject: [PATCH 1/2] getRelativeDate: support for negative deltas Add support for format="relativedate" to be used when the date is in the future. --- core/modules/utils/utils.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 921dd0724..5419781fc 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -208,6 +208,10 @@ Returns an object with these members: updatePeriod: time in millisecond until the string will be inaccurate */ exports.getRelativeDate = function(delta) { + var futurep = false; + if (delta < 0) { + futurep = true; + } var units = [ {name: "years", duration: 365 * 24 * 60 * 60 * 1000}, {name: "months", duration: (365/12) * 24 * 60 * 60 * 1000}, @@ -219,9 +223,15 @@ exports.getRelativeDate = function(delta) { for(var t=0; t= 2) { + var desc = result + " " + units[t].name; + if (futurep) { + desc = desc + " from now"; + } else { + desc = desc + " ago"; + } return { delta: delta, - description: result + " " + units[t].name + " ago", + description: desc, updatePeriod: units[t].duration }; } From d02ce5dbf304635edb27174f6d03a3c17323a434 Mon Sep 17 00:00:00 2001 From: Daniel Barrett Date: Wed, 5 Feb 2014 12:37:37 -0600 Subject: [PATCH 2/2] oops, actually correct delta Actually change delta to a positive number to get the logic the same. --- core/modules/utils/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 5419781fc..823bcdab2 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -210,6 +210,7 @@ Returns an object with these members: exports.getRelativeDate = function(delta) { var futurep = false; if (delta < 0) { + delta = -1*delta; futurep = true; } var units = [