index.js 1.1 KB

1234567891011121314151617181920
  1. import toInteger from "../toInteger/index.js";
  2. import getUTCWeekYear from "../getUTCWeekYear/index.js";
  3. import startOfUTCWeek from "../startOfUTCWeek/index.js";
  4. import requiredArgs from "../requiredArgs/index.js"; // This function will be a part of public API when UTC function will be implemented.
  5. // See issue: https://github.com/date-fns/date-fns/issues/376
  6. export default function startOfUTCWeekYear(dirtyDate, dirtyOptions) {
  7. requiredArgs(1, arguments);
  8. var options = dirtyOptions || {};
  9. var locale = options.locale;
  10. var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
  11. var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate);
  12. var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate);
  13. var year = getUTCWeekYear(dirtyDate, dirtyOptions);
  14. var firstWeek = new Date(0);
  15. firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
  16. firstWeek.setUTCHours(0, 0, 0, 0);
  17. var date = startOfUTCWeek(firstWeek, dirtyOptions);
  18. return date;
  19. }