function getFirstDayOfWeek (date) { var day = date.getDay() || 7; return new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1 - day); };