-
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
Detailed time span #65
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bde7e70
Renamed TimeSpanHumanizeTests files/class for consistency
MehdiK 7605bb5
Changed TimeSpan tests to Theories
MehdiK 0d08fe8
Added precision to TimeSpan Humanize - #29 #56
MehdiK 4b91a6f
refactored TimeSpan Humanize
MehdiK 5158762
Added TimeSpan precision to readme
MehdiK 4bf786d
Fixed typo - precision
MehdiK 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
5 changes: 2 additions & 3 deletions
5
...er.Tests/Localisation/ar/TimeSpanTests.cs → .../Localisation/ar/TimeSpanHumanizeTests.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
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 was deleted.
Oops, something went wrong.
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,114 @@ | ||
using System; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests | ||
{ | ||
public class TimeSpanHumanizeTests : AmbientCulture | ||
{ | ||
public TimeSpanHumanizeTests() : base("en-US") { } | ||
|
||
[Theory] | ||
[InlineData(14, "2 weeks")] | ||
[InlineData(7, "1 week")] | ||
public void Weeks(int days, string expected) | ||
{ | ||
var actual = TimeSpan.FromDays(days).Humanize(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(6, "6 days")] | ||
[InlineData(2, "2 days")] | ||
[InlineData(1, "1 day")] | ||
public void Days(int days, string expected) | ||
{ | ||
var actual = TimeSpan.FromDays(days).Humanize(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2, "2 hours")] | ||
[InlineData(1, "1 hour")] | ||
public void Hours(int hours, string expected) | ||
{ | ||
var actual = TimeSpan.FromHours(hours).Humanize(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2, "2 minutes")] | ||
[InlineData(1, "1 minute")] | ||
public void Minutes(int minutes, string expected) | ||
{ | ||
var actual = TimeSpan.FromMinutes(minutes).Humanize(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(135, "2 minutes")] | ||
[InlineData(60, "1 minute")] | ||
[InlineData(2, "2 seconds")] | ||
[InlineData(1, "1 second")] | ||
public void Seconds(int seconds, string expected) | ||
{ | ||
var actual = TimeSpan.FromSeconds(seconds).Humanize(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2500, "2 seconds")] | ||
[InlineData(1400, "1 second")] | ||
[InlineData(2, "2 milliseconds")] | ||
[InlineData(1, "1 millisecond")] | ||
public void Milliseconds(int ms, string expected) | ||
{ | ||
var actual = TimeSpan.FromMilliseconds(ms).Humanize(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, 3, "no time")] | ||
[InlineData(0, 2, "no time")] | ||
[InlineData(10, 2, "10 milliseconds")] | ||
[InlineData(1400, 2, "1 second, 400 milliseconds")] | ||
[InlineData(2500, 2, "2 seconds, 500 milliseconds")] | ||
[InlineData(120000, 2, "2 minutes")] | ||
[InlineData(62000, 2, "1 minute, 2 seconds")] | ||
[InlineData(62020, 2, "1 minute, 2 seconds")] | ||
[InlineData(62020, 3, "1 minute, 2 seconds, 20 milliseconds")] | ||
[InlineData(3600020, 4, "1 hour, 20 milliseconds")] | ||
[InlineData(3600020, 3, "1 hour, 20 milliseconds")] | ||
[InlineData(3600020, 2, "1 hour, 20 milliseconds")] | ||
[InlineData(3600020, 1, "1 hour")] | ||
[InlineData(3603001, 2, "1 hour, 3 seconds")] | ||
[InlineData(3603001, 3, "1 hour, 3 seconds, 1 millisecond")] | ||
[InlineData(86400000, 3, "1 day")] | ||
[InlineData(86400000, 2, "1 day")] | ||
[InlineData(86400000, 1, "1 day")] | ||
[InlineData(86401000, 1, "1 day")] | ||
[InlineData(86401000, 2, "1 day, 1 second")] | ||
[InlineData(86401200, 2, "1 day, 1 second")] | ||
[InlineData(86401200, 3, "1 day, 1 second, 200 milliseconds")] | ||
[InlineData(1296000000, 1, "2 weeks")] | ||
[InlineData(1296000000, 2, "2 weeks, 1 day")] | ||
[InlineData(1299600000, 2, "2 weeks, 1 day")] | ||
[InlineData(1299600000, 3, "2 weeks, 1 day, 1 hour")] | ||
[InlineData(1299630020, 3, "2 weeks, 1 day, 1 hour")] | ||
[InlineData(1299630020, 4, "2 weeks, 1 day, 1 hour, 30 seconds")] | ||
[InlineData(1299630020, 5, "2 weeks, 1 day, 1 hour, 30 seconds, 20 milliseconds")] | ||
public void TimeSpanWithPrecesion(int milliseconds, int precesion, string expected) | ||
{ | ||
var actual = TimeSpan.FromMilliseconds(milliseconds).Humanize(precesion); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Fact] | ||
public void NoTime() | ||
{ | ||
var noTime = TimeSpan.Zero; | ||
var actual = noTime.Humanize(); | ||
Assert.Equal("no time", actual); | ||
} | ||
} | ||
} |
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.
Weird, what is __value?
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.
I saw that too. It looks like a bug in ApiApprover for enums. I will check out ApiApprover to see if I can find and fix it.