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