-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for DateOnly to ordinal words
- Loading branch information
1 parent
f2de33d
commit b2491d8
Showing
10 changed files
with
162 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Humanizer/Configuration/DateOnlyToOrdinalWordsConverterRegistry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
using Humanizer.Localisation.DateToOrdinalWords; | ||
namespace Humanizer.Configuration | ||
{ | ||
internal class DateOnlyToOrdinalWordsConverterRegistry : LocaliserRegistry<IDateOnlyToOrdinalWordConverter> | ||
{ | ||
public DateOnlyToOrdinalWordsConverterRegistry() : base(new DefaultDateOnlyToOrdinalWordConverter()) | ||
{ | ||
Register("en-UK", new DefaultDateOnlyToOrdinalWordConverter()); | ||
Register("de", new DefaultDateOnlyToOrdinalWordConverter()); | ||
Register("en-US", new UsDateOnlyToOrdinalWordsConverter()); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Humanizer/Localisation/DateToOrdinalWords/DefaultDateOnlyToOrdinalWordConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
using System; | ||
|
||
namespace Humanizer.Localisation.DateToOrdinalWords | ||
{ | ||
internal class DefaultDateOnlyToOrdinalWordConverter : IDateOnlyToOrdinalWordConverter | ||
{ | ||
|
||
public virtual string Convert(DateOnly date) | ||
{ | ||
return date.Day.Ordinalize() + date.ToString(" MMMM yyyy"); | ||
} | ||
|
||
public virtual string Convert(DateOnly date, GrammaticalCase grammaticalCase) | ||
{ | ||
return Convert(date); | ||
} | ||
|
||
} | ||
} | ||
|
||
#endif |
28 changes: 28 additions & 0 deletions
28
src/Humanizer/Localisation/DateToOrdinalWords/IDateOnlyToOrdinalWordConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
using System; | ||
|
||
namespace Humanizer.Localisation.DateToOrdinalWords | ||
{ | ||
/// <summary> | ||
/// The interface used to localise the ToOrdinalWords method. | ||
/// </summary> | ||
public interface IDateOnlyToOrdinalWordConverter | ||
{ | ||
/// <summary> | ||
/// Converts the date to Ordinal Words | ||
/// </summary> | ||
/// <param name="date"></param> | ||
/// <returns></returns> | ||
string Convert(DateOnly date); | ||
|
||
/// <summary> | ||
/// Converts the date to Ordinal Words using the provided grammatical case | ||
/// </summary> | ||
/// <param name="date"></param> | ||
/// <param name="grammaticalCase"></param> | ||
/// <returns></returns> | ||
string Convert(DateOnly date, GrammaticalCase grammaticalCase); | ||
} | ||
} | ||
#endif |
14 changes: 14 additions & 0 deletions
14
src/Humanizer/Localisation/DateToOrdinalWords/UsDateOnlyToOrdinalWordsConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#if NET6_0_OR_GREATER | ||
using System; | ||
|
||
namespace Humanizer.Localisation.DateToOrdinalWords | ||
{ | ||
internal class UsDateOnlyToOrdinalWordsConverter : DefaultDateOnlyToOrdinalWordConverter | ||
{ | ||
public override string Convert(DateOnly date) | ||
{ | ||
return date.ToString("MMMM ") + date.Day.Ordinalize() + date.ToString(", yyyy"); | ||
} | ||
} | ||
} | ||
#endif |