Round date/time diffs so the comparisons with 1 would work.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@611 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-05-06 16:44:18 +00:00
parent ed5ef0fa16
commit 0562881a06

View File

@ -36,16 +36,16 @@ function formatDate(d) {
if (d.between(today, tomorrow)) { if (d.between(today, tomorrow)) {
return "today"; return "today";
} else if (d.between(last_week, today)) { } else if (d.between(last_week, today)) {
var diff = today.getDayOfYear() - d.getDayOfYear(); var diff = Math.floor(today.getDayOfYear() - d.getDayOfYear());
return (diff == 1) ? "yesterday" : diff + " days ago"; return (diff == 1) ? "yesterday" : diff + " days ago";
} else if (d.between(last_month, today)) { } else if (d.between(last_month, today)) {
var diff = (today.getDayOfYear() - d.getDayOfYear()) / 7; var diff = Math.floor((today.getDayOfYear() - d.getDayOfYear()) / 7);
return (diff == 1) ? "a week ago" : diff.toFixed(0) + " weeks ago" ; return (diff == 1) ? "a week ago" : diff.toFixed(0) + " weeks ago" ;
} else if (d.between(last_year, today)) { } else if (d.between(last_year, today)) {
var diff = today.getMonth() - d.getMonth(); var diff = Math.floor(today.getMonth() - d.getMonth());
return (diff == 1) ? "a month ago" : diff + " months ago"; return (diff == 1) ? "a month ago" : diff + " months ago";
} else { } else {
var diff = today.getYear() - d.getYear(); var diff = Math.floor(today.getYear() - d.getYear());
return (diff == 1) ? "a year ago" : diff + " years ago"; return (diff == 1) ? "a year ago" : diff + " years ago";
} }
} }