After reading the source, I think the correct implementation would be to allow you to specify an overriding succ function on the objectrange constructor that is used instead of
_each: function(iterator) { var value = this.start; while (this.include(value)) { iterator(value); *value = value.succ(); *} Becomes -> _each: function(iterator) { var value = this.start; while (this.include(value)) { iterator(value); *if (this.alternateSucc) value = this.alternateSucc(value); else value = value.succ(); *} Then the date prototype could have various succ's added to it- As for setting alternateSucc on the range object, i'll leave that to the experts. Gareth On 3/11/07, Gareth Evans <[EMAIL PROTECTED]> wrote: > > I agree it would be useful to be able to iterate in a range for more than > just days, and the extensions look good- possibly too wordy? > What's wrong with "dateadd"? > :) > > Anyway, how would you implement iteration between a range where you could > specify the interval to iterate? > > here's an idea.. specify the succ function (as an overload of each?) that > is used thus allowing you to create multiple succ functions for dates- > succ_day, succ_month etc... -> > > //example, not implemented > //startDate = 1/1/2007 > //endDate = 12/1/2007 > > $R(startDate, endDate).each(function(date) { > console.log(date); > }, Date.succ_month); > > /* output > 1/1/2007 > 2/1/2007 > ... > 12/1/2007 > */ > > > On 3/11/07, Kjell Bublitz <[EMAIL PROTECTED]> wrote: > > > > > > Regarding time calculations etc, here is something that i would like > > to see being added: > > > > http://burnfield.com/martin/2006/09/15/rails-time-extensions-ported-to-javascript/ > > > > Don't know from where i got that link but it's a great set of tools > > when dealing with times. As the link says it's a port of the rails > > time extension. > > > > With it you could go like this: > > > > startDate = new Date( (7).days().ago() ).succ(); > > endDate = new Date( (1).week().fromNow() ).succ(); > > > > $R(startDate, endDate).each(function(date) { > > console.log(date); > > }); > > > > On 3/11/07, Gareth Evans <[EMAIL PROTECTED]> wrote: > > > Yeah, I was thinking about that but I couldn't see how to implement it > > in a > > > nice prototype-friendly way so just cross posted to leave it with you > > guys. > > > > > > Sorry, no unit tests or anything, just wanted to bring your attention > > to it. > > > > > > Gareth > > > > > > > > > > > > On 3/11/07, Tobie Langel <[EMAIL PROTECTED]> wrote: > > > > > > > > Sounds like a great idea. > > > > > > > > Deserves a ticket IMHO. > > > > > > > > The only issue I see is if you need to iterate over hours, minutes > > or > > > > months instead of days. > > > > > > > > Regards, > > > > > > > > Tobie > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > Regards, Kjell > > www.m3nt0r.de > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---