25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

34 satır
1.1 KiB

  1. import toDate from '../toDate/index.js';
  2. import requiredArgs from '../_lib/requiredArgs/index.js';
  3. /**
  4. * @name startOfQuarter
  5. * @category Quarter Helpers
  6. * @summary Return the start of a year quarter for the given date.
  7. *
  8. * @description
  9. * Return the start of a year quarter for the given date.
  10. * The result will be in the local timezone.
  11. *
  12. * ### v2.0.0 breaking changes:
  13. *
  14. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  15. *
  16. * @param {Date|Number} date - the original date
  17. * @returns {Date} the start of a quarter
  18. * @throws {TypeError} 1 argument required
  19. *
  20. * @example
  21. * // The start of a quarter for 2 September 2014 11:55:00:
  22. * var result = startOfQuarter(new Date(2014, 8, 2, 11, 55, 0))
  23. * //=> Tue Jul 01 2014 00:00:00
  24. */
  25. export default function startOfQuarter(dirtyDate) {
  26. requiredArgs(1, arguments);
  27. var date = toDate(dirtyDate);
  28. var currentMonth = date.getMonth();
  29. var month = currentMonth - currentMonth % 3;
  30. date.setMonth(month, 1);
  31. date.setHours(0, 0, 0, 0);
  32. return date;
  33. }