DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`firstDayOfWeek`(vYear INT, vWeek INT)
	RETURNS date
	DETERMINISTIC
BEGIN
/**
 * Returns the date of the first day of the week
 *
 * @param vYear The year
 * @param vWeek The week number
 * @return Date of the first day of the week
 */
	DECLARE vDate DATE;

	SELECT dated INTO vDate
		FROM `time`
		WHERE `year` = vYear
			AND `week` = vWeek
		ORDER BY dated
		LIMIT 1;

	RETURN vDate;
END$$
DELIMITER ;
