All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bower_components.globalize.dist.globalize-runtime.relative-time.js Maven / Gradle / Ivy

There is a newer version: 0.66.0.1
Show newest version
/**
 * Globalize Runtime v1.2.3
 *
 * http://github.com/jquery/globalize
 *
 * Copyright jQuery Foundation and other contributors
 * Released under the MIT license
 * http://jquery.org/license
 *
 * Date: 2017-03-17T01:41Z
 */
/*!
 * Globalize Runtime v1.2.3 2017-03-17T01:41Z Released under the MIT license
 * http://git.io/TrdQbw
 */
(function (root, factory) {

    // UMD returnExports
    if (typeof define === "function" && define.amd) {

        // AMD
        define([
            "../globalize-runtime",
            "./number",
            "./plural"
        ], factory);
    } else if (typeof exports === "object") {

        // Node, CommonJS
        module.exports = factory(
            require("../globalize-runtime"),
            require("./number"),
            require("./plural")
        );
    } else {

        // Extend global
        factory(root.Globalize);
    }
}(this, function (Globalize) {

    var formatMessage = Globalize._formatMessage,
        runtimeKey = Globalize._runtimeKey,
        validateParameterPresence = Globalize._validateParameterPresence,
        validateParameterTypeNumber = Globalize._validateParameterTypeNumber;


    /**
     * format( value, numberFormatter, pluralGenerator, properties )
     *
     * @value [Number] The number to format
     *
     * @numberFormatter [String] A numberFormatter from Globalize.numberFormatter
     *
     * @pluralGenerator [String] A pluralGenerator from Globalize.pluralGenerator
     *
     * @properties [Object] containing relative time plural message.
     *
     * Format relative time.
     */
    var relativeTimeFormat = function (value, numberFormatter, pluralGenerator, properties) {

        var relativeTime,
            message = properties["relative-type-" + value];

        if (message) {
            return message;
        }

        relativeTime = value <= 0 ? properties["relativeTime-type-past"]
            : properties["relativeTime-type-future"];

        value = Math.abs(value);

        message = relativeTime["relativeTimePattern-count-" + pluralGenerator(value)];
        return formatMessage(message, [numberFormatter(value)]);
    };


    var relativeTimeFormatterFn = function (numberFormatter, pluralGenerator, properties) {
        return function relativeTimeFormatter(value) {
            validateParameterPresence(value, "value");
            validateParameterTypeNumber(value, "value");

            return relativeTimeFormat(value, numberFormatter, pluralGenerator, properties);
        };

    };


    Globalize._relativeTimeFormatterFn = relativeTimeFormatterFn;

    Globalize.formatRelativeTime =
        Globalize.prototype.formatRelativeTime = function (value, unit, options) {
            validateParameterPresence(value, "value");
            validateParameterTypeNumber(value, "value");

            return this.relativeTimeFormatter(unit, options)(value);
        };

    Globalize.relativeTimeFormatter =
        Globalize.prototype.relativeTimeFormatter = function (unit, options) {
            options = options || {};
            return Globalize[runtimeKey("relativeTimeFormatter", this._locale, [unit, options])];
        };

    return Globalize;


}));




© 2015 - 2024 Weber Informatics LLC | Privacy Policy