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

Support formatting units, eg. secs, days #252

Closed
rxaviers opened this issue May 19, 2014 · 5 comments
Closed

Support formatting units, eg. secs, days #252

rxaviers opened this issue May 19, 2014 · 5 comments

Comments

@rxaviers
Copy link
Member

PR #254

Format units such as seconds, minutes, days, weeks, and everything else supported by CLDR.

Requires

API

.formatUnit( value, unit [, options] );

Examples:

.formatUnit( 1, "month" ); // 1 month
.formatUnit( 5, "week" ); // 5 weeks
.formatUnit( 30, "day" ); // 30 days
.formatUnit( 30, "day", { form: "narrow" }); // 30d

Value: Number

Unit: String, eg. "month", "day", etc.

Options:

  • form ("long"|"short"|"narrow") used when tense = null to specify the unit form, eg. ("2 seconds", "2 secs", or "2s").

Specs

CLDR

Units can be found on main//units.json.

Ecma proposal

Fore more background: see #391.

@arkihillel
Copy link

This is a must have as far as I'm concerned. Would be glad to help if needed.
What I tried to do a week ago before realizing I couldn't with the current version of globalize might help you get a clear use case:

Display week dates

// Globalize initialization omitted
function formatWeek(startDate) {
    var startDate = new Date(startDate);
    // _ is gettext
    var i18nString = _('%s of %s to %s');
    var i18nWeek = Globalize.formatUnit( 1, "week" );
    var i18nFirstDay = Globalize.formatDate(startDate, {skeleton: 'yMd'});
    var i18nLastDay = Globalize.formatDate(startDate.setDate(startDate.getDate() + 6), language, {skeleton: 'yMd'});
    return util.format(i18nString, i18nWeek, i18nFirstDay, i18nLastDay);
}

@rxaviers
Copy link
Member Author

It was not clear to me whether the API specified here (and partially implemented by #252) is sufficient for you? If it is, you can help me to finish #252, so we can land it. Right now, it misses functional tests and docs. It got stalled due to lack of time/resource to work on it.

@arkihillel
Copy link

#252 perfectly fits my needs. I'd be glad to help and will look into documenting it whenever I have free time.

@rxaviers
Copy link
Member Author

Awesome, feel free to add comments needing help. As soon as we get those items tick, it should be good to land on master.

@rxaviers
Copy link
Member Author

Ecma proposal

@rxaviers rxaviers modified the milestone: 1.1.0 Oct 11, 2015
rxaviers added a commit that referenced this issue Oct 20, 2015
rxaviers pushed a commit that referenced this issue Oct 20, 2015
rxaviers added a commit to rxaviers/globalize-webpack-plugin that referenced this issue Oct 20, 2015
rxaviers added a commit that referenced this issue Oct 21, 2015
rxaviers added a commit that referenced this issue Oct 21, 2015
rxaviers added a commit that referenced this issue Oct 21, 2015
rxaviers added a commit that referenced this issue Oct 21, 2015
rxaviers added a commit that referenced this issue Feb 4, 2016
rxaviers added a commit that referenced this issue Feb 4, 2016
rxaviers added a commit that referenced this issue Feb 4, 2016
rxaviers pushed a commit that referenced this issue Feb 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants