META-INF.resources.bower_components.globalize.src.date.timezone-hour-format.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jwebmp-globalize Show documentation
Show all versions of jwebmp-globalize Show documentation
The JWebSwing implementation for a full Globalization
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);
});
};
});