import { DAY, WEEK } from "./constants.ts";
const DAYS_PER_WEEK = 7;
enum Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat,}
export function weekOfYear(date: Date): number { const workingDate = new Date( Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()), );
const day = workingDate.getUTCDay();
const nearestThursday = workingDate.getUTCDate() + Day.Thu - (day === Day.Sun ? DAYS_PER_WEEK : day);
workingDate.setUTCDate(nearestThursday);
const yearStart = new Date(Date.UTC(workingDate.getUTCFullYear(), 0, 1));
return Math.ceil((workingDate.getTime() - yearStart.getTime() + DAY) / WEEK);}