Skip to content
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 TimeSpan.ToAge() extension method #1068

Merged
merged 3 commits into from
Feb 22, 2024
Merged

Conversation

louis-z
Copy link
Contributor

@louis-z louis-z commented May 8, 2021

  • Introduce the "TimeSpanHumanize_Age" resource, which indicates how to format a humanized TimeSpan as an age expression, when the two differ.
  • Add the Resources.TryGetResource() method, which tries to retrieve a resource for a given culture but without falling back on the default culture. This will allow us to define the "TimeSpanHumanize_Age" resource for en-US (aka the default culture), but not have other cultures fall back on that culture's resource.
  • Add DefaultFormatter.TimeSpanHumanize_Age(), which resorts to Resources.TryGetResource() to determine how to express a TimeSpan as age. If no resource is found for the given culture, it will simply output the standard humanized TimeSpan as is. (For other cultures where standard TimeSpan and age expression differ, such as many germanic languages, "TimeSpanHumanize_Age" will eventually need to be defined. However, this is outside the scope of this PR.)
  • Add tests for both English & 1 non-English (i.e. French) cultures

Fixes #968

Here is a checklist you should tick through before submitting a pull request:

  • Implementation is clean
  • Code adheres to the existing coding standards; e.g. no curlies for one-line blocks, no redundant empty lines between methods or code blocks, spaces rather than tabs, etc.
  • No Code Analysis warnings
  • There is proper unit test coverage
  • If the code is copied from StackOverflow (or a blog or OSS) full disclosure is included. That includes required license files and/or file headers explaining where the code came from with proper attribution
  • There are very few or no comments (because comments shouldn't be needed if you write clean code)
  • Xml documentation is added/updated for the addition/change
  • Your PR is (re)based on top of the latest commits from the dev branch (more info below)
  • Link to the issue(s) you're fixing from your PR description. Use fixes #<the issue number>
  • Readme is updated if you change an existing feature or add a new one
  • Run either build.cmd or build.ps1 and ensure there are no test failures

@hazzik
Copy link
Member

hazzik commented May 16, 2021

I think it would be better if the addition of " old" is added through the resource rather than logic checking for a specific culture. Because it is not strictly unique to English to add "old" modifier to describe the age. It seems applies to some Germanic languages as well:

  • Afrikaans/Dutch: twee jaar oud
  • Danish/Norwegian: to år gammel
  • Swedish: två år gammal
  • German: zwei Jahre alt

@hazzik
Copy link
Member

hazzik commented May 30, 2021

Ok, I've read some info about the hyphenated age. So, hyphenated age is an age adjective. These do exist in languages other than English, in my native Russian for example:

  • пятидесятилетний мужчина - fifty-years-old man.

"летний" here means "years-old" and "пятидесяти" - is an age component.

Similar for German: "fünfzigjähriger"

So I think: we could accept the ToAge() extension as is and give a little more thought to ToHyphenatedAge() extension.

The points to consider:

  • more appropriate name?
  • how to support different languages?

@clairernovotny
Copy link
Member

Why do we need both a new en and en-US resource package? One of them will be included in the main dlll as embedded resources; which one is it?

@louis-z
Copy link
Contributor Author

louis-z commented Jun 7, 2021

Why do we need both a new en and en-US resource package? One of them will be included in the main dlll as embedded resources; which one is it?

I must admit I wasn't too sure about that myself... But if I modify the PR according to what I proposed here, then this question will become irrelevant, right? 😄

@louis-z louis-z changed the title Add TimeSpan.ToAge() & ToHyphenatedAge() extension methods + tests Add TimeSpan.ToAge() extension method + tests Mar 22, 2022
@louis-z
Copy link
Contributor Author

louis-z commented Mar 22, 2022

Hey @clairernovotny & @hazzik

I finally decided to drop the implementation of the so-called hyphenated (aka noun or pre-noun modifier) age expression, as it was too controversial. Can we now agree on this simpler PR? If not, please advise so I may make the necessary changes to have this PR accepted and merged.

@louis-z
Copy link
Contributor Author

louis-z commented Feb 15, 2024

@SimonCropp, do you think I should resurrect this PR, at least in its simplified form (refer to this comment)?

@SimonCropp
Copy link
Collaborator

@louis-z yeah i think a simpler implementation with a subset would be easier to get in

should we close this one for now?

@hazzik
Copy link
Member

hazzik commented Feb 20, 2024

@louis-z could you please resolve conflicts and (re-)sign the cla?

@hazzik hazzik self-requested a review February 20, 2024 01:15
@hazzik hazzik changed the title Add TimeSpan.ToAge() extension method + tests Add TimeSpan.ToAge() extension method Feb 20, 2024
- Add tests for both English and 1 non-English (i.e. French) cultures
@louis-z
Copy link
Contributor Author

louis-z commented Feb 21, 2024

@louis-z yeah i think a simpler implementation with a subset would be easier to get in

should we close this one for now?

I rebased my branch, as per @hazzik's request. @SimonCropp, what do you think?

@SimonCropp
Copy link
Collaborator

@louis-z can you add an explanation of the feature to the readme

@louis-z
Copy link
Contributor Author

louis-z commented Feb 21, 2024

@louis-z can you add an explanation of the feature to the readme

Done

@hazzik hazzik merged commit 19c8013 into Humanizr:main Feb 22, 2024
3 checks passed
@hazzik hazzik added this to the v3.0 milestone Feb 22, 2024
@louis-z louis-z deleted the issue-968 branch February 23, 2024 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TimeSpan.Humanize should offer an "age" format
5 participants