Cleans code.

This commit is contained in:
Lars Jung 2012-10-17 01:33:26 +02:00
parent cecc5c57a2
commit 885ce9e9e9

View file

@ -1,8 +1,7 @@
modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
var reParseSize = /^\s*([\.\d]+)\s*([kmgt]?)b?\s*$/i,
decimalMetric = {
var decimalMetric = {
t: 1000.0,
k: 1000.0,
u: ['B', 'KB', 'MB', 'GB', 'TB']
@ -15,30 +14,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
defaultMetric = decimalMetric,
defaultDateFormat = 'YYYY-MM-DD HH:mm',
parseSize = function (str) {
var match = reParseSize.exec(str),
kilo = decimalMetric.k,
val, unit;
if (!match) {
return null;
}
val = parseFloat(match[1]);
unit = match[2].toLowerCase();
if (unit === 'k') {
val *= kilo;
} else if (unit === 'm') {
val *= kilo * kilo;
} else if (unit === 'g') {
val *= kilo * kilo * kilo;
} else if (unit === 't') {
val *= kilo * kilo * kilo * kilo;
}
return val;
},
setDefaultMetric = function (metric) {
if (!metric) {
@ -73,15 +48,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
defaultDateFormat = dateFormat;
},
parseDate = function (str, dateFormat) {
try { // problems with ie < 9 :(
return moment(str, dateFormat || defaultDateFormat).valueOf() || null;
} catch (err) {}
return Date.parse(str).valueOf() || null;
},
formatDate = function (millis, dateFormat) {
if (!_.isNumber(millis) || !millis) {
@ -92,11 +58,9 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
};
return {
parseSize: parseSize,
setDefaultMetric: setDefaultMetric,
formatSize: formatSize,
setDefaultDateFormat: setDefaultDateFormat,
parseDate: parseDate,
formatDate: formatDate
};
});