Source: service/offset.js

// Generated by CoffeeScript 1.12.7

/**
 * Offset
 * @namespace Offset
 */
'use strict';
app.factory('Offset', [
  function() {
    var multipliers, pad, regex;
    pad = function(s, n, d) {
      var p;
      if (d === void 0 || (p = s.indexOf(d)) === -1) {
        p = s.length;
      }
      while (p++ < n) {
        s = '0' + s;
      }
      return s;
    };
    multipliers = [1000, 60, 60, 24];
    regex = /^\s*[-+]?(\d+:){0,2}\d+(\.\d*)?\s*$/;
    return {
      format: function(o, round) {
        var i, s;
        if (!isFinite(o)) {
          return;
        }
        i = Math.abs(o);
        s = (i % 60000) / 1000;
        if (round) {
          s |= 0;
        }
        i = 0 | i / 60000;
        s = (i % 60) + ':' + pad((round ? s.toString() : s.toFixed(3)), 2, '.');
        i = 0 | i / 60;
        if (i) {
          s = (i % 24) + ':' + pad(s, 2, ':');
          i = 0 | i / 24;
          if (i) {
            s = i + ':' + pad(s, 2, ':');
          }
        }
        if (o < 0) {
          return '-' + s;
        } else {
          return s;
        }
      },
      parse: function(s) {
        var l, n, o, r;
        if (!(r = regex.exec(s))) {
          return;
        }
        if (!(r[1] || r[2])) {
          return parseInt(s, 10);
        }
        if (n = s.charAt(0) === '-') {
          s = s.substr(1);
        }
        s = s.split(':');
        l = s.length;
        o = 0;
        _.each(s, function(val, i) {
          return o = (o + parseFloat(val)) * multipliers[l - 1 - i];
        });
        if (n) {
          return -o;
        } else {
          return o;
        }
      }
    };
  }
]);

//# sourceMappingURL=offset.js.map