Ranges.Date 1.0.0

Extremely small library that provides a DateRange implementation

Install-Package Ranges.Date -Version 1.0.0
dotnet add package Ranges.Date --version 1.0.0
<PackageReference Include="Ranges.Date" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ranges.Date --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Ranges.Date

alt

An extremely small library that provides a Range implementation for dates (DateRange).

This is useful when you want to check if a DateTime is within a date range, e.g.

var xmas = new DateTime(2018, 12, 25);

if (range.Includes(xmas))
{
	// Merry Christmas
}

For more information see:

  • https://martinfowler.com/eaaDev/Range.html
  • https://stackoverflow.com/questions/4781611/how-to-know-if-a-datetime-is-between-a-daterange-in-c-sharp

Installation

nuget install Ranges.Date

Full Example

using System;
using Xunit;
using Ranges.Date;

namespace Ranges.Tests
{
    public class DateRangeTests
    {
        [Fact]
        public void Include_Works()
        {
            var start = new DateTime(2018, 2, 1);
            var end = new DateTime(2018, 2, 28);

            var range = new DateRange(start, end);

            Assert.False(range.Includes(new DateTime(2018, 1, 31)));
            Assert.True(range.Includes(new DateTime(2018, 2, 1)));
            Assert.True(range.Includes(new DateTime(2018, 2, 15)));
            Assert.True(range.Includes(new DateTime(2018, 2, 28)));
            Assert.False(range.Includes(new DateTime(2018, 3, 1)));
        }
    }
}

Ranges.Date

alt

An extremely small library that provides a Range implementation for dates (DateRange).

This is useful when you want to check if a DateTime is within a date range, e.g.

var xmas = new DateTime(2018, 12, 25);

if (range.Includes(xmas))
{
	// Merry Christmas
}

For more information see:

  • https://martinfowler.com/eaaDev/Range.html
  • https://stackoverflow.com/questions/4781611/how-to-know-if-a-datetime-is-between-a-daterange-in-c-sharp

Installation

nuget install Ranges.Date

Full Example

using System;
using Xunit;
using Ranges.Date;

namespace Ranges.Tests
{
    public class DateRangeTests
    {
        [Fact]
        public void Include_Works()
        {
            var start = new DateTime(2018, 2, 1);
            var end = new DateTime(2018, 2, 28);

            var range = new DateRange(start, end);

            Assert.False(range.Includes(new DateTime(2018, 1, 31)));
            Assert.True(range.Includes(new DateTime(2018, 2, 1)));
            Assert.True(range.Includes(new DateTime(2018, 2, 15)));
            Assert.True(range.Includes(new DateTime(2018, 2, 28)));
            Assert.False(range.Includes(new DateTime(2018, 3, 1)));
        }
    }
}

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 460 2/8/2018