Fixes #1320, Last synced tool tip should tell how long ago a sync occurred
This commit is contained in:
parent
fb0202fef9
commit
744d6a5a0a
2 changed files with 74 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue