1.0.1 • Published 10 years ago

daynum v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
10 years ago

This is the whole function

it takes a day and optional year, as parameters, and return a date object

var getDateFromDayNum = function(dayNum, year){

	var date = new Date();
	if(year){
		date.setFullYear(year);
	}
	date.setMonth(0);
	date.setDate(0);
	var timeOfFirst = date.getTime(); // this is the time in milliseconds of the  year
	var dayMilli = 1000 * 60 * 60 * 24;
	var dayNumMilli = dayNum * dayMilli;
	date.setTime(timeOfFirst + dayNumMilli);
	return date;
}

module.exports = getDateFromDayNum;