1
0
Fork 0
forked from 0x2620/oxjs

misc updates; add geo demo

This commit is contained in:
rolux 2011-12-31 18:27:02 +05:30
commit 34753cb2ed
9 changed files with 219 additions and 81 deletions

View file

@ -274,7 +274,8 @@ Ox.formatDateRange = function(start, end, utc) {
Ox.formatDate(dates[0], formats[precision[0] - 1], utc),
Ox.formatDate(dates[1], formats[precision[1] - 1], utc)
];
// if same year, and neither date is more precise than day, then omit first year
// if same year, and neither date is more precise than day,
// then omit first year
if (
parts[0][0] == parts[1][0]
&& precision[0] <= 3
@ -553,3 +554,24 @@ Ox.formatUnit = function(num, str, dec, factor) {
factor = Ox.isUndefined(factor) ? 1 : factor;
return Ox.formatNumber(num * factor, dec) + (str == '%' ? '' : ' ') + str;
};
/*@
Ox.parseDuration <f> Takes a formatted duration, returns seconds
> Ox.parseDuration('01:02:03')
3723
> Ox.parseDuration('3')
3
> Ox.parseDuration('2:')
120
> 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);
}, 0);
}