Module: OmnifocusMcp::Utils::DateFilter
- Defined in:
- lib/omnifocus_mcp/utils/date_filter.rb
Overview
Parses MCP date-filter wire values and converts them to days-from-today.
Named filters are modeled as symbols (‘:today`, `:tomorrow`, …) after parsing; only string input is accepted at the MCP boundary. Numeric and ISO-date inputs resolve directly to day offsets.
Constant Summary collapse
- STRING_TO_NAMED =
{ "today" => :today, "tomorrow" => :tomorrow, "this week" => :this_week, "next week" => :next_week }.freeze
- ISO_DATE_RE =
/\A\d{4}-\d{2}-\d{2}\z/
Class Method Summary collapse
- .parse(input, today: Date.today) ⇒ Object
-
.resolve(input, today: Date.today) ⇒ Object
MCP boundary helper: parse and convert to days in one step.
-
.to_days(filter) ⇒ Object
Convert a parsed filter to a days-from-‘today` Integer for query scripts.
Class Method Details
.parse(input, today: Date.today) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/omnifocus_mcp/utils/date_filter.rb', line 28 def parse(input, today: Date.today) return input if input.is_a?(Numeric) return input if input.is_a?(Symbol) raise_invalid!(input) unless input.is_a?(String) && !input.empty? normalized = input.strip.downcase return STRING_TO_NAMED[normalized] if STRING_TO_NAMED.key?(normalized) return (parse_iso_date(normalized:, original: input) - today).to_i if ISO_DATE_RE.match?(normalized) raise_invalid!(input) end |
.resolve(input, today: Date.today) ⇒ Object
MCP boundary helper: parse and convert to days in one step.
55 56 57 |
# File 'lib/omnifocus_mcp/utils/date_filter.rb', line 55 def resolve(input, today: Date.today) to_days(parse(input, today: today)) end |
.to_days(filter) ⇒ Object
Convert a parsed filter to a days-from-‘today` Integer for query scripts.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/omnifocus_mcp/utils/date_filter.rb', line 42 def to_days(filter) case filter when :today then 0 when :tomorrow then 1 when :this_week then 7 when :next_week then 14 when Numeric then filter else raise ArgumentError, "expected Symbol or Numeric date filter, got #{filter.inspect}" end end |