{"id":18307806,"url":"https://github.com/exceptionless/exceptionless.datetimeextensions","last_synced_at":"2026-02-13T00:16:19.725Z","repository":{"id":22860098,"uuid":"26207748","full_name":"exceptionless/Exceptionless.DateTimeExtensions","owner":"exceptionless","description":"DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods","archived":false,"fork":false,"pushed_at":"2024-07-08T23:20:24.000Z","size":254,"stargazers_count":246,"open_issues_count":6,"forks_count":27,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-16T11:05:18.230Z","etag":null,"topics":["business-days","c-sharp","datetime","datetimeoffset","datetimerange","exceptionless","range","time","timespan"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/Exceptionless.DateTimeExtensions/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/exceptionless.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"exceptionless"}},"created_at":"2014-11-05T07:09:47.000Z","updated_at":"2025-05-12T03:01:34.000Z","dependencies_parsed_at":"2023-02-16T12:30:59.799Z","dependency_job_id":"3364730f-f67b-477a-9dba-bc71b9057fdd","html_url":"https://github.com/exceptionless/Exceptionless.DateTimeExtensions","commit_stats":{"total_commits":129,"total_committers":6,"mean_commits":21.5,"dds":0.5813953488372092,"last_synced_commit":"c0223626e3749f6c7b3ab56ec6193bd5bc3de2d2"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exceptionless%2FExceptionless.DateTimeExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exceptionless%2FExceptionless.DateTimeExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exceptionless%2FExceptionless.DateTimeExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exceptionless%2FExceptionless.DateTimeExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exceptionless","download_url":"https://codeload.github.com/exceptionless/Exceptionless.DateTimeExtensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518384,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["business-days","c-sharp","datetime","datetimeoffset","datetimerange","exceptionless","range","time","timespan"],"created_at":"2024-11-05T16:05:31.026Z","updated_at":"2026-02-13T00:16:19.718Z","avatar_url":"https://github.com/exceptionless.png","language":"C#","readme":"# Exceptionless.DateTimeExtensions\n\n[![Build status](https://github.com/Exceptionless/Exceptionless.DateTimeExtensions/workflows/Build/badge.svg)](https://github.com/Exceptionless/Exceptionless.DateTimeExtensions/actions)\n[![NuGet Version](http://img.shields.io/nuget/v/Exceptionless.DateTimeExtensions.svg?style=flat)](https://www.nuget.org/packages/Exceptionless.DateTimeExtensions/)\n[![Discord](https://img.shields.io/discord/715744504891703319)](https://discord.gg/6HxgFCx)\n[![Donate](https://img.shields.io/badge/donorbox-donate-blue.svg)](https://donorbox.org/exceptionless?recurring=true)\n\nDateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods.\n\n## Getting Started (Development)\n\n[This package](https://www.nuget.org/packages/Exceptionless.DateTimeExtensions/) can be installed via the [NuGet package manager](https://docs.nuget.org/consume/Package-Manager-Dialog). If you need help, please contact us via in-app support or [open an issue](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/issues/new). We're always here to help if you have any questions!\n\n1. You will need to have [Visual Studio Code](https://code.visualstudio.com/) installed.\n2. Open the root folder.\n\n## Using DateTimeExtensions\n\nBelow is a small sampling of the things you can accomplish with DateTimeExtensions, so check it out!\n\n### Business Day\n\nQuickly calculate if a datetime is within your hours of business. Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/BusinessDayTests.cs) for more usage samples.\n\n```csharp\nvar date = DateTime.Now.StartOfDay().AddHours(8);\n\nvar day = new BusinessDay(date.Date.DayOfWeek,\n    date.Subtract(TimeSpan.FromHours(1)).TimeOfDay,\n    date.AddHours(1).TimeOfDay);\n\nbool isDay = day.IsBusinessDay(date);\n```\n\n### DateTime Ranges\n\nQuickly work with date ranges with support for Elasticsearch-style date math expressions and bracket notation. Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/DateTimeRangeTests.cs) for more usage samples.\n\n```csharp\n// Basic range parsing\nvar range = DateTimeRange.Parse(\"yesterday\", DateTime.Now);\nif (range.Contains(DateTime.Now.Subtract(TimeSpan.FromHours(6)))) {\n  //...\n}\n\n// Elasticsearch Date Math support with proper timezone handling\nvar elasticRange = DateTimeRange.Parse(\"2025-01-01T01:25:35Z||+3d/d\", DateTime.Now);\n// Supports timezone-aware operations: Z (UTC), +05:00, -08:00\n\n// Bracket notation support [start TO end]\nvar bracketRange = DateTimeRange.Parse(\"[2023-01-01 TO 2023-12-31]\", DateTime.Now);\n\n// Wildcard support for open-ended ranges\nvar wildcardRange = DateTimeRange.Parse(\"[2023-01-01 TO *]\", DateTime.Now); // From date to infinity\n```\n\n#### Date Math Features\n\nSupports full Elasticsearch date math syntax following [official specifications](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math):\n\n- **Anchors**: `now`, explicit dates with `||` separator\n- **Operations**: `+1d` (add), `-1h` (subtract), `/d` (round down)\n- **Units**: `y` (years), `M` (months), `w` (weeks), `d` (days), `h`/`H` (hours), `m` (minutes), `s` (seconds)\n- **Timezone Support**: Preserves explicit timezones (`Z`, `+05:00`, `-08:00`) or uses system timezone as fallback\n\nExamples:\n\n- `now+1h` - One hour from now\n- `now-1d/d` - Start of yesterday\n- `2025-01-01T01:25:35Z||+3d/d` - January 4th, 2025 (start of day) in UTC\n- `2023-06-15T14:30:00+05:00||+1M-2d` - One month minus 2 days from the specified date/time in +05:00 timezone\n\n### DateMath Utility\n\nFor applications that need standalone date math parsing without the range functionality, the `DateMath` utility class provides direct access to Elasticsearch date math expression parsing. Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/DateMathTests.cs) for more usage samples.\n\n```csharp\nusing Exceptionless.DateTimeExtensions;\n\n// Parse date math expressions with standard .NET conventions\nvar baseTime = DateTimeOffset.Now;\n\n// Parse method - throws ArgumentException on invalid input\nvar result = DateMath.Parse(\"now+1h\", baseTime);\nvar rounded = DateMath.Parse(\"now-1d/d\", baseTime, isUpperLimit: false); // Start of yesterday\n\n// TryParse method - returns bool for success/failure\nif (DateMath.TryParse(\"2023.06.15||+1M/d\", baseTime, false, out var parsed)) {\n    // Successfully parsed: June 15, 2023 + 1 month, rounded to start of day\n    Console.WriteLine($\"Parsed: {parsed:O}\");\n}\n\n// Upper limit behavior affects rounding\nvar startOfDay = DateMath.Parse(\"now/d\", baseTime, isUpperLimit: false); // 00:00:00\nvar endOfDay = DateMath.Parse(\"now/d\", baseTime, isUpperLimit: true);     // 23:59:59.999\n\n// Explicit dates with timezone preservation\nvar utcResult = DateMath.Parse(\"2025-01-01T01:25:35Z||+3d/d\", baseTime);\nvar offsetResult = DateMath.Parse(\"2023-06-15T14:30:00+05:00||+1M\", baseTime);\n```\n\n#### TimeZone-Aware DateMath\n\nThe `DateMath` utility also provides overloads that work directly with `TimeZoneInfo` for better timezone handling:\n\n```csharp\nusing Exceptionless.DateTimeExtensions;\n\n// Parse expressions using a specific timezone\nvar utcTimeZone = TimeZoneInfo.Utc;\nvar easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById(\"US/Eastern\");\n\n// \"now\" will use current time in the specified timezone\nvar utcResult = DateMath.Parse(\"now+1h\", utcTimeZone);\nvar easternResult = DateMath.Parse(\"now/d\", easternTimeZone, isUpperLimit: false);\n\n// TryParse with timezone\nif (DateMath.TryParse(\"now+2d-3h\", easternTimeZone, false, out var result)) {\n    Console.WriteLine($\"Eastern time result: {result:O}\");\n}\n\n// Dates without explicit timezone use the provided TimeZoneInfo\nvar localDate = DateMath.Parse(\"2023-06-15T14:30:00||+1M\", easternTimeZone);\n\n// Dates with explicit timezone are preserved regardless of TimeZoneInfo parameter\nvar preservedTz = DateMath.Parse(\"2023-06-15T14:30:00+05:00||+1M\", easternTimeZone);\n// Result will still have +05:00 offset, not Eastern time offset\n```\n\nThe `DateMath` utility supports the same comprehensive syntax as `DateTimeRange` but provides a simpler API for direct parsing operations.\n\n### TimeUnit\n\nQuickly work with time units. . Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/TimeUnitTests.cs) for more usage samples.\n\n```csharp\nTimeSpan oneNanosecond = TimeUnit.Parse(\"1nanos\");\nTimeSpan oneMicrosecond = TimeUnit.Parse(\"1micros\");\nTimeSpan oneMillisecond = TimeUnit.Parse(\"1ms\");\nTimeSpan oneSecond = TimeUnit.Parse(\"1s\");\nTimeSpan oneMinute = TimeUnit.Parse(\"1m\");\nTimeSpan oneHour = TimeUnit.Parse(\"1h\");\nTimeSpan oneDay = TimeUnit.Parse(\"1d\");\n```\n\n### DateTime Extension methods\n\nHelper methods that makes working with DateTimes easier.  Check out the [source](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/src/Exceptionless.DateTimeExtensions/DateTimeExtensions.cs) for all of the extension methods you can use.\n\n```csharp\nusing Exceptionless.DateTimeExtensions;\n\nDateTime.Now.ToApproximateAgeString(); // \"Just now\"\nvar time = DateTime.Now.StartOfMinute();\nvar lastWeek = DateTime.Now.LastWeek();\nvar nextWeek = DateTime.Now.NextWeek();\n```\n\n### DateTimeOffset Extension methods\n\nHelper methods that makes working with DateTimeOffsets easier.  Check out the [source](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/master/src/Exceptionless.DateTimeExtensions/DateTimeOffsetExtensions.cs) for all of the extension methods you can use.\n\n```csharp\nusing Exceptionless.DateTimeExtensions;\n\nDateTimeOffset.Now.ToApproximateAgeString(); // \"Just now\"\nvar startOfMonth = DateTimeOffset.Now.ToStartOfMonth();\nvar endOfMonth = DateTimeOffset.Now.ToEndOfMonth();\n```\n\n### Timespan Extension methods\n\nHelper methods that makes working with TimeSpans easier.  Check out the [source](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/src/Exceptionless.DateTimeExtensions/TimeSpanExtensions.cs) for all of the extension methods you can use.\n\n```csharp\nusing Exceptionless.DateTimeExtensions;\n\nvar years = TimeSpan.FromHours(6).GetYears();\nvar totalYears = TimeSpan.FromHours(6).GetTotalYears();\n```\n\n## Thanks to all the people who have contributed\n\n[![contributors](https://contributors-img.web.app/image?repo=exceptionless/Exceptionless.DateTimeExtensions)](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/graphs/contributors)\n","funding_links":["https://github.com/sponsors/exceptionless"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexceptionless%2Fexceptionless.datetimeextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexceptionless%2Fexceptionless.datetimeextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexceptionless%2Fexceptionless.datetimeextensions/lists"}