-
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
Minimize verbosity of Timespan formatting. #571
Comments
@rlightner Can you please show a code example of what you are doing? Thank you. |
@darylbehrens Who was that directed at? |
This comment was marked as off-topic.
This comment was marked as off-topic.
I would like to use "m" instead of "mins or minutes" 1y, 2m, 4d, 20h, 59m, 12s |
I am thinking of adding the functionality of using short(er) variants. e.g.
or
possibly giving public enum TimeSpanFormat
{
Normal,
Short, // 1 yr, 2 mos, 2 days, 5 hrs, 56 mins, 12 secs - Original request?
Single, // 1y, 2m, 2d, 4h, 56m, 12s
} I guess these could be as separate keys in the resources, with falling back to the previous if one is not found? |
This would be awesome to have for DateTimeOffset as well: |
I would love to work on this issue. One question though, how would we deal with all the languages? Let's say we had a new parameter indicating the format, and the new key did not exist for a particular language. Would it revert to the default format? |
If you look at the current language support you will find 145 entries:
All of these have to be shortened so there will be 145 entries for If you have a closer look it is possible to get rid of all the I would suggest to discuss the design of the localization before we add a few 100 more entries to the resource files. |
One year passed, nothing moved on (about this). Any plan to actually support this? |
I would like to work on this issue. Can you please assign it to me? |
It's yours.... GitHub only allows assignments to organization members, but anyone looking should see this thread. |
I've started working on this issue. I like @michal-ciechan's idea of introducing a format enum |
Hey @ZacharyCouchman did you get anywhere on this by any chance? |
Any news about it? |
This would be awesome indeed! |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I'll be happy to take a PR that adds support for this feature if someone wants to take it on. |
What happened to this commit? 8373d2f |
I have no idea and haven't looked. All I can see is that the PR looked like it needed fixing: #990. If someone wants to finish it off, that'd be great! |
Oh okay. |
It's real pity it has not been implemented yet, not even for English :-( |
It would be amazing if this could be part of the v3 milestone somehow! |
Would love to see this in the near future, as well. |
I just did this for my purposes with some regex. There's a sample program below that I'd love to claim credit for, but that goes to Copilot! using Humanizer;
using System.Globalization;
using System.Text.RegularExpressions;
TimeSpan t = new DateTime(2024, 3, 25) - new DateTime(2024, 2, 13);
CultureInfo culture = new("de-DE");
var longString = t.Humanize(3, culture, maxUnit: Humanizer.Localisation.TimeUnit.Month);
string pattern = @"(\d+)\s+(\w)\w*";
string shortString = Regex.Replace(longString, pattern, ReplaceWithFirstLetter);
Console.WriteLine("Long timespan: " + longString);
Console.WriteLine("Short timespan: " + shortString);
static string ReplaceWithFirstLetter(Match match)
{
var digits = match.Groups[1].Value;
var firstLetter = match.Groups[2].Value;
return $"{digits}{firstLetter}";
} And here's the output:
|
Is there a way to use duration abbreviations when Humanizing a TimeSpan? I'd like to use mins instead of minutes etc..
The text was updated successfully, but these errors were encountered: