How to use relative-time-format - 10 common examples

To help you get started, we’ve selected a few relative-time-format 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 catamphetamine / javascript-time-ago / source / JavascriptTimeAgo.js View on Github external
getFormatter(flavor) {
		// `Intl.RelativeTimeFormat` instance creation is assumed a
		// lengthy operation so the instances are cached and reused.
		return this.relativeTimeFormatCache.get(this.locale, flavor) ||
			this.relativeTimeFormatCache.put(this.locale, flavor, new RelativeTimeFormat(this.locale, { style: flavor }))
	}
github aurelia / aurelia / packages / __e2e__ / src / startup.ts View on Github external
import { I18nConfiguration } from '@aurelia/i18n';
import { JitHtmlBrowserConfiguration } from '@aurelia/jit-html-browser';
import { Aurelia } from '@aurelia/runtime';
import Fetch from 'i18next-fetch-backend';
import * as intervalPlural from 'i18next-intervalplural-postprocessor';
import { App as component } from './app';
import { CustomMessage } from './plugins/custom-message';
import { SutI18N } from './plugins/sut-i18n';
import { resources } from './plugins/translation-resources';

// Intl.RelativeTimeFormat polyfill is needed as Cypress uses electron and does not seems to work with puppeteer
import RelativeTimeFormat from 'relative-time-format';
import * as deRt from 'relative-time-format/locale/de.json';
import * as enRt from 'relative-time-format/locale/en.json';
RelativeTimeFormat.addLocale(enRt['default']);
RelativeTimeFormat.addLocale(deRt['default']);
Intl['RelativeTimeFormat'] = Intl['RelativeTimeFormat'] || RelativeTimeFormat;

(async function () {
  const host = document.querySelector('app');
  const searchParams = new URL(location.href).searchParams;
  const fetchResource = !!searchParams.get('fetchResource');

  const au = new Aurelia()
    .register(
      JitHtmlBrowserConfiguration,
      DebugConfiguration,
      I18nConfiguration.customize((options) => {
        options.translationAttributeAliases = ['t', 'i18n'];
        const plugins = [intervalPlural.default];
        if (fetchResource) {
          plugins.push(Fetch);
github catamphetamine / javascript-time-ago / source / JavascriptTimeAgo.js View on Github external
constructor(locales = [])
	{
		// Convert `locales` to an array.
		if (typeof locales === 'string') {
			locales = [locales]
		}

		// Choose the most appropriate locale
		// (one of the previously added ones)
		// based on the list of preferred `locales` supplied by the user.
		this.locale = chooseLocale(
			locales.concat(RelativeTimeFormat.getDefaultLocale()),
			getLocaleData
		)

		// Use `Intl.NumberFormat` for formatting numbers (when available).
		if (typeof Intl !== 'undefined' && Intl.NumberFormat) {
			this.numberFormat = new Intl.NumberFormat(this.locale)
		}

		// Cache `Intl.RelativeTimeFormat` instance.
		this.relativeTimeFormatCache = new Cache()
	}
github catamphetamine / javascript-time-ago / source / JavascriptTimeAgo.js View on Github external
// Can't happen - "long" flavour is always present.
		// throw new Error(`None of the flavours - ${flavour.join(', ')} - was found for locale "${this.locale}".`)
	}
}

/**
 * Gets default locale.
 * @return  {string} locale
 */
JavascriptTimeAgo.getDefaultLocale = RelativeTimeFormat.getDefaultLocale

/**
 * Sets default locale.
 * @param  {string} locale
 */
JavascriptTimeAgo.setDefaultLocale = RelativeTimeFormat.setDefaultLocale

/**
 * Adds locale data for a specific locale.
 * @param {Object} localeData
 */
JavascriptTimeAgo.addLocale = function(localeData) {
	addLocaleData(localeData)
	RelativeTimeFormat.addLocale(localeData)
}

/**
 * (legacy alias)
 * Adds locale data for a specific locale.
 * @param {Object} localeData
 * @deprecated
 */
github catamphetamine / javascript-time-ago / locale / af / index.js View on Github external
var locale = require('relative-time-format/locale/af')

module.exports = {
	locale: locale.locale,
	// Standard styles.
	long: locale.long,
	short: locale.short,
	narrow: locale.narrow,
	// Quantifier.
	quantify: locale.quantify
}
github catamphetamine / javascript-time-ago / locale / af / index.js View on Github external
var locale = require('relative-time-format/locale/af')

module.exports = {
	locale: locale.locale,
	// Standard styles.
	long: locale.long,
	short: locale.short,
	narrow: locale.narrow,
	// Quantifier.
	quantify: locale.quantify
}
github catamphetamine / javascript-time-ago / locale / af / index.js View on Github external
var locale = require('relative-time-format/locale/af')

module.exports = {
	locale: locale.locale,
	// Standard styles.
	long: locale.long,
	short: locale.short,
	narrow: locale.narrow,
	// Quantifier.
	quantify: locale.quantify
}
github catamphetamine / javascript-time-ago / locale / af / index.js View on Github external
var locale = require('relative-time-format/locale/af')

module.exports = {
	locale: locale.locale,
	// Standard styles.
	long: locale.long,
	short: locale.short,
	narrow: locale.narrow,
	// Quantifier.
	quantify: locale.quantify
}
github catamphetamine / javascript-time-ago / locale / af / index.js View on Github external
var locale = require('relative-time-format/locale/af')

module.exports = {
	locale: locale.locale,
	// Standard styles.
	long: locale.long,
	short: locale.short,
	narrow: locale.narrow,
	// Quantifier.
	quantify: locale.quantify
}
github catamphetamine / javascript-time-ago / locale / am / index.js View on Github external
var locale = require('relative-time-format/locale/am')

module.exports = {
	locale: locale.locale,
	// Standard styles.
	long: locale.long,
	short: locale.short,
	narrow: locale.narrow,
	// Quantifier.
	quantify: locale.quantify
}