// Generated by CoffeeScript 1.12.7
(function() {
  var Duration, NANOS_PER_DAY, NANOS_PER_HOUR, NANOS_PER_MICRO, NANOS_PER_MILLI, NANOS_PER_MINUTE, NANOS_PER_SECOND, diffMoments;

  NANOS_PER_MICRO = 1000;

  NANOS_PER_MILLI = NANOS_PER_MICRO * 1000;

  NANOS_PER_SECOND = NANOS_PER_MILLI * 1000;

  NANOS_PER_MINUTE = NANOS_PER_SECOND * 60;

  NANOS_PER_HOUR = NANOS_PER_MINUTE * 60;

  NANOS_PER_DAY = NANOS_PER_HOUR * 24;

  Duration = (function() {
    function Duration(duration) {
      this.negative = duration < 0.0;
      this.sign = this.negative ? "-" : "";
      this.duration = this.negative ? -duration : duration;
    }

    Duration.prototype.nanos = function() {
      return this.duration;
    };

    Duration.prototype.micros = function() {
      return this.duration / NANOS_PER_MICRO;
    };

    Duration.prototype.millis = function() {
      return this.duration / NANOS_PER_MILLI;
    };

    Duration.prototype.seconds = function() {
      return this.duration / NANOS_PER_SECOND;
    };

    Duration.prototype.minutes = function() {
      return this.duration / NANOS_PER_MINUTE;
    };

    Duration.prototype.hours = function() {
      return this.duration / NANOS_PER_HOUR;
    };

    Duration.prototype.days = function() {
      return this.duration / NANOS_PER_DAY;
    };

    Duration.prototype.format = function() {
      switch (false) {
        case !(this.duration >= NANOS_PER_DAY):
          return this.sign + Math.floor(this.hours() / 24) + " d, " + Math.floor(this.hours() % 24) + " h";
        case !(this.duration >= NANOS_PER_HOUR):
          return this.sign + Math.floor(this.minutes() / 60) + " h, " + Math.floor(this.minutes() % 60) + " min";
        case !(this.duration >= NANOS_PER_MINUTE):
          return this.sign + Math.floor(this.seconds() / 60) + " min, " + Math.floor(this.seconds() % 60) + " s";
        case !(this.duration >= NANOS_PER_SECOND):
          return this.sign + Math.floor(this.millis() / 1000) + "." + this.zPad(Math.floor(this.millis() % 1000)) + " s";
        case !(this.duration >= NANOS_PER_MILLI):
          return this.sign + Math.floor(this.micros() / 1000) + "." + this.zPad(Math.floor(this.micros() % 1000)) + " ms";
        default:
          return this.sign + Math.floor(this.duration / 1000) + "." + this.zPad(Math.floor(this.duration % 1000)) + " us";
      }
    };

    Duration.prototype.toString = function() {
      return this.format();
    };

    Duration.prototype.zPad = function(value) {
      switch (false) {
        case !(value < 10):
          return "00" + value;
        case !(value < 100):
          return "0" + value;
        default:
          return "" + value;
      }
    };

    return Duration;

  })();

  diffMoments = function(momentA, momentB) {
    var nanos;
    nanos = moment.valueOf() * 1000000 - moment.valueOf() * 1000000;
    return newDuration(nanos);
  };

  module.exports = {
    "new": function(ns) {
      return new Duration(ns);
    },
    nanos: function(ns) {
      return new Duration(ns);
    },
    micros: function(us) {
      return new Duration(us * NANOS_PER_MICRO);
    },
    millis: function(ms) {
      return new Duration(ms * NANOS_PER_MILLI);
    },
    seconds: function(s) {
      return new Duration(s * NANOS_PER_SECOND);
    },
    diffMoments: diffMoments
  };

}).call(this);
