index.js 983 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. export default (function (o, c, d) {
  2. var sortBy = function sortBy(method, dates) {
  3. if (!dates || !dates.length || dates.length === 1 && !dates[0] || dates.length === 1 && Array.isArray(dates[0]) && !dates[0].length) {
  4. return null;
  5. }
  6. if (dates.length === 1 && dates[0].length > 0) {
  7. var _dates = dates;
  8. dates = _dates[0];
  9. }
  10. dates = dates.filter(function (date) {
  11. return date;
  12. });
  13. var result;
  14. var _dates2 = dates;
  15. result = _dates2[0];
  16. for (var i = 1; i < dates.length; i += 1) {
  17. if (!dates[i].isValid() || dates[i][method](result)) {
  18. result = dates[i];
  19. }
  20. }
  21. return result;
  22. };
  23. d.max = function () {
  24. var args = [].slice.call(arguments, 0); // eslint-disable-line prefer-rest-params
  25. return sortBy('isAfter', args);
  26. };
  27. d.min = function () {
  28. var args = [].slice.call(arguments, 0); // eslint-disable-line prefer-rest-params
  29. return sortBy('isBefore', args);
  30. };
  31. });