#month #fuzzy #date #parser #fuzzy-matching #time #date-time

bin+lib fuzzymonth

A fuzzy month parser which handles a variety of input formats

2 unstable releases

new 0.2.0 Jan 7, 2025
0.1.0 Jan 7, 2025

#339 in Parser implementations

Download history 143/week @ 2025-01-02

143 downloads per month

MIT/Apache

24KB
407 lines

fuzzymonth πŸ“…

A robust, user-friendly Rust library for parsing month names with built-in fuzzy matching. It handles various formats, typos, and international month names.

Features

  • ✨ Fuzzy matching for typos and misspellings
  • 🌍 International support (Spanish, French, German, Italian, Polish, Russian, Arabic, Chinese)
  • πŸ“ Multiple input formats:
    • Full names ("January", "February")
    • Common abbreviations ("Jan", "Feb", "Sept")
    • Numbers ("1", "01")
    • Ordinal numbers ("1st", "2nd", "3rd")
  • 🧹 Automatic cleanup of input (whitespace trimming, case-insensitive)
  • πŸ’ͺ Extensively tested with property-based tests and fuzzing

Usage

Add to your Cargo.toml:

[dependencies]
fuzzymonth = "0.1.0"

Basic usage:

use fuzzymonth::{parse_month, Month};

fn main() {
    // Standard formats
    assert_eq!(parse_month("January").unwrap(), Month::January);
    assert_eq!(parse_month("feb").unwrap(), Month::February);
    
    // International support
    assert_eq!(parse_month("enero").unwrap(), Month::January);    // Spanish
    assert_eq!(parse_month("fΓ©vrier").unwrap(), Month::February); // French
    
    // Handles typos
    assert_eq!(parse_month("septemer").unwrap(), Month::September);
    assert_eq!(parse_month("agust").unwrap(), Month::August);
    
    // Various formats
    assert_eq!(parse_month("1st").unwrap(), Month::January);
    assert_eq!(parse_month("03").unwrap(), Month::March);
    
    // Even handles messy input
    assert_eq!(parse_month(" JANUARY ").unwrap(), Month::January);
    assert_eq!(parse_month("j@nuary").unwrap(), Month::January);
}

Command Line Interface

fuzzymonth comes with a friendly interactive CLI tool for testing month parsing:

# Install from crates.io
cargo install fuzzymonth

# Or run directly from source
cargo run

You'll get an interactive prompt where you can test various month formats:

πŸ—“  Fuzzy Month Parser
Type a month name (any format) and press Enter
Press Ctrl+C or Enter an empty line to exit

β†’ january
βœ“ January (1)

β†’ feb
βœ“ February (2)

β†’ septembr
βœ“ September (9)

β†’ enero
βœ“ January (1)

β†’ xyz
βœ— Invalid input: xyz

β†’ [Enter]
πŸ‘‹ Goodbye!

How It Works

The library uses a multi-step approach to parse month names:

  1. Exact matching against known formats
  2. Number parsing (including ordinal numbers)
  3. International variant matching
  4. Fuzzy matching using Levenshtein distance for typo tolerance

Testing

The library is extensively tested with:

  • Comprehensive unit tests covering all supported formats
  • Property-based tests for fuzzy matching consistency
  • Edge case testing for special characters and mixed inputs
  • International format validation
  • Extensive fuzzing to ensure robustness

Contributing

Contributions are welcome! Here are some ways you can help:

  • Add support for more languages and regional formats
  • Contribute common misspellings or abbreviations from your locale
  • Add new test cases for edge cases you've encountered
  • Improve fuzzy matching accuracy
  • Add new input formats

Please ensure tests pass and add new tests for any added functionality.

License

MIT License


Built with πŸ’ for real-world month parsing. Because dates are hard, and users are creative.

Dependencies

~52KB