-
Notifications
You must be signed in to change notification settings - Fork 967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ToOrdinalWords extension with gender overload #500
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 additions & 0 deletions
15
src/Humanizer.Tests.Shared/Localisation/de/DateToOrdinalWordsTests.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,15 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace Humanizer.Tests.Localisation.de | ||
{ | ||
[UseCulture("de")] | ||
public class DateToOrdinalWordsTests | ||
{ | ||
[Fact] | ||
public void OrdinalizeString() | ||
{ | ||
Assert.Equal("1. Januar 2015", new DateTime(2015, 1, 1).ToOrdinalWords()); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Humanizer.Tests.Shared/Localisation/en/DateToOrdinalWordsTests.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,22 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace Humanizer.Tests.Localisation.en | ||
{ | ||
public class DateToOrdinalWordsTests | ||
{ | ||
[UseCulture("en-GB")] | ||
[Fact] | ||
public void OrdinalizeStringGb() | ||
{ | ||
Assert.Equal("1st January 2015", new DateTime(2015, 1, 1).ToOrdinalWords()); | ||
} | ||
|
||
[UseCulture("en-US")] | ||
[Fact] | ||
public void OrdinalizeStringUs() | ||
{ | ||
Assert.Equal("January 1st, 2015", new DateTime(2015, 1, 1).ToOrdinalWords()); | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/Humanizer/Configuration/DateToOrdinalWordsConverterRegistry.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,13 @@ | ||
using Humanizer.Localisation.DateToOrdinalWords; | ||
namespace Humanizer.Configuration | ||
{ | ||
internal class DateToOrdinalWordsConverterRegistry : LocaliserRegistry<IDateToOrdinalWordConverter> | ||
{ | ||
public DateToOrdinalWordsConverterRegistry() : base(new DefaultDateToOrdinalWordConverter()) | ||
{ | ||
Register("en-UK", new DefaultDateToOrdinalWordConverter()); | ||
Register("de", new DefaultDateToOrdinalWordConverter()); | ||
Register("en-US", new UsDateToOrdinalWordsConverter()); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using System; | ||
using System.Globalization; | ||
using Humanizer.Configuration; | ||
|
||
namespace Humanizer | ||
{ | ||
/// <summary> | ||
/// Humanizes DateTime into human readable sentence | ||
/// </summary> | ||
public static class DateToOrdinalWordsExtensions | ||
{ | ||
/// <summary> | ||
/// Turns the provided date into ordinal words | ||
/// </summary> | ||
/// <param name="input">The date to be made into ordinal words</param> | ||
/// <returns>The date in ordinal words</returns> | ||
public static string ToOrdinalWords(this DateTime input) | ||
{ | ||
return Configurator.DateToOrdinalWordsConverter.Convert(input); | ||
} | ||
/// <summary> | ||
/// Turns the provided date into ordinal words | ||
/// </summary> | ||
/// <param name="input">The date to be made into ordinal words</param> | ||
/// <param name="grammaticalCase">The grammatical case to use for output words</param> | ||
/// <returns>The date in ordinal words</returns> | ||
public static string ToOrdinalWords(this DateTime input, GrammaticalCase grammaticalCase) | ||
{ | ||
return Configurator.DateToOrdinalWordsConverter.Convert(input, grammaticalCase); | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/Humanizer/Localisation/DateToOrdinalWords/DefaultDateToOrdinalWordConverter.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,19 @@ | ||
using System; | ||
|
||
namespace Humanizer.Localisation.DateToOrdinalWords | ||
{ | ||
internal class DefaultDateToOrdinalWordConverter : IDateToOrdinalWordConverter | ||
{ | ||
|
||
public virtual string Convert(DateTime date) | ||
{ | ||
return date.Day.Ordinalize() + date.ToString(" MMMM yyyy"); | ||
} | ||
|
||
public virtual string Convert(DateTime date, GrammaticalCase grammaticalCase) | ||
{ | ||
return Convert(date); | ||
} | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Humanizer/Localisation/DateToOrdinalWords/IDateToOrdinalWordConverter.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,25 @@ | ||
using System; | ||
|
||
namespace Humanizer.Localisation.DateToOrdinalWords | ||
{ | ||
/// <summary> | ||
/// The interface used to localise the ToOrdinalWords method. | ||
/// </summary> | ||
public interface IDateToOrdinalWordConverter | ||
{ | ||
/// <summary> | ||
/// Converts the date to Ordinal Words | ||
/// </summary> | ||
/// <param name="date"></param> | ||
/// <returns></returns> | ||
string Convert(DateTime 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(DateTime date, GrammaticalCase grammaticalCase); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Humanizer/Localisation/DateToOrdinalWords/UsDateToOrdinalWordsConverter.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,12 @@ | ||
using System; | ||
|
||
namespace Humanizer.Localisation.DateToOrdinalWords | ||
{ | ||
internal class UsDateToOrdinalWordsConverter : DefaultDateToOrdinalWordConverter | ||
{ | ||
public override string Convert(DateTime date) | ||
{ | ||
return date.ToString("MMMM ") + date.Day.Ordinalize() + date.ToString(", yyyy"); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes to this file should be reverted, as they only formatting and add no value to the feature.