Skip to content

Commit

Permalink
Add DateOnly support for FluentDate
Browse files Browse the repository at this point in the history
  • Loading branch information
clairernovotny committed Jun 7, 2021
1 parent 9c98ce8 commit f2de33d
Show file tree
Hide file tree
Showing 15 changed files with 9,634 additions and 4,326 deletions.
44 changes: 44 additions & 0 deletions src/Humanizer.Tests.Shared/FluentDate/InDateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#if NET6_0_OR_GREATER

using System;
using Xunit;

namespace Humanizer.Tests.FluentDate
{
public class InDateTests
{
[Fact]
public void InJanuary()
{
Assert.Equal(new DateOnly(DateTime.Now.Year, 1, 1), InDate.January);
}

[Fact]
public void InJanuaryOf2009()
{
Assert.Equal(new DateOnly(2009, 1, 1), InDate.JanuaryOf(2009));
}

[Fact]
public void InFebruary()
{
Assert.Equal(new DateOnly(DateTime.Now.Year, 2, 1), InDate.February);
}

[Fact]
public void InTheYear()
{
Assert.Equal(new DateOnly(2009, 1, 1), InDate.TheYear(2009));
}

[Fact]
public void InFiveDays()
{
var baseDate = OnDate.January.The21st;
var date = InDate.Five.DaysFrom(baseDate);
Assert.Equal(baseDate.AddDays(5), date);
}
}
}
#endif

30 changes: 30 additions & 0 deletions src/Humanizer.Tests.Shared/FluentDate/OnDateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if NET6_0_OR_GREATER

using System;
using Xunit;

namespace Humanizer.Tests.FluentDate
{
public class OnDateTests
{
[Fact]
public void OnJanuaryThe23rd()
{
Assert.Equal(new DateOnly(DateTime.Now.Year, 1, 23), OnDate.January.The23rd);
}

[Fact]
public void OnDecemberThe4th()
{
Assert.Equal(new DateOnly(DateTime.Now.Year, 12, 4), OnDate.December.The4th);
}

[Fact]
public void OnFebruaryThe()
{
Assert.Equal(new DateOnly(DateTime.Now.Year, 2, 11), OnDate.February.The(11));
}
}
}

#endif
2 changes: 2 additions & 0 deletions src/Humanizer.Tests.Shared/Humanizer.Tests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<Compile Include="$(MSBuildThisFileDirectory)CollectionHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DateHumanize.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DateHumanizeDefaultStrategyTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FluentDate\InDateTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FluentDate\OnDateTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TimeOnlyHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DateTimeHumanizePrecisionStrategyTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DateOnlyHumanizeTests.cs" />
Expand Down

Large diffs are not rendered by default.

196 changes: 98 additions & 98 deletions src/Humanizer/FluentDate/In.Months.cs
Original file line number Diff line number Diff line change
@@ -1,201 +1,201 @@


using System;

namespace Humanizer
{
public partial class In
{

/// <summary>
/// Returns 1st of January of the current year
/// </summary>
public static DateTime January
{
get { return new DateTime(DateTime.UtcNow.Year, 1, 1); }
}
public static DateTime January
{
get { return new DateTime(DateTime.UtcNow.Year, 1, 1); }
}

/// <summary>
/// Returns 1st of January of the year passed in
/// </summary>
public static DateTime JanuaryOf(int year)
{
return new DateTime(year, 1, 1);
}

{
return new DateTime(year, 1, 1);
}
/// <summary>
/// Returns 1st of February of the current year
/// </summary>
public static DateTime February
{
get { return new DateTime(DateTime.UtcNow.Year, 2, 1); }
}
public static DateTime February
{
get { return new DateTime(DateTime.UtcNow.Year, 2, 1); }
}

/// <summary>
/// Returns 1st of February of the year passed in
/// </summary>
public static DateTime FebruaryOf(int year)
{
return new DateTime(year, 2, 1);
}

{
return new DateTime(year, 2, 1);
}
/// <summary>
/// Returns 1st of March of the current year
/// </summary>
public static DateTime March
{
get { return new DateTime(DateTime.UtcNow.Year, 3, 1); }
}
public static DateTime March
{
get { return new DateTime(DateTime.UtcNow.Year, 3, 1); }
}

/// <summary>
/// Returns 1st of March of the year passed in
/// </summary>
public static DateTime MarchOf(int year)
{
return new DateTime(year, 3, 1);
}

{
return new DateTime(year, 3, 1);
}
/// <summary>
/// Returns 1st of April of the current year
/// </summary>
public static DateTime April
{
get { return new DateTime(DateTime.UtcNow.Year, 4, 1); }
}
public static DateTime April
{
get { return new DateTime(DateTime.UtcNow.Year, 4, 1); }
}

/// <summary>
/// Returns 1st of April of the year passed in
/// </summary>
public static DateTime AprilOf(int year)
{
return new DateTime(year, 4, 1);
}

{
return new DateTime(year, 4, 1);
}
/// <summary>
/// Returns 1st of May of the current year
/// </summary>
public static DateTime May
{
get { return new DateTime(DateTime.UtcNow.Year, 5, 1); }
}
public static DateTime May
{
get { return new DateTime(DateTime.UtcNow.Year, 5, 1); }
}

/// <summary>
/// Returns 1st of May of the year passed in
/// </summary>
public static DateTime MayOf(int year)
{
return new DateTime(year, 5, 1);
}

{
return new DateTime(year, 5, 1);
}
/// <summary>
/// Returns 1st of June of the current year
/// </summary>
public static DateTime June
{
get { return new DateTime(DateTime.UtcNow.Year, 6, 1); }
}
public static DateTime June
{
get { return new DateTime(DateTime.UtcNow.Year, 6, 1); }
}

/// <summary>
/// Returns 1st of June of the year passed in
/// </summary>
public static DateTime JuneOf(int year)
{
return new DateTime(year, 6, 1);
}

{
return new DateTime(year, 6, 1);
}
/// <summary>
/// Returns 1st of July of the current year
/// </summary>
public static DateTime July
{
get { return new DateTime(DateTime.UtcNow.Year, 7, 1); }
}
public static DateTime July
{
get { return new DateTime(DateTime.UtcNow.Year, 7, 1); }
}

/// <summary>
/// Returns 1st of July of the year passed in
/// </summary>
public static DateTime JulyOf(int year)
{
return new DateTime(year, 7, 1);
}

{
return new DateTime(year, 7, 1);
}
/// <summary>
/// Returns 1st of August of the current year
/// </summary>
public static DateTime August
{
get { return new DateTime(DateTime.UtcNow.Year, 8, 1); }
}
public static DateTime August
{
get { return new DateTime(DateTime.UtcNow.Year, 8, 1); }
}

/// <summary>
/// Returns 1st of August of the year passed in
/// </summary>
public static DateTime AugustOf(int year)
{
return new DateTime(year, 8, 1);
}

{
return new DateTime(year, 8, 1);
}
/// <summary>
/// Returns 1st of September of the current year
/// </summary>
public static DateTime September
{
get { return new DateTime(DateTime.UtcNow.Year, 9, 1); }
}
public static DateTime September
{
get { return new DateTime(DateTime.UtcNow.Year, 9, 1); }
}

/// <summary>
/// Returns 1st of September of the year passed in
/// </summary>
public static DateTime SeptemberOf(int year)
{
return new DateTime(year, 9, 1);
}

{
return new DateTime(year, 9, 1);
}
/// <summary>
/// Returns 1st of October of the current year
/// </summary>
public static DateTime October
{
get { return new DateTime(DateTime.UtcNow.Year, 10, 1); }
}
public static DateTime October
{
get { return new DateTime(DateTime.UtcNow.Year, 10, 1); }
}

/// <summary>
/// Returns 1st of October of the year passed in
/// </summary>
public static DateTime OctoberOf(int year)
{
return new DateTime(year, 10, 1);
}

{
return new DateTime(year, 10, 1);
}
/// <summary>
/// Returns 1st of November of the current year
/// </summary>
public static DateTime November
{
get { return new DateTime(DateTime.UtcNow.Year, 11, 1); }
}
public static DateTime November
{
get { return new DateTime(DateTime.UtcNow.Year, 11, 1); }
}

/// <summary>
/// Returns 1st of November of the year passed in
/// </summary>
public static DateTime NovemberOf(int year)
{
return new DateTime(year, 11, 1);
}

{
return new DateTime(year, 11, 1);
}
/// <summary>
/// Returns 1st of December of the current year
/// </summary>
public static DateTime December
{
get { return new DateTime(DateTime.UtcNow.Year, 12, 1); }
}
public static DateTime December
{
get { return new DateTime(DateTime.UtcNow.Year, 12, 1); }
}

/// <summary>
/// Returns 1st of December of the year passed in
/// </summary>
public static DateTime DecemberOf(int year)
{
return new DateTime(year, 12, 1);
}
}
{
return new DateTime(year, 12, 1);
}
}
}
Loading

0 comments on commit f2de33d

Please sign in to comment.