How to use the globalize.relativeTimeFormatter 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
console.log(like(1));
console.log(like(2));
console.log(like(3));

// 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 / app-npm-webpack / app / index.js View on Github external
var _dateToPartsFormatter = Globalize.dateToPartsFormatter({ datetime: "medium" });
var dateToPartsFormatter = function( value ) {
	return _dateToPartsFormatter( value, {
		datetime: "medium"
	}).map(function( part ) {
		switch(part.type) {
			case "month": return "<strong>" + part.value + "</strong>";
			default: return part.value;
		}
	}).reduce(function( memo, value ) {
		return memo + value;
	});
};
document.getElementById( "date-to-parts" ).innerHTML = dateToPartsFormatter( new Date() );

var relativeTimeFormatter = Globalize.relativeTimeFormatter( "second" );
document.getElementById( "relative-time" ).textContent = relativeTimeFormatter( 0 );

var unitFormatter = Globalize.unitFormatter( "mile/hour", { form: "short" } );
document.getElementById( "unit" ).textContent = unitFormatter( 60 );

// Messages.
document.getElementById( "intro-1" ).textContent = Globalize.formatMessage( "intro-1" );
document.getElementById( "number-label" ).textContent = Globalize.formatMessage( "number-label" );
document.getElementById( "number-compact-label" ).textContent = Globalize.formatMessage( "number-compact-label" );
document.getElementById( "currency-label" ).textContent = Globalize.formatMessage( "currency-label" );
document.getElementById( "date-label" ).textContent = Globalize.formatMessage( "date-label" );
document.getElementById( "date-time-zone-label" ).textContent = Globalize.formatMessage( "date-time-zone-label" );
document.getElementById( "date-to-parts-label" ).textContent = Globalize.formatMessage( "date-to-parts-label" );
document.getElementById( "relative-time-label" ).textContent = Globalize.formatMessage( "relative-time-label" );
document.getElementById( "unit-label" ).textContent = Globalize.formatMessage( "unit-label" );
document.getElementById( "message-1" ).textContent = Globalize.formatMessage( "message-1", {
github rxaviers / relative-time / src / relative-time.js View on Github external
RelativeTime.initializeFormatters = function(globalize) {
  if (globalize) {
    return {
      second: globalize.relativeTimeFormatter("second"),
      minute: globalize.relativeTimeFormatter("minute"),
      hour: globalize.relativeTimeFormatter("hour"),
      day: globalize.relativeTimeFormatter("day"),
      month: globalize.relativeTimeFormatter("month"),
      year: globalize.relativeTimeFormatter("year")
    };
  }
  return {
    second: Globalize.relativeTimeFormatter("second"),
    minute: Globalize.relativeTimeFormatter("minute"),
    hour: Globalize.relativeTimeFormatter("hour"),
    day: Globalize.relativeTimeFormatter("day"),
    month: Globalize.relativeTimeFormatter("month"),
    year: Globalize.relativeTimeFormatter("year")
  };
};
github rxaviers / relative-time / src / relative-time.js View on Github external
RelativeTime.initializeFormatters = function(globalize) {
  if (globalize) {
    return {
      second: globalize.relativeTimeFormatter("second"),
      minute: globalize.relativeTimeFormatter("minute"),
      hour: globalize.relativeTimeFormatter("hour"),
      day: globalize.relativeTimeFormatter("day"),
      month: globalize.relativeTimeFormatter("month"),
      year: globalize.relativeTimeFormatter("year")
    };
  }
  return {
    second: Globalize.relativeTimeFormatter("second"),
    minute: Globalize.relativeTimeFormatter("minute"),
    hour: Globalize.relativeTimeFormatter("hour"),
    day: Globalize.relativeTimeFormatter("day"),
    month: Globalize.relativeTimeFormatter("month"),
    year: Globalize.relativeTimeFormatter("year")
  };
};
github rxaviers / relative-time / src / relative-time.js View on Github external
if (globalize) {
    return {
      second: globalize.relativeTimeFormatter("second"),
      minute: globalize.relativeTimeFormatter("minute"),
      hour: globalize.relativeTimeFormatter("hour"),
      day: globalize.relativeTimeFormatter("day"),
      month: globalize.relativeTimeFormatter("month"),
      year: globalize.relativeTimeFormatter("year")
    };
  }
  return {
    second: Globalize.relativeTimeFormatter("second"),
    minute: Globalize.relativeTimeFormatter("minute"),
    hour: Globalize.relativeTimeFormatter("hour"),
    day: Globalize.relativeTimeFormatter("day"),
    month: Globalize.relativeTimeFormatter("month"),
    year: Globalize.relativeTimeFormatter("year")
  };
};
github rxaviers / relative-time / src / relative-time.js View on Github external
return {
      second: globalize.relativeTimeFormatter("second"),
      minute: globalize.relativeTimeFormatter("minute"),
      hour: globalize.relativeTimeFormatter("hour"),
      day: globalize.relativeTimeFormatter("day"),
      month: globalize.relativeTimeFormatter("month"),
      year: globalize.relativeTimeFormatter("year")
    };
  }
  return {
    second: Globalize.relativeTimeFormatter("second"),
    minute: Globalize.relativeTimeFormatter("minute"),
    hour: Globalize.relativeTimeFormatter("hour"),
    day: Globalize.relativeTimeFormatter("day"),
    month: Globalize.relativeTimeFormatter("month"),
    year: Globalize.relativeTimeFormatter("year")
  };
};
github rxaviers / relative-time / src / relative-time.js View on Github external
RelativeTime.initializeFormatters = function(globalize) {
  if (globalize) {
    return {
      second: globalize.relativeTimeFormatter("second"),
      minute: globalize.relativeTimeFormatter("minute"),
      hour: globalize.relativeTimeFormatter("hour"),
      day: globalize.relativeTimeFormatter("day"),
      month: globalize.relativeTimeFormatter("month"),
      year: globalize.relativeTimeFormatter("year")
    };
  }
  return {
    second: Globalize.relativeTimeFormatter("second"),
    minute: Globalize.relativeTimeFormatter("minute"),
    hour: Globalize.relativeTimeFormatter("hour"),
    day: Globalize.relativeTimeFormatter("day"),
    month: Globalize.relativeTimeFormatter("month"),
    year: Globalize.relativeTimeFormatter("year")
  };
};
github rxaviers / relative-time / src / relative-time.js View on Github external
RelativeTime.initializeFormatters = function(globalize) {
  if (globalize) {
    return {
      second: globalize.relativeTimeFormatter("second"),
      minute: globalize.relativeTimeFormatter("minute"),
      hour: globalize.relativeTimeFormatter("hour"),
      day: globalize.relativeTimeFormatter("day"),
      month: globalize.relativeTimeFormatter("month"),
      year: globalize.relativeTimeFormatter("year")
    };
  }
  return {
    second: Globalize.relativeTimeFormatter("second"),
    minute: Globalize.relativeTimeFormatter("minute"),
    hour: Globalize.relativeTimeFormatter("hour"),
    day: Globalize.relativeTimeFormatter("day"),
    month: Globalize.relativeTimeFormatter("month"),
    year: Globalize.relativeTimeFormatter("year")
  };
};