-
Notifications
You must be signed in to change notification settings - Fork 966
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
Added optional Culture parameter to DateTime.Humanize #286
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
530b2f5
Added option Culture parameter to DateTime.Humanize
adea66c
Fixed formatting
3dde23d
Reverted changes to DateHumanize (testing with both implicit & explic…
abbc23e
Added a test for getting culture-specific resource with explicitly sp…
0788a38
Fixed method's comment
ed4121c
Only using optional "Culture" parameter for public methods
1f8ad39
+ unit tests for DateTime.Humanize with explicit culure
3bb7fec
Updated readme to reflect new "culture" parameter for DateTime.Humanize
464e7b4
Updated release_notes to reflect new "culture" parameter for DateTime…
70f8f72
Added optional Culture parameter to TimeSpan.Humanize
c8bcd87
1) Made Date/Time formatters to own "culture";
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
using Humanizer.Localisation; | ||
using System.Globalization; | ||
using Humanizer.Localisation; | ||
using Xunit; | ||
|
||
namespace Humanizer.Tests.Localisation | ||
{ | ||
public class ResourcesTests | ||
{ | ||
[Fact] | ||
public void CanGetCultureSpecificTranslations() | ||
public void CanGetCultureSpecificTranslationsWithImplicitCulture() | ||
{ | ||
using (new AmbientCulture("ro")) | ||
{ | ||
var format = Resources.GetResource("DateHumanize_MultipleYearsAgo_Above20"); | ||
Assert.Equal("acum {0} de ani", format); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void CanGetCultureSpecificTranslationsWithExplicitCulture() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
{ | ||
var format = Resources.GetResource("DateHumanize_MultipleYearsAgo_Above20", new CultureInfo("ro")); | ||
Assert.Equal("acum {0} de ani", format); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -14,15 +14,15 @@ public DateHumanizeTests() : base("nl-NL") { } | |
[InlineData(-1, "gisteren")] | ||
public void DaysAgo(int days, string expected) | ||
{ | ||
Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); | ||
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing these. |
||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "2 uur geleden")] | ||
[InlineData(-1, "één uur geleden")] | ||
public void HoursAgo(int hours, string expected) | ||
{ | ||
Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); | ||
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
|
@@ -39,23 +39,23 @@ public void MinutesAgo(int minutes, string expected) | |
[InlineData(-1, "één maand geleden")] | ||
public void MonthsAgo(int months, string expected) | ||
{ | ||
Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); | ||
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "2 seconden geleden")] | ||
[InlineData(-1, "één seconde geleden")] | ||
public void SecondsAgo(int seconds, string expected) | ||
{ | ||
Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); | ||
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "2 jaar geleden")] | ||
[InlineData(-1, "één jaar geleden")] | ||
public void YearsAgo(int years, string expected) | ||
{ | ||
Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); | ||
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.
This is exactly what I meant. Thanks.