"use strict";

var _chai = require("chai");

var _formatTimespan = require("../formatTimespan");

describe('formatTimespan', function () {
  it('formats timespans less than one minute', function () {
    var startTime = new Date();
    var fifteenSeconds = 15 * 1000;
    var endTime = new Date(startTime.getTime() + fifteenSeconds);
    var result = (0, _formatTimespan.formatTimespan)(startTime, endTime);
    (0, _chai.expect)(result).to.equal('15 seconds');
  });
  it('formats timespans over a minute', function () {
    var startTime = new Date();
    var twoMinutes = 2 * 60 * 1000;
    var fifteenSeconds = 15 * 1000;
    var endTime = new Date(startTime.getTime() + twoMinutes + fifteenSeconds);
    var result = (0, _formatTimespan.formatTimespan)(startTime, endTime);
    (0, _chai.expect)(result).to.equal('2 minutes 15 seconds');
  });
  it('formats timespans over an hour', function () {
    var startTime = new Date();
    var sixHours = 6 * 60 * 60 * 1000;
    var twoMinutes = 2 * 60 * 1000;
    var fifteenSeconds = 15 * 1000;
    var endTime = new Date(startTime.getTime() + sixHours + twoMinutes + fifteenSeconds);
    var result = (0, _formatTimespan.formatTimespan)(startTime, endTime);
    (0, _chai.expect)(result).to.equal('6 hours 2 minutes 15 seconds');
  });
  it('excludes zero-duration segments', function () {
    var startTime = new Date();
    var sixHours = 6 * 60 * 60 * 1000;
    var endTime = new Date(startTime.getTime() + sixHours);
    var result = (0, _formatTimespan.formatTimespan)(startTime, endTime);
    (0, _chai.expect)(result).to.equal('6 hours');
  });
  it('displays 0 seconds when less than a second', function () {
    var startTime = new Date();
    var endTime = new Date(startTime.getTime() + 999);
    var result = (0, _formatTimespan.formatTimespan)(startTime, endTime);
    (0, _chai.expect)(result).to.equal('0 seconds');
  });
  it('displays 0 seconds when no time difference', function () {
    var startTime = new Date();
    var result = (0, _formatTimespan.formatTimespan)(startTime, startTime);
    (0, _chai.expect)(result).to.equal('0 seconds');
  });
  it('formats singulars', function () {
    var startTime = new Date();
    var oneHour = 1 * 60 * 60 * 1000;
    var oneMinute = 1 * 60 * 1000;
    var oneSecond = 1 * 1000;
    var endTime = new Date(startTime.getTime() + oneHour + oneMinute + oneSecond);
    var result = (0, _formatTimespan.formatTimespan)(startTime, endTime);
    (0, _chai.expect)(result).to.equal('1 hour 1 minute 1 second');
  });
});
describe('formatTime', function () {
  it('formats times less than one minute', function () {
    (0, _chai.expect)((0, _formatTimespan.formatTime)(15)).to.equal('15 seconds');
  });
  it('formats times over a minute', function () {
    (0, _chai.expect)((0, _formatTimespan.formatTime)(2 * 60 + 15)).to.equal('2 minutes 15 seconds');
  });
  it('formats times over an hour', function () {
    (0, _chai.expect)((0, _formatTimespan.formatTime)(6 * 3600 + 135)).to.equal('6 hours 2 minutes 15 seconds');
  });
  it('excludes zero segments', function () {
    (0, _chai.expect)((0, _formatTimespan.formatTime)(6 * 3600)).to.equal('6 hours');
  });
  it('displays 0 seconds when less than a second', function () {
    (0, _chai.expect)((0, _formatTimespan.formatTime)(0.99)).to.equal('0 seconds');
    (0, _chai.expect)((0, _formatTimespan.formatTime)(0.5)).to.equal('0 seconds');
    (0, _chai.expect)((0, _formatTimespan.formatTime)(0)).to.equal('0 seconds');
  });
  it('formats singulars', function () {
    (0, _chai.expect)((0, _formatTimespan.formatTime)(3600 + 61)).to.equal('1 hour 1 minute 1 second');
  });
});