mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-22 23:16:53 +00:00
Merge pull request #399 from shendaras/patch-1
getRelativeDate: support for negative deltas
This commit is contained in:
commit
f0ab607ea1
@ -208,6 +208,11 @@ 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) {
|
||||
delta = -1*delta;
|
||||
futurep = true;
|
||||
}
|
||||
var units = [
|
||||
{name: "years", duration: 365 * 24 * 60 * 60 * 1000},
|
||||
{name: "months", duration: (365/12) * 24 * 60 * 60 * 1000},
|
||||
@ -219,9 +224,15 @@ exports.getRelativeDate = function(delta) {
|
||||
for(var t=0; t<units.length; t++) {
|
||||
var result = Math.floor(delta / units[t].duration);
|
||||
if(result >= 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
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user