-
Notifications
You must be signed in to change notification settings - Fork 965
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
DateTime Humanizer : returns hours, days, months, but not weeks #765
Comments
@onovotny (sorry for the tag, let me know if I should stop tagging you), I think I'm going to need your input on this. The method for choosing which unit is returned is calculated in DefaultHumanize() within DateTimeHumanizeAlgorithms.cs here:
Currently the parts of the algorithm we are interested in work as described below (The third line is the bit we could change): If it is less than 24 hours, return in hours. The less than 28 days has the following code: if (ts.TotalDays < 28)
{
return formatter.DateHumanize(TimeUnit.Day, tense, ts.Days);
} We could fix this issue by changing that code to look like the below to return Weeks for the area between 6 days and 28 days (exclusive): if (ts.TotalDays < 7)
{
return formatter.DateHumanize(TimeUnit.Day, tense, ts.Days);
}
if (ts.TotalDays < 28)
{
return formatter.DateHumanize(TimeUnit.Week, tense, ts.Days);
} This would then return the expected result of "7 days from now". BUT, if this code is changed now we get a lovely little error of This is because there is no resource for "Weeks from now". We could add one, but all the other localized languages would be missing this (I'm not sure what happens if it isn't there for a language). How do you want to go forward with this (@onovotny). Is adding a new resource something you would want to wait until vNext for? As far as I can see no logic is really changed, we just return weeks instead of days for any values between 6 and 28 days (exclusive). Alex |
We can add a new resource in english, and solicit help from the community to fill in the blank. |
It looks like a fix has been done a long time ago, but the PR has never been merged. |
I would also be intrested in this change. Is there any plan to change it? |
Why does DateTime Humanizer return a number of hours, days, months, but never return a number of weeks ?
It does not seems consistent with TimeSpan Humanizer.
Example :
TimeSpan.FromDays(7).Humanize() => "1 week"
DateTime.UtcNow.AddDays(7).Humanize() => "7 days from now" (instead of "1 week from now")
The text was updated successfully, but these errors were encountered: