NextGregorianCalendar an extension of ObjectRangeIn my pursuit to develop a date chooser widget I came across the idea to extend the ObjectRange class from prototype. This would ease my troubles in creating a range of dates representing a span of time. ObjectRange prototype's Ranged Enumeration classObjectRange "mixes" in with Enumerable, which means it inherits a bunch of great functions to enumerate over an internal data set. In most cases it is a range of numbers or characters, but with a little help it can easily handle a range of Date objects. Extension NeccesaryIt needed a succ method, this is called within the ObjectRange's to increment to the next value, I figured the next day would be perfect for this. Becareful though the inequality operator is precise down to the millisecond you've got to copy your object's wisely for it to iterate all the way through. To define just an arbitrary range of dates was so easy with ObjectRange it didn't even require a class extension. You just need to implement the succ method into the date object's prototype. When I needed more logic to define the end of the range, i decided to extend the class with some easy to work with constants to retrieve max days and the corresponding English name of the month, such as January, February etc.
|
||||||||||||||||||||||
CommentsNo comments have been posted for this page.
|
||