Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: [date date! month month-bounds] MONTH-BOUNDS func design

From: carl:cybercraft at: 29-Jan-2008 7:23

On Monday, 28-January-2008 at 16:08:40 Gregg Irwin wrote,
>Another example question, which I almost posted as the primer question >on this topic, is whether a LEAP-YEAR? func should always require a >year, or should it default to the current year, and use a refinement >if you want a different year.
I'd go for always... if leap-year? now [...] if leap-year? 1986 [...] if leap-year? 28-Jan-2008 [...] The alternatives being just confusing... if leap-year? [...] if leap-year?/year 1986 [...] if leap-year?/year 28-Jan-2008 [...] Thew first is ambigious, as it could be read (by human readers of the script) as querying if the block contains a leap-year, with the others being longer than they need to be. While... if leap-year?/now [...] if leap-year? 1986 [...] if leap-year? 28-Jan-2008 [...] is hardly better than the always approach.
>And the same question for MONTH-BOUNDS applies to WEEK-BOUNDS. > >EOC> Reaching back to my smalltalk days, I recall that they had a lot of >EOC> nice classes that helped with calendars. The methods DaysInMonth and >EOC> CalendarForMonth come to mind, iirc. > >I have DaysInMonth already, and a lot of others, e.g. >same-day-last-month, year-week, weeks-in-year, week-bounds. And a copy >of Ed's calc-workdays funcs. :) > >CR> Why are two values even required? Is there any month that doesn't >CR> start on the 1st? It's useful to be able to get the last day of a >CR> month since they vary, but I don't see the need for returning >CR> a block with the first as well in it. > >EOC> Don't we always know what the date of a given month is? And the >EOC> start time/end times for any month? :^) > >Starting today, what do you have to do to get a list of all dates in >the current month?
That's why days-in-month is needed. It doesn't explain why you need the month-bounds block. If I had days-in-month, I'd do it something like this... today: now repeat day days-in-month today [today/day: day print today/date] How would month-bounds inprove on that?
>Or how do you compare a date to see if it was last >month,
Currently, like so... date: now date/month: date/month - 1 if all [foo/year = date/year foo/month = date/month][...] I'm open to the idea that month-bounds would improve on that. How would it be used to do it?
>or in any given date range?
How would month-bounds help you with that? I'd use... if all [date >= low-date date <= high-date][...]
>That is, how can we best express the abstraction of date and time >ranges? For a monthly calendar display, you need just the dates. For a >scheduler that gives you daily and weekly views, you need more detail. > >In the case of month-bounds, let's say a user can say "find me all the >files that were added/updated between x and y". Given dates, or just a >month name (files updated in jan-2008), we need the time detail to >catch everything.
But only for the end of the month, since...
>> 1-jan-2008 = 1-jan-2008/0:0:0
== true (Only thinking of month-bounds or week-bounds there.)