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

[date date! month month-bounds] MONTH-BOUNDS func design

 [1/17] from: gregg:pointillistic at: 28-Jan-2008 14:42


Given a function, MONTH-BOUNDS, that returns the first and last date of a month, how would you like it to work? Should it return dates only by default, or include time values (0:0:0 for the first day and 23:59:59 for the last). Should it look at the incoming parameter and include the time only if the input date does? Should there be /date and/or /time refinements? Looking at it another way, what result would you expect, given these calls (assuming it's called today, 28-jan-2008): month-bounds now month-bounds now/precise month-bounds 1 month-bounds 0 month-bounds -1 this-month next-month last-month Let me know what you think. -- Gregg

 [2/17] from: carl:cybercraft at: 28-Jan-2008 23:20


On Monday, 28-January-2008 at 14:42:51 Gregg Irwin wrote,
>Given a function, MONTH-BOUNDS, that returns the first and last date >of a month, how would you like it to work? Should it return dates only >by default,
Yes, I think that should be the default.
>or include time values (0:0:0 for the first day and >23:59:59 for the last). Should it look at the incoming parameter and >include the time only if the input date does?
No, else it'd require the prior striping of the time value when just the date's required, which I assume would be the most common need for knowing a date's first and last day.
>Should there be /date >and/or /time refinements?
I think just /time.
>Looking at it another way, what result would you expect, given these >calls (assuming it's called today, 28-jan-2008): > > month-bounds now
[1-Jan-2008 31-Jan-2008]
> month-bounds now/precise
[1-Jan-2008/0:0:0.0 31-Jan-2008/23:59:59.999]
> month-bounds 1
** Script Error: Invalid argument: 1
> month-bounds 0
** Script Error: Invalid argument: 0
> month-bounds -1
** Script Error: Invalid argument: -1 (ie - what 'to-date 1' etc. gives, unless it's accepted in R3?)
> this-month
1
> next-month
2
> last-month
12 Those three I think are over-kill (unless you meant them as refinements?)
>Let me know what you think.
Why are two values even required? Is there any month that doesn't start on the 1st? It's useful to be able to get the last day of a month since they vary, but I don't see the need for returning a block with the first as well in it.

 [3/17] from: edoconnor:gma:il at: 28-Jan-2008 17:34


Hi Gregg-- Don't we always know what the date of a given month is? And the start time/end times for any month? :^) Reaching back to my smalltalk days, I recall that they had a lot of nice classes that helped with calendars. The methods DaysInMonth and CalendarForMonth come to mind, iirc. If you're building this as part of a larger set of functions, let us know. Dates are a great candidate for dialects. Ed On Jan 28, 2008 4:42 PM, Gregg Irwin wrote:

 [4/17] from: gregg::pointillistic::com at: 28-Jan-2008 16:08


Hi Carl, and Ed, EOC> If you're building this as part of a larger set of functions, let us EOC> know. Dates are a great candidate for dialects. Yes, this is the motivation. I have a library of date related functions, and BOUNDS and RANGE funcs that can deal with dates. If we have a good set of funcs, and design them for easy use on their own, or from a dialect, it would give us great flexibility. 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. 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? Or how do you compare a date to see if it was last month, or in any given date range? 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. -- Gregg

 [5/17] 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
<<quoted lines omitted: 11>>
>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
<<quoted lines omitted: 3>>
>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.)

 [6/17] from: gregg::pointillistic::com at: 29-Jan-2008 0:11


Hi Carl, CR> I'd go for always... if leap-year? now [...] That's my inclination as well, though not how I first did it a long time ago.
>>Starting today, what do you have to do to get a list of all dates in >>the current month?
CR> That's why days-in-month is needed. It doesn't explain why you CR> need the month-bounds block. If I had days-in-month, I'd do it CR> something like this... CR> today: now CR> repeat day days-in-month today [today/day: day print today/date] That lets you act on each day in a month and, yes, days-in-month is good for that, but it doesn't *give you* a list of days. To do that, you have to run that logic and collect the values yourself, every time you want that list of dates. CR> How would month-bounds inprove on that? range month-bounds now
>>Or how do you compare a date to see if it was last month,
CR> Currently, like so... CR> date: now date/month: date/month - 1 CR> if all [foo/year = date/year foo/month = date/month][...] CR> I'm open to the idea that month-bounds would improve on that. How CR> would it be used to do it? find range last-month foo Or like you did, but with more abstraction all [foo >= first last-month foo <= last last-month] And of course, helpers can help between? first last-month last last-month foo
>>or in any given date range?
CR> How would month-bounds help you with that? CR> I'd use... CR> if all [date >= low-date date <= high-date][...] Where we're leading is in-range? last-month foo or in-bounds? last-month foo People may recall my RANGE and BOUNDS funcs. With all the rich types we have in REBOL, we don't have any span/range type(s). I haven't campaigned hard, or successfully, for them, but I think there's a lot of value in them. It they aren't built in, the next question is how best to create them at the mezzanine level.
>>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.
CR> But only for the end of the month, since...
>>> 1-jan-2008 = 1-jan-2008/0:0:0
CR> == true only for the end of the month would be kind of critical to that kind of query though, yes? :) -- Gregg

 [7/17] from: carl::cybercraft::co::nz at: 29-Jan-2008 11:27


On Tuesday, 29-January-2008 at 0:11:55 Gregg Irwin wrote,
>People may recall my RANGE and BOUNDS funcs.
Ah. But that's cheating! :-)
>CR> But only for the end of the month, since... > >>>> 1-jan-2008 = 1-jan-2008/0:0:0 >CR> == true > >"only for the end of the month" would be kind of critical to that kind >of query though, yes? :)
Yes, hence I agree we need a days-in-the-month function...

 [8/17] from: gregg::pointillistic::com at: 29-Jan-2008 4:51


Hi Carl,
>>People may recall my RANGE and BOUNDS funcs.
CR> Ah. But that's cheating! :-) No it's not. Remember, the question is about a MONTH-*BOUNDS* func. :)
>>CR> But only for the end of the month, since... >>
<<quoted lines omitted: 3>>
>>"only for the end of the month" would be kind of critical to that kind >>of query though, yes? :)
CR> Yes, hence I agree we need a days-in-the-month function... days-in-month isn't enough by itself though, since it has no concept of a time associated with each day, which needs to be 0:0:0 for the first day and 23:59:59 for the last. -- Gregg

 [9/17] from: anton::wilddsl::net::au at: 30-Jan-2008 12:11


Hi Gregg. Gregg Irwin wrote:
> days-in-month isn't enough by itself though, since it has no concept > of a time associated with each day, which needs to be 0:0:0 for the > first day and 23:59:59 for the last.
I would prefer not to use <= 31-Mar-2008/23:59:59 but rather < 1-Apr-2008 as the first can never be specified with complete accuracy by definition. Anton.

 [10/17] from: carl::cybercraft::co::nz at: 30-Jan-2008 7:38


On Tuesday, 29-January-2008 at 4:51:20 Gregg Irwin wrote,
>days-in-month isn't enough by itself though, since it has no concept >of a time associated with each day, which needs to be 0:0:0 for the >first day and 23:59:59 for the last.
But if it's only the day's we're considering, it makes more sense to ignore the time. someday/date <= anotherday/date etc. (Thus getting around the need to use Anton's < 1st-of-next-month.) -- Carl Read.

 [11/17] from: gregg:pointillistic at: 30-Jan-2008 5:56


Hi Anton, AR> I would prefer not to use AR> <= 31-Mar-2008/23:59:59 AR> but rather AR> < 1-Apr-2008 AR> as the first can never be specified with complete accuracy by AR> definition. That's true, but then you end up having to write >= for the lower bound comparison and < for the upper. I like symmetry, and I think I can live with accuracy as complete as we can get it. Which I guess means 23:59:59.999. Given the above, are you saying that "MONTH-BOUNDS Mar-2008" should return, e.g., [1-Mar-2008 1-Apr-2008]? -- Gregg

 [12/17] from: gregg:pointillistic at: 30-Jan-2008 5:59


Hi Carl, CR> But if it's only the day's we're considering, it makes more sense CR> to ignore the time. someday/date <= anotherday/date etc. (Thus CR> getting around the need to use Anton's < 1st-of-next-month.) Which brings us back to the original question: What should MONTH-BOUNDS return? Is there a use that requires the time be included, or is the common case of date-only used 99% of the time, and we favor simplicity and obviousness over flexibility? -- Gregg

 [13/17] from: gregg:pointillistic at: 30-Jan-2008 6:03


Addendum to last message CR> But if it's only the day's we're considering, it makes more sense CR> to ignore the time. someday/date <= anotherday/date etc. (Thus CR> getting around the need to use Anton's < 1st-of-next-month.) And what does that do to generic bounds comparisons? foreach file files [ if within month-bounds 'mar-2007 modified? file [...] ] -- Gregg

 [14/17] from: jblake:arsenaldigital at: 30-Jan-2008 8:39


It cant be implemented with MONTH-BOUNDS/days to just get the days And MONTH_BOUND/days/time to get both?

 [15/17] from: gregg:pointillistic at: 30-Jan-2008 7:36


Hi John, JB> It cant be implemented with JB> MONTH-BOUNDS/days to just get the days JB> And JB> MONTH_BOUND/days/time to get both? Sure, it could. If so, what does MONTH-BOUNDS with no refinements return? And what should the refinements be called? In your example, I might use /date rather than /days, since that is use by NOW and the date! datatype. To me, /days means "return a block of days in the month", probably because it's plural. -- Gregg

 [16/17] from: jblake:arsenaldigital at: 30-Jan-2008 9:46


I'm just trying to think of the use for it. Once you figure out what it could be used for, then you make the options. The only thing I can think of is 1 to get how many days are in a month 2. how many days in a range of months (4 months) 3. how many days there are from today till the end of the month or end of range 4. how much time (days, hrs sec) there is till the end of the month/range. Taking that into consideration, and since it is a basically a range, I'd go for the generic reply first. If you want more specific data, then add the options. Or maybe I'm missing the purpose of the MONTH_BOUNDS thing.

 [17/17] from: gregg::pointillistic::com at: 30-Jan-2008 11:46


Hi John, JB> I'm just trying to think of the use for it. That's why I asked on the list. I know what I use it for, but wanted other opinions. JB> 3. how many days there are from today till the end of the month JB> or end of range JB> 4. how much time (days, hrs sec) there is till the end of the JB> month/range. Those are good ones. -- Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted