mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 10:29:34 +00:00
Add a $year
shortcut for selecting items within some year
This commit is contained in:
parent
7638dc5111
commit
31e2e99c36
@ -131,6 +131,14 @@ object ItemQuery {
|
||||
and(date(Operator.Gte, attr, left), date(Operator.Lte, attr, right))
|
||||
}
|
||||
|
||||
case class YearMacro(attr: DateAttr, year: Int) extends MacroExpr {
|
||||
val body =
|
||||
DateRangeMacro(attr, date(year), date(year + 1))
|
||||
|
||||
private def date(y: Int): Date =
|
||||
Date(y, 1, 1).fold(throw _, identity)
|
||||
}
|
||||
|
||||
def or(expr0: Expr, exprs: Expr*): OrExpr =
|
||||
OrExpr(Nel.of(expr0, exprs: _*))
|
||||
|
||||
|
@ -43,6 +43,9 @@ object DateParser {
|
||||
private val dateFromToday: P[Date.DateLiteral] =
|
||||
P.string("today").as(Date.Today)
|
||||
|
||||
val yearOnly: P[Int] =
|
||||
digits4
|
||||
|
||||
val dateLiteral: P[Date.DateLiteral] =
|
||||
P.oneOf(List(dateFromString, dateFromToday, dateFromMillis))
|
||||
|
||||
|
@ -16,6 +16,9 @@ object MacroParser {
|
||||
Expr.DateRangeMacro(attr, left, right)
|
||||
}
|
||||
|
||||
private def yearMacroImpl(name: String, attr: Attr.DateAttr): P[Expr.YearMacro] =
|
||||
(macroDef(name) *> DateParser.yearOnly).map(year => Expr.YearMacro(attr, year))
|
||||
|
||||
val namesMacro: P[Expr.NamesMacro] =
|
||||
(macroDef("names") *> BasicParser.singleString).map(Expr.NamesMacro.apply)
|
||||
|
||||
@ -25,9 +28,12 @@ object MacroParser {
|
||||
val dueDateRangeMacro: P[Expr.DateRangeMacro] =
|
||||
dateRangeMacroImpl("duein", Attr.DueDate)
|
||||
|
||||
val yearDateMacro: P[Expr.YearMacro] =
|
||||
yearMacroImpl("year", Attr.Date)
|
||||
|
||||
// --- all macro parser
|
||||
|
||||
val all: P[Expr] =
|
||||
P.oneOf(List(namesMacro, dateRangeMacro, dueDateRangeMacro))
|
||||
P.oneOf(List(namesMacro, dateRangeMacro, dueDateRangeMacro, yearDateMacro))
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user