diff --git a/chrome/content/zotero/contextPane.js b/chrome/content/zotero/contextPane.js index 78db231abb..68f33a7d44 100644 --- a/chrome/content/zotero/contextPane.js +++ b/chrome/content/zotero/contextPane.js @@ -507,13 +507,7 @@ var ZoteroContextPane = new function () { var parts = text.split('\n').map(x => x.trim()).filter(x => x.length); var title = parts[0] && parts[0].slice(0, Zotero.Notes.MAX_TITLE_LENGTH); var date = Zotero.Date.sqlToDate(note.dateModified); - if (Date.now() - date < 24 * 60 * 60 * 1000) { - date = Zotero.getString('date.today'); - date = date.charAt(0).toUpperCase() + date.slice(1); - } - else { - date = Zotero.Date.toRelativeDate(date); - } + date = Zotero.Date.toFriendlyDate(date); return { id: note.id, diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index 8caed47bc4..848a6acc84 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -853,6 +853,40 @@ Zotero.Date = new function(){ } + this.toFriendlyDate = function (date) { + // 6:14:36 PM + if (isToday(date)) { + return date.toLocaleString(false, { hour: 'numeric', minute: 'numeric' }) + } + // 'Thursday' + if (isThisWeek(date)) { + return date.toLocaleString(false, { weekday: 'long' }); + } + return date.toLocaleDateString(false, { year: '2-digit', month: 'numeric', day: 'numeric' }); + }; + + + function isToday(date) { + var d = new Date(); + return d.getDate() == date.getDate() + && d.getMonth() == d.getMonth() + && d.getFullYear() == d.getFullYear(); + } + + + function isThisWeek(date) { + var d = new Date(); + return d.getFullYear() == date.getFullYear() && getWeekNumber(d) == getWeekNumber(date); + } + + + // https://stackoverflow.com/a/27125580 + function getWeekNumber(date) { + let onejan = new Date(date.getFullYear(), 0, 1); + return Math.ceil((((date.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7); + } + + function getFileDateString(file){ var date = new Date(); date.setTime(file.lastModifiedTime);