"use strict";

var _tape = _interopRequireDefault(require("tape"));

var _timeString = require("./time-string");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(0, _tape.default)('parseTimeString', t => {
  const entries = [[null, null], [NaN, null], ['', null], [false, null], [true, null], [0, null], ['0a', {
    hours: 0,
    minutes: 0
  }], ['1a', {
    hours: 1,
    minutes: 0
  }], ['1    am', {
    hours: 1,
    minutes: 0
  }], ['12    pm', {
    hours: 12,
    minutes: 0
  }], ['12    am', {
    hours: 0,
    minutes: 0
  }], ['8:45', {
    hours: 8,
    minutes: 45
  }], ['8 45', {
    hours: 8,
    minutes: 45
  }], ['8:45a', {
    hours: 8,
    minutes: 45
  }], ['8:45p', {
    hours: 20,
    minutes: 45
  }], ['8:45 pm', {
    hours: 20,
    minutes: 45
  }], ['8:45 p.m.', {
    hours: 20,
    minutes: 45
  }], ['8a', {
    hours: 8,
    minutes: 0
  }], ['835a', {
    hours: 8,
    minutes: 35
  }], ['835 pm', {
    hours: 20,
    minutes: 35
  }], ['0800', {
    hours: 8,
    minutes: 0
  }], ['2400', {
    hours: 0,
    minutes: 0
  }], ['2500', null], ['', null], ['a', null], ['b', null], ['   ', null], [':', null], ['23:', {
    hours: 23,
    minutes: 0
  }], ['4:60', null], ['4:59', {
    hours: 4,
    minutes: 59
  }], ['13:59p', null], ['23:59a', null], ['12:59a', {
    hours: 0,
    minutes: 59
  }], ['24.59', {
    hours: 0,
    minutes: 59
  }], ['24.59a', null], ['12: a', {
    hours: 0,
    minutes: 0
  }], ['11:2', null], ['5:21 p.m.', {
    hours: 17,
    minutes: 21
  }]];

  for (const entry of entries) {
    t.deepEqual((0, _timeString.parseTimeString)(entry[0]), entry[1], "".concat(entry[0], " should be ").concat(JSON.stringify(entry[1])));
  }

  let pad = num => (num + '').padStart(2, '0'); // build every possible valid minute time


  const expectedValid = [];
  let hourCount = 0;

  while (hourCount < 25) {
    let minuteCount = 0;

    while (minuteCount < 60) {
      const addExpected = str => expectedValid.push([str, {
        hours: hourCount >= 24 ? hourCount - 24 : hourCount,
        minutes: minuteCount
      }]);

      addExpected("".concat(hourCount, ":").concat(pad(minuteCount)));
      addExpected("".concat(pad(hourCount), ":").concat(pad(minuteCount)));
      addExpected("".concat(pad(hourCount)).concat(pad(minuteCount))); // handle 12 am scenario

      if (hourCount === 0) {
        addExpected("12:".concat(pad(minuteCount), " a"));
      } // handle 12 pm scenario


      if (hourCount === 12) {
        addExpected("12:".concat(pad(minuteCount), " pm"));
        addExpected("12:".concat(pad(minuteCount), "pm"));
        addExpected("12:".concat(pad(minuteCount), "p.m."));
        addExpected("12:".concat(pad(minuteCount), " p.m. asdfas"));
        addExpected("12:".concat(pad(minuteCount), "PM"));
        addExpected("12:".concat(pad(minuteCount), "P.M."));
        addExpected("12".concat(pad(minuteCount), " pm"));
        addExpected("12".concat(pad(minuteCount), "pm"));
        addExpected("12".concat(pad(minuteCount), "p.m."));
        addExpected("12".concat(pad(minuteCount), " p.m. asdfas"));
        addExpected("12".concat(pad(minuteCount), "PM"));
        addExpected("12".concat(pad(minuteCount), "P.M."));
      } // handle 12+ pm


      if (hourCount > 12 && hourCount < 24) {
        const hours = hourCount - 12;
        addExpected("".concat(hours, ":").concat(pad(minuteCount), " pm"));
        addExpected("".concat(hours, ":").concat(pad(minuteCount), "pm"));
        addExpected("".concat(hours, ":").concat(pad(minuteCount), "p.m."));
        addExpected("".concat(hours, ":").concat(pad(minuteCount), " p.m. asdfas"));
        addExpected("".concat(hours, ":").concat(pad(minuteCount), "PM"));
        addExpected("".concat(hours, ":").concat(pad(minuteCount), "P.M."));
        addExpected("".concat(hours).concat(pad(minuteCount), " pm"));
        addExpected("".concat(hours).concat(pad(minuteCount), "pm"));
        addExpected("".concat(hours).concat(pad(minuteCount), "p.m."));
        addExpected("".concat(hours).concat(pad(minuteCount), " p.m. asdfas"));
        addExpected("".concat(hours).concat(pad(minuteCount), "PM"));
        addExpected("".concat(hours).concat(pad(minuteCount), "P.M."));
      }

      minuteCount++;
    }

    hourCount++;
  }

  for (const entry of expectedValid) {
    t.deepEqual((0, _timeString.parseTimeString)(entry[0]), entry[1], "".concat(entry[0], " should be ").concat(JSON.stringify(entry[1])));
  }

  t.end();
});
(0, _tape.default)('cleanTimeStringInput', t => {
  const entries = [['', ''], ['a', 'a'], ['ap', 'ap'], ['alkjsadlfjalskdjflaskdjfalksdfjalskdjfasdfas', 'a', null], ['AA', 'A', null], ['PP', 'P', null], ['aaa', 'a', null], ['12: 23 aaa', '12: 23 a', {
    hours: 0,
    minutes: 23
  }], ['12: aaa', '12: a', {
    hours: 0,
    minutes: 0
  }], ['12: aM', '12: aM', {
    hours: 0,
    minutes: 0
  }], ['12: ...', '12: .', {
    hours: 12,
    minutes: 0
  }]];

  for (const entry of entries) {
    t.equal((0, _timeString.cleanTimeStringInput)(entry[0]), entry[1], "".concat(entry[0], " should be ").concat(entry[1]));

    if (entry.length === 3) {
      t.deepEqual((0, _timeString.parseTimeString)((0, _timeString.cleanTimeStringInput)(entry[0])), entry[2], "".concat(entry[0], " should be ").concat(JSON.stringify(entry[2])));
    }
  }

  t.end();
}); // strict means four digits are requried
// if there's a separator both minutes
// and hours need to be 2 digits.
// 2345 (always 4-digits)
// 0800 (always 4-digits)
// 02:20pm

(0, _tape.default)('parseTimeString strict', t => {
  const entries = [[null, null], [NaN, null], ['', null], [false, null], [true, null], [0, null], ['0a', null], ['1a', null], ['1    am', null], ['12    pm', null], ['12    am', null], ['8:45', null], ['8 45', null], ['8:45a', null], ['8:45p', null], ['8:45 pm', null], ['8:45 p.m.', null], ['8a', null], ['835a', null], ['835 pm', null], ['0800', {
    hours: 8,
    minutes: 0
  }], ['2400', {
    hours: 0,
    minutes: 0
  }], ['2500', null], ['', null], ['a', null], ['b', null], ['   ', null], [':', null], ['23:', null], ['4:60', null], ['4:59', null], ['13:59p', null], ['23:59a', null], ['12:59a', {
    hours: 0,
    minutes: 59
  }], ['24.59', {
    hours: 0,
    minutes: 59
  }], ['24.59a', null], ['12:', null], ['11:2', null], ['5:21 p.m.', null]];

  for (const entry of entries) {
    t.deepEqual((0, _timeString.parseTimeString)(entry[0], {
      strict: true
    }), entry[1], "".concat(entry[0], " should be ").concat(JSON.stringify(entry[1])));
  }

  t.end();
});