I was thinking if we could simplify the process of date arithmetic by adding an "add" method, which would add a certain value to the given date object and return the new date. I propose the following structure:
Date.prototype.add = function(unit:String, value:Number)
Where unit
is a specified string to denote hours, minutes, seconds, days, months etc. and value
is the actual value being added. If value
is negative, it would end up subtracting that from the specified date.
The reason I am proposing this is that although adding days to a date object is fairly simple, there does not appear to be any straightforward way to add minutes, seconds, and such to a certain date/time. There have been javascript libraries like moment, but it sure would be nice to have this in the ES specs.
Thoughts?