www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 744d6a5a0a4beaef285d19c4ec826905814718d2
parent fb0202fef990625b16ba92420ad81b3e59e2d860
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun, 22 Feb 2009 10:30:01 +0000

Fixes #1320, Last synced tool tip should tell how long ago a sync occurred


Diffstat:
Mchrome/content/zotero/overlay.js | 16++++++++++------
Mchrome/content/zotero/xpcom/zotero.js | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 6 deletions(-)

diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js @@ -341,7 +341,7 @@ var ZoteroPane = new function() var d = new Date(); Zotero.purgeDataObjects(true); var d2 = new Date(); - Zotero.debug("Purged data tables in " + (d2 - d) + "ms"); + Zotero.debug("Purged data tables in " + (d2 - d) + " ms"); if (Zotero.Prefs.get('sync.autoSync') && Zotero.Sync.Server.enabled) { setTimeout(function () { @@ -2201,11 +2201,15 @@ var ZoteroPane = new function() } var lastSyncTime = Zotero.Sync.Server.lastLocalSyncTime; - msg = 'Last sync: ' // TODO: localize - + (lastSyncTime - ? new Date(lastSyncTime * 1000).toLocaleString() - : 'Not yet synced' - ); + // TODO: localize + msg = 'Last sync: '; + if (lastSyncTime) { + var time = new Date(lastSyncTime * 1000); + msg += Zotero.Date.toRelativeDate(time); + } + else { + msg += 'Not yet synced'; + } label.value = msg; } diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -1874,6 +1874,70 @@ Zotero.Date = new function(){ } + /** + * Convert a JS Date to a relative date (e.g., "5 minutes ago") + * + * Adapted from http://snipplr.com/view/10290/javascript-parse-relative-date/ + * + * @param {Date} date + * @return {String} + */ + this.toRelativeDate = function (date) { + // TODO: localize + + var str; + var now = new Date(); + var timeSince = now.getTime() - date; + var inSeconds = timeSince / 1000; + var inMinutes = timeSince / 1000 / 60; + var inHours = timeSince / 1000 / 60 / 60; + var inDays = timeSince / 1000 / 60 / 60 / 24; + var inYears = timeSince / 1000 / 60 / 60 / 24 / 365; + + // in seconds + if (Math.round(inSeconds) == 1) { + str = "1 second ago"; + } + else if (inMinutes < 1.01) { + str = Math.round(inSeconds) + " seconds ago"; + } + + // in minutes + else if (Math.round(inMinutes) == 1) { + str = "1 minute ago"; + } + else if (inHours < 1.01) { + str = Math.round(inMinutes) + " minutes ago"; + } + + // in hours + else if (Math.round(inHours) == 1) { + str = "1 hour ago"; + } + else if (inDays < 1.01) { + str = Math.round(inHours) + " hours ago"; + } + + // in days + else if (Math.round(inDays) == 1) { + str = "1 day ago"; + } + else if (inYears < 1.01) { + str = Math.round(inDays) + " days ago"; + } + + // in years + else if (Math.round(inYears) == 1) { + str = "1 year ago"; + } + else { + str = Math.round(inYears) + " years ago"; + } + + return str; + } + + function getFileDateString(file){ var date = new Date(); date.setTime(file.lastModifiedTime);