How to use the globalize.formatRelativeTime function in globalize

To help you get started, we’ve selected a few globalize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github globalizejs / globalize-compiler / test / unit / fixtures / basic.js View on Github external
// Use messageFormatter.
like = Globalize.messageFormatter("like");

// Use formatMessage.
console.log(Globalize.formatMessage("task", {count: 1000, formattedCount: "1,000"}));

/**
 * Relative Time
 */

// Use relativeTimeFormatter.
var relativeTimeFormatter = Globalize.relativeTimeFormatter("day");
console.log(relativeTimeFormatter(0));

// Use formatRelativeTime.
console.log(Globalize.formatRelativeTime(-35, "second"));

/**
 * Unit
 */

// Use unitFormatter.
var unitFormatter = Globalize.unitFormatter("kilowatt");
console.log(unitFormatter(120));

// Use formatUnit.
console.log(Globalize.formatUnit(60, "mile/hour", {form: "short"}));
github globalizejs / globalize / examples / node-npm / main.js View on Github external
// Use Globalize to format currencies.
console.log( Globalize.formatCurrency( 69900, "USD" ) );

// Use Globalize to get the plural form of a numeric value.
console.log( Globalize.plural( 12345.6789 ) );

// Use Globalize to format a message with plural inflection.
like = Globalize.messageFormatter( "like" );
console.log( like( 0 ) );
console.log( like( 1 ) );
console.log( like( 2 ) );
console.log( like( 3 ) );

// Use Globalize to format relative time.
console.log( Globalize.formatRelativeTime( -35, "second" ) );

// Use Globalize to format unit.
console.log( Globalize.formatUnit( 60, "mile/hour", { form: "short" } ) );
github globalizejs / globalize / examples / node-npm / main.js View on Github external
// Use Globalize to format currencies.
console.log( Globalize.formatCurrency( 69900, "USD" ) );

// Use Globalize to get the plural form of a numeric value.
console.log( Globalize.plural( 12345.6789 ) );

// Use Globalize to format a message with plural inflection.
like = Globalize.messageFormatter( "like" );
console.log( like( 0 ) );
console.log( like( 1 ) );
console.log( like( 2 ) );
console.log( like( 3 ) );

// Use Globalize to format relative time.
console.log( Globalize.formatRelativeTime( -35, "second" ) );

// Use Globalize to format unit.
console.log( Globalize.formatUnit( 60, "mile/hour", { form: "short" } ) );
github dojo / framework / tests / i18n / unit / util / globalize.ts View on Github external
const options: RelativeTimeFormatterOptions = { form: 'short' };

				assert.strictEqual(
					globalizeDelegator('formatRelativeTime', {
						unit,
						value
					}),
					Globalize.formatRelativeTime(value, unit)
				);
				assert.strictEqual(
					globalizeDelegator('formatRelativeTime', {
						optionsOrLocale: options,
						unit,
						value
					}),
					Globalize.formatRelativeTime(value, unit, options)
				);
				assert.strictEqual(
					globalizeDelegator('formatRelativeTime', {
						locale,
						optionsOrLocale: options,
						unit,
						value
					}),
					new Globalize('fr').formatRelativeTime(value, unit, options)
				);
			},
github dojo / framework / tests / i18n / unit / util / globalize.ts View on Github external
'assert method that takes a value and a unit'() {
				const locale = 'fr';
				const unit = 'week';
				const value = 5;
				const options: RelativeTimeFormatterOptions = { form: 'short' };

				assert.strictEqual(
					globalizeDelegator('formatRelativeTime', {
						unit,
						value
					}),
					Globalize.formatRelativeTime(value, unit)
				);
				assert.strictEqual(
					globalizeDelegator('formatRelativeTime', {
						optionsOrLocale: options,
						unit,
						value
					}),
					Globalize.formatRelativeTime(value, unit, options)
				);
				assert.strictEqual(
					globalizeDelegator('formatRelativeTime', {
						locale,
						optionsOrLocale: options,
						unit,
						value
					}),