rename vars; in Ox.formatDimensions, use multiplication sign; more efficient version of Ox.parseDuration

This commit is contained in:
rolux 2012-05-25 12:19:04 +02:00
parent a37949094d
commit 2dbb61c103

View file

@ -464,11 +464,11 @@ Ox.formatDegrees <f> Formats degrees as D°MM'SS"
> Ox.formatDegrees(-111.11, 'lng')
"111\u00B006'36\"W"
@*/
Ox.formatDegrees = function(deg, mode) {
Ox.formatDegrees = function(degrees, mode) {
var days = 0,
sec = Math.round(Math.abs(deg) * 3600),
sign = deg < 0 ? '-' : '',
split = Ox.formatDuration(sec).split(':');
seconds = Math.round(Math.abs(degrees) * 3600),
sign = degrees < 0 ? '-' : '',
split = Ox.formatDuration(seconds).split(':');
if (split.length == 4) {
days = parseInt(split.shift(), 10);
}
@ -476,8 +476,8 @@ Ox.formatDegrees = function(deg, mode) {
return (!mode ? sign : '')
+ split[0] + '\u00B0' + split[1] + "'" + split[2] + '"'
+ (
mode == 'lat' ? (deg < 0 ? 'S' : 'N')
: mode == 'lng' ? (deg < 0 ? 'W' : 'E')
mode == 'lat' ? (degrees < 0 ? 'S' : 'N')
: mode == 'lng' ? (degrees < 0 ? 'W' : 'E')
: ''
);
};
@ -485,10 +485,10 @@ Ox.formatDegrees = function(deg, mode) {
/*@
Ox.formatDimensions <f> Formats valus as dimension
> Ox.formatDimensions([1920, 1080], 'px')
"1920 x 1080 px"
"1920 × 1080 px"
@*/
Ox.formatDimensions = Ox.formatResolution = function(arr, str) {
return arr.join(' x ') + (str ? ' ' + str : '');
Ox.formatDimensions = Ox.formatResolution = function(array, string) {
return array.join(' × ') + (string ? ' ' + string : '');
};
/*@
@ -629,7 +629,6 @@ Ox.formatPercent = function(num, total, dec) {
return Ox.formatNumber(num / total * 100, dec) + '%'
};
/*@
Ox.formatString <f> Basic string formatting
> Ox.formatString('{0}{1}', ['foo', 'bar'])
@ -690,12 +689,8 @@ Ox.parseDuration <f> Takes a formatted duration, returns seconds
> Ox.parseDuration('1::')
3600
@*/
Ox.parseDuration = function(str) {
var split = str.split(':').reverse();
while (split.length > 3) {
split.pop();
}
return split.reduce(function(prev, curr, i) {
return prev + (parseFloat(curr) || 0) * Math.pow(60, i);
Ox.parseDuration = function(string) {
return string.split(':').reverse().slice(0, 3).reduce(function(p, c, i) {
return p + (parseFloat(c) || 0) * Math.pow(60, i);
}, 0);
}
};