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

META-INF.resources.bower_components.globalize.src.date.timezone-hour-format.js Maven / Gradle / Ivy

The newest version!
define([
    "../util/string/pad"
], function (stringPad) {

    /**
     * hourFormat( date, format, timeSeparator, formatNumber )
     *
     * Return date's timezone offset according to the format passed.
     * Eg for format when timezone offset is 180:
     * - "+H;-H": -3
     * - "+HHmm;-HHmm": -0300
     * - "+HH:mm;-HH:mm": -03:00
     */
    return function (date, format, timeSeparator, formatNumber) {
        var absOffset,
            offset = date.getTimezoneOffset();

        absOffset = Math.abs(offset);
        formatNumber = formatNumber || {
            1: function (value) {
                return stringPad(value, 1);
            },
            2: function (value) {
                return stringPad(value, 2);
            }
        };

        return format

        // Pick the correct sign side (+ or -).
            .split(";")[offset > 0 ? 1 : 0]

        // Localize time separator
            .replace(":", timeSeparator)

            // Update hours offset.
            .replace(/HH?/, function (match) {
                return formatNumber[match.length](Math.floor(absOffset / 60));
            })

            // Update minutes offset and return.
            .replace(/mm/, function () {
                return formatNumber[2](absOffset % 60);
            });
    };

});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy