Opened 13 years ago

Closed 13 years ago

#306 closed defect (fixed)

Dojo Needs a date.add function

Reported by: anonymous Owned by: anonymous
Priority: high Milestone:
Component: General Version: 0.2
Keywords: Cc:
Blocked By: Blocking:

Description

Need an easy way to add to date object. This uses same tokens as the toString function.

dojo.date.add = function(datePart, number, date) {
	var newDate = new Date(date.valueOf());
	switch (datePart) {
		case "d" :
			newDate.setDate(newDate.getDate() + number);
			break;
		case "M" :
			newDate.setMonth(date.getMonth() + number);
			break;
		case "y" :
			newDate.setFullYear(date.getFullYear() + number);
			break;
		case "H":
		case "h":
			newDate.setHours(date.getHours() + number);
			break;		
		case "m":
			newDate.setMinutes(date.getMinutes() + number);
			break;
		case "s":
			newDate.setSeconds(date.getSeconds() + number);
			break;		
	}
	return newDate;
}

Change History (2)

comment:1 Changed 13 years ago by Michael Schall

My cla is on file if you want to include this function.

comment:2 Changed 13 years ago by Tom Trenka

Resolution: fixed
Status: newclosed

I added this to date.js about 3 weeks ago (without seeing your bug post)...since dojo.date.toString was killed, there is an enum in date for this usage.

Note: See TracTickets for help on using tickets.