Fix parsing of 'yesterday'/'today'/'tomorrow' in access date field

Regression from 5.0.78
This commit is contained in:
Dan Stillman 2019-12-23 03:10:43 -05:00
parent 9c380c362a
commit 0b9f463b9f
2 changed files with 28 additions and 12 deletions

View file

@ -1920,6 +1920,9 @@
if (value != '') {
switch (fieldName) {
case 'accessDate':
// Parse 'yesterday'/'today'/'tomorrow'
value = Zotero.Date.parseDescriptiveString(value);
// Allow "now" to use current time
if (value == 'now') {
value = Zotero.Date.dateToSQL(new Date(), true);
@ -1964,18 +1967,8 @@
default:
// TODO: generalize to all date rows/fields
if (Zotero.ItemFields.isFieldOfBase(fieldName, 'date')) {
// Parse 'yesterday'/'today'/'tomorrow' and convert to dates,
// since it doesn't make sense for those to be actual metadata values
var lc = value.toLowerCase();
if (lc == 'yesterday' || lc == Zotero.getString('date.yesterday')) {
value = Zotero.Date.dateToSQL(new Date(new Date().getTime() - 86400000)).substr(0, 10);
}
else if (lc == 'today' || lc == Zotero.getString('date.today')) {
value = Zotero.Date.dateToSQL(new Date()).substr(0, 10);
}
else if (lc == 'tomorrow' || lc == Zotero.getString('date.tomorrow')) {
value = Zotero.Date.dateToSQL(new Date(new Date().getTime() + 86400000)).substr(0, 10);
}
// Parse 'yesterday'/'today'/'tomorrow'
value = Zotero.Date.parseDescriptiveString(value);
}
}
}

View file

@ -708,6 +708,29 @@ Zotero.Date = new function(){
}
/**
* Convert 'yesterday'/'today'/'tomorrow' to SQL date, or else return original string
*
* @param {String} str
* @return {String}
*/
this.parseDescriptiveString = function (str) {
// Parse 'yesterday'/'today'/'tomorrow' and convert to dates,
// since it doesn't make sense for those to be actual metadata values
var lc = str.toLowerCase().trim();
if (lc == 'yesterday' || lc == Zotero.getString('date.yesterday')) {
str = Zotero.Date.dateToSQL(new Date(new Date().getTime() - 86400000)).substr(0, 10);
}
else if (lc == 'today' || lc == Zotero.getString('date.today')) {
str = Zotero.Date.dateToSQL(new Date()).substr(0, 10);
}
else if (lc == 'tomorrow' || lc == Zotero.getString('date.tomorrow')) {
str = Zotero.Date.dateToSQL(new Date(new Date().getTime() + 86400000)).substr(0, 10);
}
return str;
};
function isSQLDate(str, allowZeroes) {
if (allowZeroes) {
return _sqldateWithZeroesRE.test(str);