OpenHours 1.0.2
dotnet add package OpenHours --version 1.0.2
NuGet\Install-Package OpenHours -Version 1.0.2
<PackageReference Include="OpenHours" Version="1.0.2" />
<PackageVersion Include="OpenHours" Version="1.0.2" />
<PackageReference Include="OpenHours" />
paket add OpenHours --version 1.0.2
#r "nuget: OpenHours, 1.0.2"
#:package OpenHours@1.0.2
#addin nuget:?package=OpenHours&version=1.0.2
#tool nuget:?package=OpenHours&version=1.0.2
๐ OpeningHours
OpeningHours is a lightweight .NET library for evaluating whether a specific DateTime falls within defined business hours. It supports a rich, human-readable pattern syntax for specifying weekly schedules, date-based rules, time ranges, and exclusions.
โจ Features
- โ Define business hours using intuitive patterns
- ๐
Support for weekdays, specific dates, and nth weekday of the month (e.g.,
Fr[2]) - โฐ Time range support including overnight spans (e.g.,
23:00-02:00) - ๐ซ Exclusion rules override inclusions (e.g.,
We off) - ๐งช Thoroughly tested with edge cases and complex combinations
๐ Pattern Syntax
Patterns are composed of inclusions and exclusions, separated by semicolons:
Mo-Th 08:00-20:00;We off;Aug 20;Aug 21 off
๐งฉ Components
| Syntax | Description |
|---|---|
Mo, Tu, We, Th, Fr, Sa, Su |
Weekdays |
08:00-20:00 |
Time range (24h format) |
Fr[2] |
Nth weekday of the month (e.g., 2nd Friday) |
Aug 20 |
Specific calendar date |
Aug 20 off |
Exclude a specific date |
Mo off |
Exclude a weekday |
00:00-24:00 |
Full-day availability |
23:00-02:00 |
Overnight span |
Jan 01-04 off |
Exclude a date range |
โน๏ธ Exclusions always take precedence over inclusions.
๐ Usage
bool isOpen = OpeningHours.IsNowWithinBusinessHours(
"Mo-Fr 09:00-17:00;We off;Dec 25 off",
DateTime.Parse("2025-12-25 10:00")
);
// Returns false (Christmas is excluded)
โ Test Coverage
The library is validated with extensive NUnit test cases, including:
- โ๏ธ Basic weekday and time range checks
- โ Excluded weekdays and dates
- ๐ Specific dates and date ranges
- ๐ง Priority resolution (exclusions override inclusions)
- ๐ Midnight and overnight spans
- ๐
Nth weekday logic (e.g.,
Mo[1],Fr[2]) - ๐ Time zone-sensitive evaluations
Example test case:
[TestCase("Mo-Th 08:00-20:00;We off", "2025-01-15 09:00", false)]
[TestCase("Fr[2] 08:00-10:00;Fr[3] off", "2025-10-10 08:30", true)]
[TestCase("Aug 20;Aug 20 off", "2025-08-20", false)]
๐งช Running Tests
Tests are written using NUnit. To run them:
dotnet test
๐ง Inspiration: opening_hours.js
This library was inspired by the excellent opening_hours.js project, which provides a robust parser and evaluator for the opening_hours tag used in OpenStreetMap (OSM). That tag encodes complex business hour patterns for facilities like shops, restaurants, and public services. Also you can evaluate your pattern here
๐ License
MIT License. See LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- 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.