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

Feature Request: Pass relativeTimeThresholds to humanize() as argument #4295

Closed
TedDriggs opened this issue Nov 8, 2017 · 2 comments
Closed

Comments

@TedDriggs
Copy link
Contributor

TedDriggs commented Nov 8, 2017

Note: PR #4296 has been submitted for this.

Description of the Issue and Steps to Reproduce:

  1. Have an application which wants to use different relativeTimeThreshold values in different parts of its application
  2. Call relativeTimeThreshold in one part of the application

Desired: There is a way to confine those relative time thresholds to that part of the application
Observed: The changes are global

Proposal

Change the signature of humanize as follows:

export function humanize(withSuffixOrOptions?: boolean | Options): string;

export interface Options {
    withSuffix?: boolean;
    thresholds?: Thresholds;
}

// Define a type with the current set of keys accepted by relativeTimeThreshold
export type Thresholds = typeof thresholds;

Within humanize, if withSuffixOrOptions is an object and it contains a thresholds property, that will be used instead of the var thresholds defined earlier in the file.

@rokoroku
Copy link

rokoroku commented Dec 7, 2017

This feature is good, but I think it's not enough to format duration.

Could we have time unit to includes as options, rather than the thresholds?

e.g.

moment.duration({ s: 100 }).humanize({ s: true }) // '100 seconds'
moment.duration({ s: 100 }).humanize({ m: true }) // '1 minute'
moment.duration({ s: 100 }).humanize({ m: true, s: true }) // '1 minute 40 seconds'
moment.duration({ s: 100 }).humanize({ ms: true }) // '10000 milliseconds'

@TedDriggs
Copy link
Contributor Author

This issue describes a scoped means of invoking existing formatting behavior. I’d suggest filing a separate issue for a new formatting behavior that spans multiple units of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants