daynum

1.0.1 • Public • Published

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;

Dependents (0)

Package Sidebar

Install

npm i daynum

Weekly Downloads

0

Version

1.0.1

License

ISC

Last publish

Collaborators

  • mark116