From 32f290dc13bbd111b4b62904a074c23a74386964 Mon Sep 17 00:00:00 2001 From: Daniel Barrett Date: Wed, 5 Feb 2014 11:44:01 -0600 Subject: [PATCH] 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 }; }