Skip to content

Add $month_from_text built-in variable #43

@michaelbeutler

Description

@michaelbeutler

Add a built-in variable $month_from_text that detects month names in the document text and resolves to a 2-digit month number. Supports English and German month names.

Detected Text Resolves To
January / Januar 01
February / Februar 02
March / März 03
April 04
May / Mai 05
June / Juni 06
July / Juli 07
August 08
September 09
October / Oktober 10
November 11
December / Dezember 12

If no month name is found, resolves to empty string (or a configurable default).

Example Usage

output:
  filename: "Test_AG_$y_$month_from_text"

Implementation

  • File: crates/paporg/src/config/variables.rs
  • Add a new function detect_month_from_text(text: &str) -> Option<String> that scans for month names (case-insensitive)
  • Return the first match found (scanning left-to-right)
  • Add to builtin variables in get_builtin_variables() — requires access to the document text, so the function signature may need to accept text as parameter
  • If no month detected, insert empty string or omit the variable (letting the default mechanism handle it)

Acceptance Criteria

  • Detects English month names (January–December)
  • Detects German month names (Januar, Februar, März, etc.)
  • Case-insensitive detection
  • Returns 2-digit zero-padded number
  • First occurrence wins when multiple months appear
  • Resolves to empty string when no month found
  • Covered by unit tests for all 12 months in both languages

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions