Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/exceptionless/Exceptionless.DateTimeExtensions
DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods
https://github.com/exceptionless/Exceptionless.DateTimeExtensions
business-days c-sharp datetime datetimeoffset datetimerange exceptionless range time timespan
Last synced: 3 months ago
JSON representation
DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods
- Host: GitHub
- URL: https://github.com/exceptionless/Exceptionless.DateTimeExtensions
- Owner: exceptionless
- License: apache-2.0
- Created: 2014-11-05T07:09:47.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T23:20:24.000Z (6 months ago)
- Last Synced: 2024-09-19T01:38:56.827Z (4 months ago)
- Topics: business-days, c-sharp, datetime, datetimeoffset, datetimerange, exceptionless, range, time, timespan
- Language: C#
- Homepage: https://www.nuget.org/packages/Exceptionless.DateTimeExtensions/
- Size: 248 KB
- Stars: 238
- Watchers: 11
- Forks: 27
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-csharp - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various `DateTime`, `DateTimeOffset`, `TimeSpan` extension methods. (Datetime)
- awesome-dotnet-cn - Exceptionless.DateTimeExtensions - 时间范围、工作日和各种各样的`DateTime`、`DateTimeOffset`、`TimeSpan`扩展方法 (日期)
- awesome-dotnet-core - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods. (Frameworks, Libraries and Tools / Date and Time)
- awesome-dotnet - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various `DateTime`, `DateTimeOffset`, `TimeSpan` extension methods. (Datetime)
- awesome-dot-dev - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various `DateTime`, `DateTimeOffset`, `TimeSpan` extension methods. (Datetime)
- awsome-dotnet - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various `DateTime`, `DateTimeOffset`, `TimeSpan` extension methods. (Datetime)
- fucking-awesome-dotnet-core - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods. (Frameworks, Libraries and Tools / Date and Time)
- awesome-dotnet - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various `DateTime`, `DateTimeOffset`, `TimeSpan` extension methods. (Datetime)
- awesome-dotnet-core - Exceptionless.DateTimeExtensions - DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods. (Frameworks, Libraries and Tools / Date and Time)
- awesome-dotnet-core - Exceptionless.DateTimeExtensions - DateTimeRange,工作日和各种DateTime,DateTimeOffset,TimeSpan扩展方法。 (框架, 库和工具 / 日期和时间)
README
# Exceptionless.DateTimeExtensions
[![Build status](https://github.com/Exceptionless/Exceptionless.DateTimeExtensions/workflows/Build/badge.svg)](https://github.com/Exceptionless/Exceptionless.DateTimeExtensions/actions)
[![NuGet Version](http://img.shields.io/nuget/v/Exceptionless.DateTimeExtensions.svg?style=flat)](https://www.nuget.org/packages/Exceptionless.DateTimeExtensions/)
[![Discord](https://img.shields.io/discord/715744504891703319)](https://discord.gg/6HxgFCx)
[![Donate](https://img.shields.io/badge/donorbox-donate-blue.svg)](https://donorbox.org/exceptionless?recurring=true)DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods.
## Getting Started (Development)
[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!
1. You will need to have [Visual Studio Code](https://code.visualstudio.com/) installed.
2. Open the root folder.## Using DateTimeExtensions
Below is a small sampling of the things you can accomplish with DateTimeExtensions, so check it out!
### Business Day
Quickly 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.
```csharp
var date = DateTime.Now.StartOfDay().AddHours(8);var day = new BusinessDay(date.Date.DayOfWeek,
date.Subtract(TimeSpan.FromHours(1)).TimeOfDay,
date.AddHours(1).TimeOfDay);bool isDay = day.IsBusinessDay(date);
```### DateTime Ranges
Quickly work with date ranges. . Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/DateTimeRangeTests.cs) for more usage samples.
```csharp
var range = DateTimeRange.Parse("yesterday", DateTime.Now);
if (range.Contains(DateTime.Now.Subtract(TimeSpan.FromHours(6)))) {
//...
}
```### TimeUnit
Quickly 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.
```csharp
TimeSpan oneNanosecond = TimeUnit.Parse("1nanos");
TimeSpan oneMicrosecond = TimeUnit.Parse("1micros");
TimeSpan oneMillisecond = TimeUnit.Parse("1ms");
TimeSpan oneSecond = TimeUnit.Parse("1s");
TimeSpan oneMinute = TimeUnit.Parse("1m");
TimeSpan oneHour = TimeUnit.Parse("1h");
TimeSpan oneDay = TimeUnit.Parse("1d");
```### DateTime Extension methods
Helper 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.
```csharp
using Exceptionless.DateTimeExtensions;DateTime.Now.ToApproximateAgeString(); // "Just now"
var time = DateTime.Now.StartOfMinute();
var lastWeek = DateTime.Now.LastWeek();
var nextWeek = DateTime.Now.NextWeek();
```### DateTimeOffset Extension methods
Helper 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.
```csharp
using Exceptionless.DateTimeExtensions;DateTimeOffset.Now.ToApproximateAgeString(); // "Just now"
var startOfMonth = DateTimeOffset.Now.ToStartOfMonth();
var endOfMonth = DateTimeOffset.Now.ToEndOfMonth();
```### Timespan Extension methods
Helper 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.
```csharp
using Exceptionless.DateTimeExtensions;var years = TimeSpan.FromHours(6).GetYears();
var totalYears = TimeSpan.FromHours(6).GetTotalYears();
```## Thanks to all the people who have contributed
[![contributors](https://contributors-img.web.app/image?repo=exceptionless/Exceptionless.DateTimeExtensions)](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/graphs/contributors)