"use strict";

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

var _milliseconds = _interopRequireDefault(require("milliseconds"));

var _date = require("./date");

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

(0, _tape.default)('formatDate', t => {
  const dateToCompare = new Date(2021, 5, 3, 5);
  const opts = {
    now: dateToCompare
  };
  t.equal((0, _date.toFriendlyDate)(dateToCompare, opts), 'Today');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() + _milliseconds.default.days(1), opts), 'Tomorrow');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() - _milliseconds.default.days(1), opts), 'Yesterday');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() - _milliseconds.default.days(7), opts), 'May 27');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() - _milliseconds.default.days(6), opts), 'Last Friday');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() - _milliseconds.default.days(3), opts), 'Last Monday');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() + _milliseconds.default.days(6), opts), 'Wednesday');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() + _milliseconds.default.days(7), opts), 'June 10');
  t.equal((0, _date.toFriendlyDate)(dateToCompare.valueOf() + _milliseconds.default.days(2), _objectSpread(_objectSpread({}, opts), {}, {
    includeTime: true
  })), 'Saturday @ 05:00');
  t.equal((0, _date.toFriendlyDate)(new Date('Thu Jun 03 2021 00:00:00 GMT-0700'), {
    now: new Date(1622731348017)
  }), 'Today', 'Confirm test case from app, that was breaking'); // this is a bug in chrome, it returns 24:01 instead of 00:01
  // so we have some code to correct

  t.equal((0, _date.toFriendlyDate)(new Date(2020, 11, 14, 0, 1, 0), {
    includeTime: true
  }), 'December 14, 2020 @ 00:01');
  t.end();
});
(0, _tape.default)('toSimpleISODateString, fromSimpleISODateString', t => {
  let start = new Date(2022, 1, 8);
  let result = (0, _date.toSimpleISODateString)(start);
  t.equal(result, '2022-02-08', 'pads months/date');
  t.equal((0, _date.fromSimpleISODateString)(result).valueOf(), start.valueOf());
  start = new Date(2022, 1, 8, 23, 59, 59, 999);
  result = (0, _date.toSimpleISODateString)(start);
  t.equal(result, '2022-02-08', 'handles high');
  t.equal((0, _date.fromSimpleISODateString)(result).valueOf(), new Date(2022, 1, 8).valueOf());
  start = new Date(2022, 1, 8, 23, 59, 59, 1000);
  result = (0, _date.toSimpleISODateString)(start);
  t.equal(result, '2022-02-09', 'handles low');
  t.equal((0, _date.fromSimpleISODateString)(result).valueOf(), new Date(2022, 1, 9).valueOf());
  t.equal((0, _date.toSimpleISODateString)(1644393600000), '2022-02-09', 'handles ms value');
  t.end();
});
(0, _tape.default)('msToTimeAgo', t => {
  const cases = [[-120, '0s'], [5000, '5s'], [15000, '15s'], [999, '0s'], [1800, '0m', false], [60000, '1m', false], [60000 * 150, '2h 30m', false], [60000 * 179, '2h 59m', false], [60000 * 59, '59m', false], [60000 * 59 + 1000, '59m 1s']];

  for (const entry of cases) {
    t.equal((0, _date.msToTimeAgo)(entry[0], entry[2]), entry[1], "".concat(entry[0], " should be ").concat(entry[1]));
  }

  t.end();
});