Whenharp 1.0.0-alpha.2505.4

This is a prerelease version of Whenharp.
dotnet add package Whenharp --version 1.0.0-alpha.2505.4
                    
NuGet\Install-Package Whenharp -Version 1.0.0-alpha.2505.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Whenharp" Version="1.0.0-alpha.2505.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Whenharp" Version="1.0.0-alpha.2505.4" />
                    
Directory.Packages.props
<PackageReference Include="Whenharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Whenharp --version 1.0.0-alpha.2505.4
                    
#r "nuget: Whenharp, 1.0.0-alpha.2505.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Whenharp@1.0.0-alpha.2505.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Whenharp&version=1.0.0-alpha.2505.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Whenharp&version=1.0.0-alpha.2505.4&prerelease
                    
Install as a Cake Tool

Whenharp

Tests publish Whenharp to nuget Whenharp on NuGet

Whenharp is a lightweight and powerful .NET library designed to parse human-readable time rules and determine whether a given DateTime matches those rules.

🚀 Features

  • 🕒 Simple and readable time rule syntax
  • ✅ Basic rules like Always and Never
  • 📅 Specific date ranges: From 2025-04-23T12:00 to 2025-04-23T17:00
  • 🔁 Recurring day rules: EveryMonday, EveryWeekend
  • ⏰ Daily time intervals combined with day rules: EveryMonday from 12:00 to 17:00
  • 💥 Throws detailed ArgumentException for invalid inputs

📦 Installation

Install via NuGet:

dotnet add package Whenharp

📌 Usage Examples

✅ Basic Usage

using WhenSharp;

// Parse a time rule
var rule = When.Parse("EveryMonday from 09:00 to 17:00");

// Check if a given DateTime matches the rule
bool isMatch = rule.Match(DateTime.Now);

Console.WriteLine($"Is match: {isMatch}");

📅 Supported Rule Formats

🔹 Always

var rule = When.Parse("Always");
rule.Match(DateTime.Now); // always true

🔹 Never

var rule = When.Parse("Never");
rule.Match(DateTime.Now); // always false

🔹 From a Specific DateTime to Another

var rule = When.Parse("From 2025-04-23T08:30 to 2025-04-23T17:45");
rule.Match(new DateTime(2025, 4, 23, 9, 0, 0)); // true
rule.Match(new DateTime(2025, 4, 24, 9, 0, 0)); // false

🔹 Recurring Rule: Every Day of the Week

var rule = When.Parse("EveryMonday");
rule.Match(new DateTime(2025, 5, 5)); // true if Monday

🔹 Recurring with Time Range

var rule = When.Parse("EveryFriday from 14:00 to 18:00");
rule.Match(new DateTime(2025, 6, 6, 15, 30, 0)); // true
rule.Match(new DateTime(2025, 6, 6, 19, 0, 0));  // false

🔹 EveryWeekend (Saturday & Sunday)

var rule = When.Parse("EveryWeekend");
rule.Match(new DateTime(2025, 5, 25)); // true if Sunday

🔹 EveryWeekend with Time Range

var rule = When.Parse("EveryWeekend from 10:00 to 16:00");
rule.Match(new DateTime(2025, 5, 24, 12, 0, 0)); // true if Saturday

⚠️ Invalid Rule Handling

try
{
    var rule = When.Parse("EveryBlursday");
}
catch (ArgumentException ex)
{
    Console.WriteLine($"Invalid rule: {ex.Message}");
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.2505.4 141 5/28/2025
1.0.0-alpha.2505.3 122 5/28/2025
1.0.0-alpha.2505.2 130 5/28/2025
1.0.0-alpha.2505.1 164 5/28/2025

Initial release with basic rules like Always, Never, Range, and recurring day-time combinations.