Humanizer icon indicating copy to clipboard operation
Humanizer copied to clipboard

time span format verbosity

Open neilboyd opened this issue 2 years ago • 5 comments

Fixes #571 Fixes #642 Fixes #969

Based on HeadingStyle (although that's inconsistent with WordForm).

Replace timeSpan.Humanize(toWords: true) with timeSpan.Humanize(timeSpanStyle: TimeSpanStyle.Words). This is a breaking change.

timeSpan.Humanize() remains unchanged, although the optional parameter has changed from toWords: false to timeSpanStyle: TimeSpanStyle.Full.

Added timeSpan.Humanize(timeSpanStyle: TimeSpanStyle.Abbreviated) and timeSpan.Humanize(timeSpanStyle: TimeSpanStyle.Short). These return English regardless of the locale.

Question: how do you normally handle translation in this project? I could add tests for every language, where Abbreviated and Short return English for every locale, or not, or I could create translations (and tests) for every language (I could make a best guess for Latin and Cyrillic alphabets, but not the others).

Question: should we use uppercase for Y, D, W? (M is already uppercase in order to disambiguate with minute)


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

  • [x] Implementation is clean
  • [x] 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.
  • [x] No Code Analysis warnings
  • [x] 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
  • [x] There are very few or no comments (because comments shouldn't be needed if you write clean code)
  • [x] Xml documentation is added/updated for the addition/change
  • [x] Your PR is (re)based on top of the latest commits from the main branch (more info below)
  • [x] Link to the issue(s) you're fixing from your PR description. Use fixes #<the issue number>
  • [x] Readme is updated if you change an existing feature or add a new one
  • [x] Run either build.cmd or build.ps1 and ensure there are no test failures

neilboyd avatar Feb 23 '22 05:02 neilboyd

I think it's ready, but there are some questions in the description

neilboyd avatar Mar 22 '22 06:03 neilboyd

@hazzik thoughts on this one?

one note is that it significantly increase the number of entries in all the resource files. but if the entry is missing it can sensibly fall back to an acceptable value

SimonCropp avatar Feb 22 '24 05:02 SimonCropp

I'm refactoring this whole thing into using fewer resources:

DateHumanize_MultipleDaysFromNow ("{0} days from now") would become:

DateHumanize_Future => "{0} from now" (new resource) and TimeSpanHumanize_MultipleDays => "{0} days" (existing resource)

After that refactoring we could start thinking about abbreviations.

hazzik avatar Feb 22 '24 05:02 hazzik

@hazzik awesome. love your work

SimonCropp avatar Feb 22 '24 09:02 SimonCropp

I've tried to refactor *Ago and *FromNow. Unfortunately it is not an easy task :( Too many language specific rules.

hazzik avatar Feb 22 '24 13:02 hazzik