name_time_period

Crates.ioname_time_period
lib.rsname_time_period
version0.3.1
created_at2025-06-07 00:31:42.013928+00
updated_at2025-06-07 01:13:45.802709+00
descriptionName the time period a date is in, configuraiton is supported
homepagehttps://github.com/rickprice/NameTimePeriods
repositoryhttps://github.com/rickprice/NameTimePeriods
max_upload_size
id1703615
size40,536
Frederick Price (rickprice)

documentation

README

NameTimePeriod

A simple and extensible command-line tool written in Rust to determine which named time period (like "Mother's Day" or "Easter") a given date falls into, based on configurable YAML definitions.

✨ Features

  • ✅ Supports flexible date definitions like:
    • The second Sunday of May
    • Easter, Thanksgiving, LaborDay, MLKDay, etc.
  • ✅ Configurable days_before and days_after buffer windows.
  • ✅ System and user configuration file support with merging.
  • ✅ Command-line override of the date to test.
  • ✅ Generates a default config file if none exists.

📦 Installation

Prerequisites

  • Rust (version 1.70+ recommended)

Clone and build:

git clone https://github.com/yourusername/NameTimePeriod.git
cd NameTimePeriod
cargo build --release

Or run with rust-script:

cargo install rust-script
rust-script src/main.rs

🚀 Usage

name_time_period              # Checks today's date
name_time_period --date 2025-05-11
name_time_period --init      # Force (re)create user config

🔧 Configuration

System Config

  • /etc/NameTimePeriod/time_periods.yaml (global, optional)

User Config

  • ~/.config/NameTimePeriod/time_periods.yaml
  • Created automatically on first run or with --init

Example time_periods.yaml

TimePeriods:
  - MothersDay:
      Date: The second Sunday of May
      DaysBefore: 3
      DaysAfter: 1
      Comment: Mother's Day
  - EasterPeriod:
      Date: Easter
      DaysBefore: 5
      DaysAfter: 2

Entries are evaluated in order, and the first match wins.

🧪 Running Tests

cargo test

📁 Directory Structure

NameTimePeriod/
├── src/
│   └── main.rs         # Main logic
├── Cargo.toml
└── README.md

🙋 FAQ

Q: What happens if the same key appears in both system and user configs?
A: The user config takes precedence and overrides the system config for that entry.

Q: Can I define custom holidays?
A: Yes! Just add them to the YAML using a flexible date or standard date format.

📜 License

MIT License. See LICENSE for details.

✍️ Author

Frederick Price

Commit count: 21

cargo fmt