diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index 020e35adea..1c0d18aab7 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -52,6 +52,12 @@ class ConditionEditor(QWidget): # {{{ (_('is less than'), 'lt'), (_('is greater than'), 'gt') ), + 'datetime' : ( + (_('is equal to'), 'eq'), + (_('is less than'), 'lt'), + (_('is greater than'), 'gt'), + (_('is not more days ago than'), 'count_days') + ), 'multiple' : ( (_('has'), 'has'), (_('does not have'), 'does not have'), @@ -70,7 +76,7 @@ class ConditionEditor(QWidget): # {{{ ), } - for x in ('float', 'rating', 'datetime'): + for x in ('float', 'rating'): ACTION_MAP[x] = ACTION_MAP['int'] @@ -232,8 +238,12 @@ class ConditionEditor(QWidget): # {{{ v = QIntValidator if dt == 'int' else QDoubleValidator self.value_box.setValidator(v(self.value_box)) elif dt == 'datetime': - self.value_box.setInputMask('9999-99-99') - tt = _('Enter a date in the format YYYY-MM-DD') + if action == 'count_days': + self.value_box.setValidator(QIntValidator(self.value_box)) + tt = _('Enter the number of days old the item can be') + else: + self.value_box.setInputMask('9999-99-99') + tt = _('Enter a date in the format YYYY-MM-DD') else: tt = _('Enter a string.') if 'pattern' in action: diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 9366b3e5d7..807279a565 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -133,13 +133,16 @@ class Rule(object): # {{{ return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) def date_condition(self, col, action, val): + if action == 'count_days': + return (("cmp(add(%s, 1), days_between(today(), format_date(raw_field('%s'), 'yyyy-MM-dd')), '', '1', '1')") + %(val, col)) lt, eq, gt = { 'eq': ('', '1', ''), 'lt': ('1', '', ''), 'gt': ('', '', '1') }[action] - return "strcmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), '%s', '%s', '%s', '%s')" % (col, - val, lt, eq, gt) + return ("strcmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), '%s', '%s', '%s', '%s')" % + (col, val, lt, eq, gt)) def multiple_condition(self, col, action, val, sep): if not sep or sep == '|':