more useful dates

git-svn-id: http://google-refine.googlecode.com/svn/trunk@589 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-05-04 23:05:10 +00:00
parent e9b630bd76
commit 4f8aea9935
2 changed files with 19 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -26,17 +26,27 @@ function onClickUploadFileButton(evt) {
}
function formatDate(d) {
var yesterday = Date.today().add({ days: -1 });
var d = new Date(d);
var last_year = Date.today().add({ years: -1 });
var last_month = Date.today().add({ months: -1 });
var last_week = Date.today().add({ days: -7 });
var today = Date.today();
var tomorrow = Date.today().add({ days: 1 });
if (d.between(today, tomorrow)) {
return "Today " + d.toString("h:mm tt");
} else if (d.between(yesterday, today)) {
return "Yesterday " + d.toString("h:mm tt");
} else if (d.getYear() == today.getYear()) {
return d.toString("ddd, MMM d");
return "today";
} else if (d.between(last_week, today)) {
var diff = today.getDayOfYear() - d.getDayOfYear();
return (diff == 1) ? "yesterday" : diff + " days ago";
} else if (d.between(last_month, today)) {
var diff = (today.getDayOfYear() - d.getDayOfYear()) / 7;
return (diff == 1) ? "a week ago" : diff.toFixed(0) + " weeks ago" ;
} else if (d.between(last_year, today)) {
var diff = today.getMonth() - d.getMonth();
return (diff == 1) ? "a month ago" : diff + " months ago";
} else {
return d.toString("ddd, MMM d, yyyy");
var diff = today.getYear() - d.getYear();
return (diff == 1) ? "a year ago" : diff + " years ago";
}
}
@ -116,7 +126,7 @@ function renderProjects(data) {
.appendTo(tr.insertCell(tr.cells.length));
$('<div></div>')
.text(formatDate(project.date))
.html(formatDate(project.date))
.addClass("last-modified")
.appendTo(tr.insertCell(tr.cells.length));