# from David Cantrell
# on Friday 04 January 2008 09:13:
>> my $feb_1st = today->next('month');
>> my $jan_6th = today->next('week');
>
>That's very confusing. "Today next week" means Friday 11th. "Today
>next month" would mean either the first Friday of next month, or the
> 4th day of next month.
Well, two those things are covered by the operator API, so that's not
what I have in mind. Perhaps the methods should not be last/this/next?
The 4th of next month would just be
date('2008-01-04')+1*months
One week later is just:
date('2008-01-04')+7
The first friday of the month is a bit different (the first of next
month would be "today->end_of_month + 1", but then you have to check
the dow() and wander around a bit.) Perhaps an nth_foo_of_the_month()
method or so...
Of course, "today->end_of_month + 1" is useful and common, but that's a
bit clunky. today->start_of_next_month starts to get a bit wordy.
Thus, the behavior of next/this/last.
I'm not trying to parse English usage or context, I just want a terse
API to do useful things with dates and I would like the behavior to be
*close* to what you would expect it would do. If expectations are all
over the map, then I guess everyone will just have to read the
manual :-)
Forgetting for a second what a human might mean by "this friday", the
fact remains that it would be convenient to have a concise,
programmatic way to determine which date is "the friday" within a given
week. For some humans, this might mean that the answer corresponds to
expectations (remember: I'm designing a documented API, not an Eliza.)
From what I've heard, I'm inclined to stick with the original plan for
last/this/next, but it sounds like previous()/following() methods may
be useful:
$dec28 = today->previous('friday');
$jan11 = today->following('friday');
Now that I think about it, the next/last methods are actually redundant,
as the "friday of last week" is just:
today->this("friday") - 1*weeks
Where (roughly, and with no month/year/abbreviation features):
sub this {
my $self = shift;
my ($want) = @_;
my $start = $self->start_of_week;
my ($day) = grep({lc($_->dayname) eq lc($want)}
$start->thru($start+7)
);
return($day);
}
Though I might still leave them there to satisfy my syntactic
sweettooth.
--Eric
--
"Everything should be made as simple as possible, but no simpler."
--Albert Einstein
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------